Caltech-IPAC / kete

Kete Solar System Survey tools
https://Caltech-IPAC.github.io/kete
BSD 3-Clause "New" or "Revised" License
3 stars 0 forks source link

Incorrect true anomaly for hyperbolic objects #60

Closed ynkwontop closed 3 months ago

ynkwontop commented 3 months ago

Comet C/2012 K1 has an eccentricity just above 1 (1.000152915493971) and the code prints an incorrect true anomaly.

dahlend commented 3 months ago

Error is present during the approach to perihelion:

import matplotlib.pyplot as plt
import neospy
import numpy as np

obj = neospy.CometElements(desig="2012 K1",
                           epoch=2456697.5,
                           eccentricity=1.0001529154938005,
                           inclination=142.4282581726916,
                           lon_of_ascending=-42.26235083106466,
                           peri_time=2456897.160044118,
                           peri_arg=203.1066008826146,
                           peri_dist=1.0545970982935025)
peri = neospy.propagate_two_body([obj.state], obj.peri_time)[0]

true = []
calc = []

dts = np.linspace(-1000, 1000, 100)
for dt in dts:
    s = neospy.propagate_two_body([obj.state], obj.peri_time + dt)[0]
    calc.append(s.elements.true_anomaly)
    sign = -1 if dt < 0 else 1
    true.append((sign*s.pos.angle_between(peri.pos)) % 360)

plt.plot(dts, calc, label="Orbital Elements Calc")
plt.plot(dts, true, ls='--', label="Actual")
plt.legend(loc=4)
plt.xlabel("Time from Perihelion (days)")
plt.ylabel("Angle (Deg)")
image