diff options
author | HanEmile <emile.hansmaennel@gmail.com> | 2017-03-11 01:15:35 +0100 |
---|---|---|
committer | HanEmile <emile.hansmaennel@gmail.com> | 2017-03-11 01:15:35 +0100 |
commit | e568c202455b93ccebfacc8ab4e032f12f7b3233 (patch) | |
tree | 19f7d5461ba7805b3136a14c0c64abc889784528 /poltocart.py | |
parent | 8b38ee426ed75396e0f49276608e763867261a83 (diff) |
poltocart.py working :D
Diffstat (limited to 'poltocart.py')
-rw-r--r-- | poltocart.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/poltocart.py b/poltocart.py new file mode 100644 index 0000000..2db6723 --- /dev/null +++ b/poltocart.py @@ -0,0 +1,41 @@ +# import +import numpy as np +import matplotlib.pyplot as plt + +# define r, theta, phi +r = 0 +theta = 0 +phi = 0 +cart = [r, theta, phi] + +def poltocart(pol): + print(pol) + + x = pol[0] + y = pol[1] + z = pol[2] + + # radius + r = np.sqrt(np.power(x, 2) + np.power(y, 2) + np.power(z, 2)) + + # theta + theta = np.arccos( z / r ) + + # phi + if x > 0: + phi = np.arctan(y/x) + elif x == 0: + phi = np.sign(y)*(np.pi/2) + elif x < 0 and y >= 0: + phi = np.arctan(y/x) + math.pi + elif x < 0 and y < 0: + phi = np.arctan(y/x) - math.pi + + # write to cartesian list + cart[0] = r + cart[1] = theta + cart[2] = phi + + return cart + +poltocart([4, 3, 5]) |