# 2D Orbital Path from State Vectors

Given a planet of mass $M$ at the origin, and the state vectors $\textbf{r}$ (in meters) and $\textbf{v}$ (in $m/s$) at time $t = 0$ for a satellite, what are are the equations for:

• Distance $d(t)$ between the satellite and the planet at time $t$, and

• Distance $d(\theta)$ when the satellite is at an angle $\theta$ from "horizontal" (the vector $<1, 0>$)?

Edit: I can already compute certain values, such as the semi-major axis $a$, and the eccentricity $e$. I could even make do with just being able to compute the angle from the horizontal of periapsis.

I'm writing a simple 2d orbital simulator, and I would really like to draw a projected trajectory for the satellite/spaceship that the player is controlling, but I need these formulas to be able to do that. Thanks!

Well, there are quite a few values to compute for the equations: $$\mu = MG$$ $$\textbf{h} = \textbf{r}\times\textbf{v} = <0, 0, h>, h = x v_y - y v_x$$ $$\textbf{e} = \frac{\textbf{v}\times\textbf{h}}\mu - \frac{\textbf{r}}{|\textbf{r}|} = <\frac{v_y h}{\mu} - \frac{x}{r}, -\frac{v_x h}{\mu} - \frac{x}{r}>$$ $$e = |\textbf{e}|$$ $$a = \frac{h^2}{\mu(1-e^2)}$$ $$\omega = tan^{-1}\frac{\textbf{e}_y}{\textbf{e}_x}$$ $$d(\theta) = \frac{a(1 - e^2)}{1 + e\space\text{cos}(\theta + \omega)}$$ $$\tau = tan^{-1}\frac{\sqrt{1-e^2}\space\text{sin}\space\theta}{e+\text{cos}\space\theta}, \theta = 2\space tan^{-1}(\sqrt\frac{1+e}{1-e}\space tan\frac{\tau}{2})$$ $$M(\tau) = \tau - e\space\text{sin}\space \tau$$ $$M_0 = M|_{\tau = \tau(\omega)}$$ $$M(t) = t\sqrt{\frac{G(M + m)}{a^3}}+M_0$$ There isn't a closed form solution for $d(t)$; to compute $d(t)$ at a specific $t$, one must:

• compute mean anomaly $M$ for the given time $t$
• solve for eccentric anomaly $\tau$ in $M = \tau - e\space\text{sin}\space \tau$
• compute true anomaly $\theta$ from $\tau$
• and then plug $\theta$ into $d(\theta)$ to get the distance at the angle that corresponds to the given time
• On the third equation, shouldn't that be y/r at the very end (instead of x/r)? – Maxpm May 21 '14 at 20:48

With $M$, $\textbf{r}$, $\textbf{v}$, you can calculate the specific energy, $\mathcal{E}$ and specific angular momentum of the object, $\mathcal{M}$, which are constants of the orbital motion. From those you can get the semi-major axis, $a$, and the eccentricity, $e$. That is all you need in two dimensions.

That won't get you a closed form solution for $d(t)$. What you can get are parametric solutions in the form $t(\tau)$, $r(\tau)$, and $\phi(\tau)$ (or $x(\tau)$ and $y(\tau)$), which can be used for making plots. $\tau$ is the eccentric anomaly, which for an elliptical orbit is the angle of the position from the center of the ellipse (not the focus of the ellipse, where the planet is). When you run $\tau$ from $0$ to $2\pi$, you get a complete orbit. The equations are (where $r$ is the magnitude of $\textbf{r}$ (what you're calling "$d$"), and $\mu$ is $GM$:

$r(\tau)=a\left(1-e\cos{\tau}\right)$

$\phi(\tau)=\tan^{-1}\left(\cos{\tau}-e,\sqrt{1-e^2}\sin{\tau}\right)$

$t(\tau)=\sqrt{a^3\over\mu}\left(\tau-e \sin{\tau}\right)$

The argument order for the two-parameter inverse tangent above is $\tan^{-1}\left(x,y\right)$. Many programming languages have an atan2(y,x) function with the arguments in the other order, so be careful lest you cause havoc in the heavens.

You will need to solve for $\tau_0$, e.g. using $r(\tau_0)=r_0$ to know where your starting point is in the orbit, if that matters for your plot. You may also want to add an offset to $\phi$ to get the orbit rotated to some specific starting location, again if that matters to you.

By the way, it is common to use $\mu$ instead of $M$ because we can usually measure $\mu$ to much higher accuracy than we currently know the fundamental physical constant $G$. So how well we know $M$ for a body is usually limited by how well we know $G$.

I won't solve 100% of this for you, but I'll give you enough to figure it out. From Wikipedia

$v=\sqrt{\mu\left({2\over{r}}-{1\over{a}}\right)}$

Where

$\mu=GM$

From these, G is a constant, M is the mass. You provide then every term in that equation except for $a$. Simply back out what $a$ is, and you know the orbital velocity at for any given distance. The next thing to know is the orbital period. That can be found, according to Wikipedia/ Kepler's Third Law, to be:

$T = 2\pi\sqrt{a^3/\mu}$

You know all of these values already. Last piece of information is Kepler's Second Law. Put it all together, and you should be able to piece together the formula.

• I'm afraid I don't understand. I can compute the velocity at any distance ($r$, correct?), but how do I determine at what angle the max-velocity (periapsis) is? That's really all I need. – feralin Oct 28 '13 at 13:05