Determine orbital position after change in velocity
I am working on a satellite simulator for a project/game and I am stuck on this one bit of physics. So far I have a satellite that revolves around earth on a 2D plane following Keplerian motion using Kepler's equation. Everything is fine and the satellite will orbit many times without problem. 1023
I can also change the velocity of the satellite to manipulate apo/peri points as well as augment of periapsis.
However, the problem occurs if I change the velocity once the satellite passes the PI/2 mark, the entire orbit gets flipped (augment of periapsis is offset by PI) and the true anomaly resets to 0.
Here is how it is currently implemented: With the assumption that the satellite starts at the periapsis at t0, I find the eccentric and true anomaly given a time since periapsis $w$. Then I find the radius at that angle to get the final position.
$$t_0 = 0$$ $$E_0 = 0$$ $$M(0) = E_0 - e \sin E_0$$ $$n = \sqrt{ \frac{GM }{ a^3}}$$ $$E = {\rm kepler}(e, M)$$ $$v = 2 \tan^{-1}{(\sqrt{\frac{(1+e)}{(1-e)}}\tan\frac{E}{2})}$$ $$r = a\frac{1-e^2}{1 + e\cos{v}}$$
When I update the velocity of the satellite (flight path angle $\phi$ is recomputed after change in velocity), I recalculate a new true anomaly using $\phi$, I then find the difference between the old true anomaly and the new true anomaly, and add that to the augment of periapsis $w$. After that I recompute time since periapsis $t$ using the new true anomaly and recompute the orbital parameters as well.
$$vel = \sqrt{GM\frac{2}{r} - \frac{1}{a}}$$ $$\phi = \tan^{-1} ( \frac{e\sin{v}}{1 + e \cos{v}})$$ $$v_2 = \tan^{-1}{\frac{r v g m \cos{\phi} * \sin{\phi}}{r v g m \cos^2{\phi} - 1}}$$ $$w \mathrel{{+}{=}} v_2 - v$$ $$E = \cos^{-1}{ \frac{e + \cos{v}}{1 + e \cos{v}} }$$ $$M = E - e \sin{E}$$ $$n = \sqrt{ \frac{GM}{a^3} }$$ $$t = \frac{M}{n}$$ $${\rm calculateOrbit}()$$
I noticed if I were to $v = v + \pi$ if ever $v_2 < 0$ and $v > 0$, then the weird orbit/position flip won't occur until the $v = \pi$ Otherwise I do not know what the problem is. I would really appreciate it if someone can point me the way, as I have been scratching my head over this for a long time now. 394