Kepler's equation
A planet's orbit is an ellipse, and its speed along that ellipse changes all the time. Finding where the planet is at a given moment takes three angles and one equation with no closed-form solution. This page walks through each step. Every figure runs the same functions the Orbital Map uses to place every planet and moon.
Time and angle on an ellipse
Kepler's second law says the line from the Sun to a planet sweeps out equal areas in equal times. Near periapsis (the closest point) the line is short, so the planet moves fast; near apoapsis it moves slowly. Angle around the orbit therefore does not advance at a constant rate.
The quantity that does advance at a constant rate is the mean anomaly:
M = n (t − tp), n = √(GM / a3)
Here n is the mean motion (radians per unit time), a the semi-major axis, GM the gravitational parameter of the body being orbited, and tp the time of periapsis passage. M is a clock: it runs from 0 to 2π once per orbit. What we need is the true anomaly ν, the actual angle from periapsis to the planet, measured at the focus. The bridge between them is a third angle, the eccentric anomaly E.
Three anomalies
Draw a circle of radius a around the ellipse's centre C (the auxiliary circle). The Sun sits at the focus F, a distance ae from the centre, where e is the eccentricity. Project the planet perpendicular to the major axis onto the circle: the angle of that circle point, measured at C, is E. The planet's position follows directly from E:
x = a (cos E − e), y = b sin E, b = a √(1 − e2)
with F at the origin. At e = 0 all three angles coincide. As e grows they separate: the planet runs ahead of the uniform clock M after periapsis and falls behind it before.
The equation
The area swept from periapsis to the planet, measured from F, is the circle's sector area scaled by b/a, minus the triangle formed by the centre, the focus and the planet. That works out as ½ab(E − e sin E). The whole ellipse has area πab. By the second law the swept fraction equals the elapsed fraction of the period, M / 2π. Equating the two gives Kepler's equation:
M = E − e sin E
Going from E to M is one line of arithmetic. The direction needed in practice, from a time (M) to a position (E), has no solution in elementary functions. It has to be solved numerically.
Solving it with Newton-Raphson
Write f(E) = E − e sin E − M. Its derivative is 1 − e cos E, which is positive for any e < 1, so f increases steadily and has exactly one root. Newton's method replaces the curve with its tangent at the current guess and jumps to where the tangent crosses zero:
Ek+1 = Ek − (Ek − e sin Ek − M) / (1 − e cos Ek)
Each step roughly doubles the number of correct digits. The map starts from E0 = M, or from E0 = π when e ≥ 0.8, and stops once a step changes E by less than 10−8 radians. Over a full orbit this takes at most three iterations for most planets and four for Mercury and Pluto; Nereid, at e = 0.75, needs up to six. The π start for high eccentricity avoids the case where the tangent near periapsis is almost flat and the first step overshoots. To see it, set e near 0.9 and M to a few degrees, then switch the figure's starting guess between the code's choice and E0 = M.
export function solveKepler(M, e, tol) {
tol = tol || 1e-8;
M = ((M % (2 * Math.PI)) + 2 * Math.PI) % (2 * Math.PI);
let E = e < 0.8 ? M : Math.PI;
for (let i = 0; i < 50; i++) {
const dE = (E - e * Math.sin(E) - M) / (1 - e * Math.cos(E));
E -= dE;
if (Math.abs(dE) < tol) break;
}
return E;
}
From eccentric anomaly to position
With E known, the true anomaly and the distance from the focus are
tan(ν/2) = √((1 + e) / (1 − e)) tan(E/2), r = a (1 − e cos E)
The code evaluates the half-angle form with a two-argument arctangent, so the result lands in the correct quadrant without special cases. The final angle in the map's frame adds the argument of periapsis ω, the direction the ellipse points:
export function trueAnomalyFromE(E, e) {
return 2 * Math.atan2(Math.sqrt(1 + e) * Math.sin(E / 2),
Math.sqrt(1 - e) * Math.cos(E / 2));
}
// inside ellipseState(...)
const M = n * (t - tp);
const E = solveKepler(M, e);
const nu = trueAnomalyFromE(E, e) * direction;
const r = a * (1 - e * Math.cos(E));
const theta = omega + nu;
return { r, theta, x: r * Math.cos(theta), y: r * Math.sin(theta) };
Equal areas in equal times
Solving Kepler's equation at evenly spaced times divides the ellipse into sectors of equal area: long thin ones near periapsis, short wide ones near apoapsis. The ratio of speeds at the two ends follows from conservation of angular momentum, vperi / vapo = (1 + e) / (1 − e). For Earth that ratio is about 1.03; for Neptune's moon Nereid, at e = 0.75, it is about 7.
In the map
Every body in the Orbital Map is placed this way,
every frame, from orbital elements at the J2000 epoch
(2000-01-01 12:00 UTC). The functions on this page are
solveKepler, trueAnomalyFromE and
ellipseState in
core/orbits.js.
The model has known limits: each orbit is a two-body ellipse around its
parent, with no mutual perturbation between planets, and the map is
flat, so orbital inclination is ignored.
Next: Lagrange points and Hill spheres, the places where two gravitational fields and an orbit balance.