Three laws, extracted from a table of numbers
Johannes Kepler had no theory of gravity. What he had was Tycho Brahe's twenty years of naked-eye observations of Mars — the most accurate positional data ever taken, and accurate enough that the circle-and-epicycle models of the day missed them by about eight arcminutes. Kepler refused to discard that discrepancy, and it cost him the circle. What came out, between 1609 and 1619, were three empirical statements that still describe every two-body orbit exactly:
1. Orbits are ELLIPSES with the Sun at one focus (not at the centre). 2. The line from the Sun to the planet sweeps EQUAL AREAS in equal times — so a planet moves fastest at perihelion, slowest at aphelion. 3. T² ∝ a³ — the square of the period is proportional to the cube of the semi-major axis, with the SAME constant for every planet.
Newton later showed all three are consequences of a single inverse-square force. The second law is simply the conservation of angular momentum in disguise — nothing about gravity is needed for it, only that the force points along the line joining the two bodies. And the third acquires the constant Newton could not have guessed:
T² = 4π² a³ / (G M) M = the mass of the central body ⇒ measuring T and a for any moon gives you the mass of its planet.
The geometry of an ellipse
An orbit is fixed by its shape and size: the semi-major axis a (half the long diameter) and the eccentricity e (0 = a circle, approaching 1 = a needle). The distance from the focus as a function of the true anomaly ν — the angle at the Sun, measured from perihelion — is the polar equation of a conic:
r(ν) = a (1 − e²) / (1 + e cos ν) ν = 0 → r = a(1 − e) perihelion, the closest point ν = π → r = a(1 + e) aphelion, the furthest point
Speed follows from energy conservation. The total energy of a bound orbit depends only on a, which gives the vis-viva equation — arguably the single most useful formula in orbital mechanics, since it converts a position into a speed with no integration at all:
v² = G M ( 2/r − 1/a ) circular orbit (r = a): v = sqrt(GM / r) escape (a → ∞): v = sqrt(2GM / r) — exactly √2 times faster
Kepler's equation, and the reason it is famous
Now the hard part. The three laws tell you the shape of the orbit and that area is swept uniformly — but they do not give you the position as an elementary function of time. Getting there needs two auxiliary angles. The mean anomaly M is the angle a fictitious body on a circular orbit of the same period would have swept: it is exactly linear in time. The eccentric anomaly E is a geometric construction on the circle circumscribing the ellipse. They are related by
M = 2π (t − t₀) / T // trivially linear in time M = E − e·sin E // KEPLER'S EQUATION — transcendental
That second line has no closed-form solution for E. It has resisted one since 1609, and it is the reason orbital propagation is done numerically even though the orbit itself is an exact analytic curve. In practice it is solved per time step by Newton–Raphson, which converges in two or three iterations for the eccentricities of the planets:
let E = M; // good seed for small e
for (let i = 0; i < 8; i++) {
const f = E - e * Math.sin(E) - M;
const fp = 1 - e * Math.cos(E);
const dE = f / fp;
E -= dE;
if (Math.abs(dE) < 1e-12) break; // typically 2–3 iterations
}
// eccentric anomaly → true anomaly → position
const nu = 2 * Math.atan2(Math.sqrt(1 + e) * Math.sin(E / 2),
Math.sqrt(1 - e) * Math.cos(E / 2));
const r = a * (1 - e * Math.cos(E));
const x = r * Math.cos(nu), y = r * Math.sin(nu);
For near-parabolic orbits (e close to 1) the naive seed E = M converges slowly or not at all, and a better starting guess or a different formulation is needed — a comet is much harder to propagate than a planet.
Two ways to build a solar system, and when each is right
The method above is Keplerian propagation: each planet carries a fixed set of orbital elements, and its position at any time t is computed directly from them. It is fast, it is exact for two bodies, it never drifts, and you can jump to any date in one step with no accumulated error. What it cannot do is respond to anything — the planets do not feel each other, orbits never precess, resonances never form, and a spacecraft cannot change its path.
The alternative is N-body integration: give every body a position and a velocity, compute the mutual gravitational forces each step, and integrate. Now perturbations are automatic — Jupiter tugs on Mars, orbits precess, resonances emerge on their own — but you have inherited the whole apparatus of numerical integration, including its errors. The integrator must be symplectic (Leapfrog, or the Wisdom–Holman symplectic map used in long-term solar-system studies); use RK4 and the energy will drift monotonically, and the planets will spiral in or out over a long run.
Keplerian elements N-body integration ────────────────────── ───────────────────────────── exact for 2 bodies approximate, error grows no perturbations perturbations are automatic jump to any date, O(1) must step through the interval no energy drift, ever needs a symplectic integrator planet ephemerides, galaxy dynamics, resonances, stable visualisations collisions, spacecraft
A visual solar system like the one on this site is best served by the first: Keplerian elements give clean, stable, always-correct ellipses at any zoom and any playback speed, with no possibility of a planet slowly escaping because the time step was too coarse. Real ephemerides used for navigation go further still — the JPL Development Ephemerides are numerically integrated with relativistic corrections and then fitted, because at that precision even Kepler's ellipse is only an approximation.
Frequently asked questions
Why does Kepler's equation need to be solved numerically?
Because M = E − e·sin E is transcendental: it mixes an angle with the sine of that angle, and no elementary function inverts it. Position as a function of time therefore has no closed form, even though the orbit itself is an exact ellipse. Newton-Raphson converges in two or three iterations for planetary eccentricities.
Should I use Kepler's laws or gravity to simulate a solar system?
Kepler's laws for a stable, visually exact set of planets: the orbits are analytic, never drift and can be evaluated at any date in one step. Direct N-body integration if you need planets to perturb each other, resonances and precession to emerge, or spacecraft to manoeuvre — but then you need a symplectic integrator, or the energy will drift.
Why is the Sun at a focus rather than at the centre of the ellipse?
Because it falls out of the inverse-square force law: solving the two-body problem gives r = a(1 − e²)/(1 + e·cos ν), the polar equation of a conic with the origin at a focus. It is only for a circle (e = 0) that the focus and the centre coincide — which is why the old circular models kept needing corrections.
Try it live
Everything above runs in your browser — open Solar System and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Solar System simulation