From e568c202455b93ccebfacc8ab4e032f12f7b3233 Mon Sep 17 00:00:00 2001 From: HanEmile Date: Sat, 11 Mar 2017 01:15:35 +0100 Subject: poltocart.py working :D --- NOTES.md | 4 +-- __pycache__/poltocart.cpython-35.pyc | Bin 0 -> 943 bytes convert_koordinate.py | 52 ----------------------------------- main2.py | 4 +++ poltocart.py | 41 +++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 54 deletions(-) create mode 100644 __pycache__/poltocart.cpython-35.pyc delete mode 100644 convert_koordinate.py create mode 100644 poltocart.py diff --git a/NOTES.md b/NOTES.md index e4e002f..b18ec21 100644 --- a/NOTES.md +++ b/NOTES.md @@ -3,12 +3,12 @@ ## TODO: - speed -- Kugelkoordinatensysteme (räumliche Polarkoordinaten) +- Kugelkoordinatensysteme (Sphere) * helferklasese ## Notes: -# Umrechnung kartesian - polar +# Umrechnung Cartesian - Sphere koordinatentripel (r, theta, phi) diff --git a/__pycache__/poltocart.cpython-35.pyc b/__pycache__/poltocart.cpython-35.pyc new file mode 100644 index 0000000..0f3e255 Binary files /dev/null and b/__pycache__/poltocart.cpython-35.pyc differ diff --git a/convert_koordinate.py b/convert_koordinate.py deleted file mode 100644 index b5e52e3..0000000 --- a/convert_koordinate.py +++ /dev/null @@ -1,52 +0,0 @@ -# import -import math -import numpy as np -import matplotlib.pyplot as plt - -# pol[x, y, z] -x = 1 -y = 2 -z = 3 -pol = [x, y, z] - -# define r, theta, phi -r = 0 -theta = 0 -phi = 0 -kart = [0, 0, 0] - -def poltokart(pol): - # split up list - 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 - a = np.sqrt(x^2 + y^2 + z^2) - b = ((z) / a) - b = b * math.pi / 180 - theta = np.arccos(b) - - # phi - if x > 0: - phi = np.arctan(y/x) - elif x == 0: - phi = np.sign(y)*(math.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 - kart[0] = r - kart[1] = theta - kart[2] = phi - -# run -poltokart(pol) - -print("{:<15}{:<60}".format("polar:", str(pol) )) -print("{:<15}{:<60}".format("cartesian:", str(kart) )) diff --git a/main2.py b/main2.py index 7745d86..29335d7 100644 --- a/main2.py +++ b/main2.py @@ -6,6 +6,10 @@ import math import numpy as np from timeit import default_timer as timer +# import helper-modules +# convert ploar to cartesian koordinates: +import poltocart as ptc + class TLE: def get(value, category, satNr): with open('TLE/' + category + '.txt') as data: 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]) -- cgit 1.4.1