# Calculating the time of flight between two anomalies gives a negative result?

I want to calculate the time of flight (TOF) between two true anomalies on an orbit with known orbital elements. Based on this wikipedia article and the post Time of flight between two anomalies in a known orbital trajectory , I ended up using the following formula.
Knowing the true anomalies $$\nu_1$$ and $$\nu_2$$ (with $$\nu_2 > \nu_1$$) at some (unknown) times $$t_1$$ and $$t_2$$ ($$t_2 > t_1$$), I express the TOF $$t_2 - t_1$$ from $$\nu_1$$ to $$\nu_2$$ by: $$t_2-t_1 = \sqrt{\frac{a^3}{\mu}}(E_2-E_1 + e(\sin E_1 - \sin E_2))$$ Where $$E_1$$ and $$E_2$$ are the corresponding eccentric anomalies calculated using the equation: $$E = 2 \arctan \left( \sqrt{\frac{1-e}{1+e}} \tan \frac{\nu}{2} \right)$$

However this expression in practice gives me a wrong negative TOF.

This can be verified with a simple numerical example. Since $$\sqrt{a^3/\mu}$$ is always positive, we can focus only on the sign of the part involving the eccentric anomalies. Considering :

$$e = 0.11$$ (slightly elliptic orbit)
$$\nu_1 = 2.43 \ \text{rad}$$
$$\nu_2 = 3.78 \ \text{rad}$$

We calculate $$E_1$$ and $$E_2$$:

$$E_1 \approx 2.35 \ \text{rad}$$
$$E_2 \approx -2.43 \ \text{rad}$$

Which then gives:

\begin{align} (E_2-E_1 + e(\sin E_1 - \sin E_2)) & = (-2.43-2.35+0.11\times(\sin(2.35)-\sin(-2.43))) \\ & \approx -4.63 < 0 \end{align}

This problem will arise whenever a true anomaly is greater than $$\pi$$ because of the $$\pi$$-periodicity of $$\tan$$. Is there a way to counter this ? Is there a formula for TOF that works well for all cases ? If possible one that would also work with a hyperbolic orbit (through sign changes and the usage of the hyperbolic anomaly).

• @Uwe I don't understand your comment. I never mentioned two or more bodies. I'm focusing on a single perfect elliptic orbit (I'm working on a simulation). A spacecraft is moving on that orbit. I want to calculate the time of flight of that spacecraft going from a point A on that orbit specified by its true anomaly $\nu_1$, and a point B of true anomaly $\nu_2$. Aug 4 '21 at 14:47
• Since you're working with an elliptical orbit, continue working through the calculation. If the resulting time of flight is negative, add the orbital period. Aug 4 '21 at 15:17
• @Uwe Quoting entry #5 from the dictionary.com definition of anomaly, Astronomy. a quantity measured in degrees, defining the position of an orbiting body with respect to the point at which it is nearest to or farthest from its primary. Aug 4 '21 at 15:17
• @novotny Alternatively add $2\pi$ to the ending eccentric anomaly ($E_2$) when $E_2<E_1$. Aug 4 '21 at 15:30
• I am sorry, I confused anomalies and mascons.
– Uwe
Aug 4 '21 at 15:45

When true anomaly is between 0 and $$\pi$$ the formula for E is fine, but above $$\pi$$ you have to adjust the Arctan value to get E in the right quadrant. It looks like just add 2$$\pi$$ to a negative value E.