INNER CODE UNIT · Python
_ecef_to_geodetic_into
ATTron/astroz · bindings/python/astroz/__init__.py:145
def _ecef_to_geodetic_into(pos, sats):
"""WGS84 ECEF km -> (lat deg, lon deg, alt km) in place; mirrors
WorldCoordinateSystem.ecefToGeodeticDeg (iterative, 10 rounds)."""
p = pos[:, sats]
x, y, z = p[..., 0].copy(), p[..., 1].copy(), p[..., 2].copy()
lon = np.arctan2(y, x)
r = np.sqrt(x * x + y * y)
lat = np.arctan2(z, r * (1.0 - _WGS84_E2))
for _ in range(10):
sin_lat = np.sin(lat)
n = _WGS84_A / np.sqrt(1.0 - _WGS84_E2 * sin_lat * sin_lat)
lat = np.arctan2(z + _WGS84_E2 * n * sin_lat, r)
sin_lat = np.sin(lat)
n = _WGS84_A / np.sqrt(1.0 - _WGS84_E2 * sin_lat * sin_lat)
p[..., 0] = np.degrees(lat)
p[..., 1] = np.degrees(lon)
p[..., 2] = r / np.cos(lat) - n