Dynamic elliptical orbits for the two-body Kepler problem:

In terms of the eccentric anomaly, the parametrization of the orbit in Cartesian coordinates is

$x(u) = a (\cos u - e) \hspace{4em} y(u) = a \sqrt{1-e^2} \sin u$

with semimajor axis $$a$$ and semiminor axis $$b = a \sqrt{1-e^2}$$. The ellipse is offset along the negative x-axis by $$c = a e$$, which is just the distance to a focus of the ellipse. The statements are confirmed by evaluating

$\frac{ (x + ae)^2 }{ a^2 } + \frac{ y^2 }{ b^2 } = \cos^2 u + \sin^2 u = 1$

which is the expression for a shifted ellipse. The amount of the shift means the larger body is always at a focus (using reduced mass). The major axis of the ellipse remains a constant $$2a$$ as the eccentricity changes.

The orbiting body always stays in the invariant xy-plane, with the point of closest approach on the positive x-axis. Coordinate axes are included on the larger body simply to help orient the orbit in three-dimensional space.

Cartesian coordinates are not only simpler here but less tricky to employ. The radial variable can be written simply as a function of eccentric anomaly, but cannot be visualized as a polar plot without also including the dependence of the physical polar angle $$\phi$$ on eccentric anomaly as well.

The eccentric anomaly has the same domain as the physical polar angle, but neither tranverse their domains evenly as a function of time. To get the actual physical behavior of the orbit, one must determine the eccentric anomaly in terms of constantly flowing time from the Kepler equation

$\omega t = u - e \sin u$

This equation cannot be solved explicitly in terms of known functions, and is generally solved numerically. That is why this example requires the higher-level mathematics of Math. The frequency is set equal to one to reduce an already involved calculation.

As a final note on the code, the path of the orbiting body is constructed using a JavaScript template literal in order to included variables easily. It could of course be constructed by adding together regular strings.

Complete code for this example:

Examples Page