The distance between the Earth and Mars depends on their relative positions in their orbits and varies quite a bit over time. This post will show how to compute the approximate distance over time. We’re primarily interested in Earth and Mars, though this shows how to calculate the distance between any two planets.

The planets have elliptical orbits with the sun at one focus, but these ellipses are nearly circles centered at the sun. We’ll assume the orbits are perfectly circular and lie in the same plane. (Now that Pluto is not classified as a planet, we can say without qualification that the planets have nearly circular orbits. Pluto’s orbit is much more elliptical than any of the planets.)

We can work in astronomical units (AUs) so that the distance from the Earth to the sun is 1. We can also work in units of years so that the period is also 1. Then we could describe the position of the Earth at time *t* as exp(2π*it*).

Mars has a larger orbit and a longer period. By Kepler’s third law, the size of the orbit and the period are related: the square of the period is proportional to the cube of the radius. Because we’re working in AUs and years, the proportionality constant is 1. If we denote the radius of Mars’ orbit by *r*, then its orbit can be described by

*r* exp(2π*i* (*r*^{-3/2} *t* ))

Here we pick our initial time so that at *t* = 0 the two planets are aligned.

The distance between the planets is just the absolute value of the difference between their positions:

| exp(2π*it*) – *r* exp(2π*i* (*r*^{-3/2} *t*)) |

The following code computes and plots the distance from Earth to Mars over time.

from scipy import exp, pi, absolute, linspace import matplotlib.pyplot as plt def earth(t): return exp(2*pi*1j*t) def mars(t): r = 1.524 # semi-major axis of Mars orbit in AU return r*exp(2*pi*1j*(r**-1.5*t)) def distance(t): return absolute(earth(t) - mars(t)) x = linspace(0, 20, 1000) plt.plot(x, distance(x)) plt.xlabel("Time in years") plt.ylabel("Distance in AU") plt.ylim(0, 3) plt.show()

And the output looks like this:

Notice that the distance varies from about 0.5 to about 2.5. That’s because the radius of Mars’ orbit is about 1.5 AU. So when the planets are exactly in phase, they are 0.5 AU apart and when they’re exactly out of phase they are 2.5 AU apart. In other words the distance ranges from 1.5 – 1 to 1.5 + 1.

The distance function seems to be periodic with period about 2 years. We can do a little calculation by hand to show that is the case and find the period exactly.

The distance squared is the distance times its complex conjugate. If we let ω = *r *^{-3/2} then the distance squared is

*d*^{2}(*t*) = (exp(2π*it*) – *r* exp(2π*i*ω*t*)) (exp(-2π*it*) – *r* exp(-2π*i*ω*t*))

which simplifies to

1 + *r*^{2} – 2*r* cos(2π(1 – ω)*t*)

and so the (squared) distance is periodic with period 1/(1 – ω) = 2.13.

Notice that the plot of distance looks more angular at the minima and more rounded near the maxima. Said another way, the distance changes more rapidly when the planets leave their nearest approach than their furthest approach. You can prove this by taking square root of *d*^{2}(*t*) and computing its derivative.

Let *f*(*t*) = 1 + *r*^{2} – 2*r* cos(2π(1 – ω)*t*). By the chain rule, the derivative of the square root of *f*(*t*) is 1/2 *f*(*t*)^{-1/2} *f*‘(*t*). Near a maximum or a minimum, *f*‘(*t*) takes on the same values. But the term *f*(*t*)^{-1/2} is largest when *f*(*t*) is smallest and vice versa because of the negative exponent.

**Related links**: