# 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!

• Not exactly what you're looking for, but related: How to programmatically calculate orbital elements using position/velocity vectors?
– user29
Commented Oct 27, 2013 at 18:17
• No, I don't think that's what I'm looking for... some of those orbital elements don't apply in 2d; I was hoping that there was a simple formulation for the satellite's path in 2d. Commented Oct 28, 2013 at 13:03

Well, there are quite a few values to compute for the equations. Here is a list of what the symbols mean:

• $$\mu$$ is the standard gravitational parameter
• r is the position vector, whose magnitude $$r$$ is the current distance from the origin
• v is the velocity vector, whose magnitude $$v$$ is the current speed
• h is the angular momentum vector, whose magnitude $$h$$ is the angular momentum
• e is the eccentricity vector, whose magnitude is the orbital eccentricity
• $$a$$ is the semimajor axis
• $$\omega$$ is argument of periapsis (which in the 2d case is the angle from the $$x$$-axis of periapsis, measured counterclockwise)
• $$\theta$$ is the true anomaly
• $$\tau$$ is the eccentric anomaly
• $$M$$ is the mean anomaly
• $$M_0$$ is mean anomaly at periapsis
• $$d(\theta)$$ is distance of a point on the orbit with a given true anomaly $$\theta$$
• $$d(t)$$ is the distance of a point on the orbit at a particular time $$t$$ (with $$t = 0$$ giving the periapsis distance)

Now here are the equations to use/solve: $$\mu = MG$$ $$\textbf{h} = \textbf{r}\times\textbf{v} = \left<0, 0, h\right>, h = x v_y - y v_x$$ $$\textbf{e} = \frac{\textbf{v}\times\textbf{h}}\mu - \frac{\textbf{r}}{|\textbf{r}|} = \left<\frac{v_y h}{\mu} - \frac{x}{r}, -\frac{v_x h}{\mu} - \frac{x}{r}\right>$$ $$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 \cos(\theta + \omega)}$$ $$\tau = \tan^{-1}\frac{\sqrt{1-e^2} \sin\theta}{e+\cos\theta}, \ \theta = 2 \tan^{-1}\left(\sqrt\frac{1+e}{1-e} \tan\frac{\tau}{2}\right)$$ $$M(\tau) = \tau - e \sin \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 \sin \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)? Commented May 21, 2014 at 20:48
• For v×h, since h is a single non-vector value in 2D, is it just multiplication? Commented Dec 26, 2019 at 22:33
• What are all of the values you start with? Which values are stored as the final result of the calculation? What are the words for these values? What is |r| and how is it different from r? What is the <,> notation, a new vector with those components? What handedness do these equations expect? (Godot has the Y axis pointing down) Commented Dec 26, 2019 at 22:42
• How are you supposed to compute true anomaly $\theta$ from $\tau$ if you need $\tau$ but the equation for $\tau$ requires $\theta$ and it's a cyclic dependency? Commented Dec 27, 2019 at 0:36
• Could you put down the meaning of the symbols you use? I was looking at the wikipedia on orbital elements, but I can't make sense of elements like $\omega$ in the 2D case. What is $\mathbf e$? I can only find the eccentricity on wikipedia, but it should be a scalar.
– SOFe
Commented Jan 20, 2020 at 16:55

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. Commented Oct 28, 2013 at 13:05