Remove numpy from geometry

This commit is contained in:
30hours 2024-02-28 12:04:35 +00:00
parent 8d40699da9
commit 6d9027f1be

View file

@ -4,7 +4,6 @@
""" """
import math import math
import numpy as np
class Geometry: class Geometry:
@ -48,25 +47,25 @@ class Geometry:
e = 8.1819190842622e-2 e = 8.1819190842622e-2
# Calculations: # Calculations:
b = np.sqrt(a**2 * (1 - e**2)) b = math.sqrt(a**2 * (1 - e**2))
ep = np.sqrt((a**2 - b**2) / b**2) ep = math.sqrt((a**2 - b**2) / b**2)
p = np.sqrt(x**2 + y**2) p = math.sqrt(x**2 + y**2)
th = np.arctan2(a * z, b * p) th = math.atan2(a * z, b * p)
lon = np.arctan2(y, x) lon = math.atan2(y, x)
lat = np.arctan2((z + ep**2 * b * np.sin(th)**3), (p - e**2 * a * np.cos(th)**3)) lat = math.atan2((z + ep**2 * b * math.sin(th)**3), (p - e**2 * a * math.cos(th)**3))
N = a / np.sqrt(1 - e**2 * np.sin(lat)**2) N = a / math.sqrt(1 - e**2 * math.sin(lat)**2)
alt = p / np.cos(lat) - N alt = p / math.cos(lat) - N
# Return lon in range [0, 2*pi) # Return lon in range [0, 2*pi)
lon = np.mod(lon, 2 * np.pi) lon = lon % (2 * math.pi)
# Correct for numerical instability in altitude near exact poles: # Correct for numerical instability in altitude near exact poles:
# (after this correction, error is about 2 millimeters, which is about # (after this correction, error is about 2 millimeters, which is about
# the same as the numerical precision of the overall function) # the same as the numerical precision of the overall function)
k = np.logical_and(np.abs(x) < 1e-10, np.abs(y) < 1e-10) k = abs(x) < 1e-10 and abs(y) < 1e-10
alt = np.where(k, np.abs(z) - b, alt) alt = abs(z) - b if k else alt
lat = np.degrees(lat) lat = math.degrees(lat)
lon = np.degrees(lon) lon = math.degrees(lon)
return lat, lon, alt return lat, lon, alt