Skip to content

Commit

Permalink
Use arctan2 instead of arcsin when converting to spherical coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
wedesoft committed Jun 25, 2024
1 parent 382acea commit afa6789
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions skyfield/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit afa6789

Please sign in to comment.