From afa6789e3e7dd3d479bceac0048be059850906e4 Mon Sep 17 00:00:00 2001 From: "Jan Wedekind (Dr)" Date: Tue, 25 Jun 2024 20:56:15 +0100 Subject: [PATCH] Use arctan2 instead of arcsin when converting to spherical coordinates --- skyfield/functions.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/skyfield/functions.py b/skyfield/functions.py index e0c78589a..5b4386a9e 100644 --- a/skyfield/functions.py +++ b/skyfield/functions.py @@ -2,7 +2,7 @@ from numpy import ( arcsin, arctan2, array, cos, einsum, finfo, float64, - full_like, load, nan, rollaxis, sin, sqrt, where, + full_like, hypot, load, nan, rollaxis, sin, sqrt, where, ) from pkgutil import get_data from skyfield.constants import tau @@ -86,7 +86,7 @@ def to_spherical(xyz): """ r = length_of(xyz) x, y, z = xyz - theta = arcsin(z / (r + _AVOID_DIVIDE_BY_ZERO)) + theta = arctan2(z, hypot(x, y)) phi = arctan2(y, x) % tau return r, theta, phi @@ -96,7 +96,7 @@ def _to_spherical_and_rates(r, v): xdot, ydot, zdot = v length = length_of(r) - lat = arcsin(z / (length + _AVOID_DIVIDE_BY_ZERO)) + lat = arctan2(z, hypot(x, y)); lon = arctan2(y, x) % tau range_rate = dots(r, v) / length_of(r)