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} = \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\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
  • 1
    $\begingroup$ On the third equation, shouldn't that be y/r at the very end (instead of x/r)? $\endgroup$ – Maxpm May 21 '14 at 20:48
  • $\begingroup$ For v×h, since h is a single non-vector value in 2D, is it just multiplication? $\endgroup$ – Aaron Franke Dec 26 '19 at 22:33
  • $\begingroup$ 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) $\endgroup$ – Aaron Franke Dec 26 '19 at 22:42
  • $\begingroup$ 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? $\endgroup$ – Aaron Franke Dec 27 '19 at 0:36
  • $\begingroup$ @AaronFranke since my answer is pretty old, I don't remember all the details, but let me try to answer your questions. For $v \times h$, it's a cross product, which lies in the $x$,$y$-plane since $h$ lies along the $z$ axis. $\left|r\right|$ is the magnitude (length) of the vector $r$. Indeed the $\left<x,y\right>$ notation describes a vector with those components. The handedness is that $x$ is right and $y$ is up (which is standard in math). The true anomaly $\theta$ can be computed from the eccentric anomaly $\tau$ using the second formula on the fourth-to-last line of formulas. $\endgroup$ – feralin Dec 27 '19 at 17:44

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$:



$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




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.

  • 1
    $\begingroup$ 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. $\endgroup$ – feralin Oct 28 '13 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.