Kepler's laws, and where they stop being enough
For a single planet orbiting a single, much heavier star, Kepler's three laws describe the motion exactly: orbits are ellipses with the star at one focus; a line from star to planet sweeps equal areas in equal times (so a planet moves faster near perihelion, slower near aphelion); and the square of the orbital period is proportional to the cube of the semi-major axis. This two-body problem has an exact closed-form solution — you can compute the planet's position at any future time directly from six orbital elements, no simulation required.
The moment a third body enters — a second planet, a moon, a spacecraft — the system generally has no closed-form solution. This is the famous three-body problem: Poincaré showed in the 1890s that its trajectories can be chaotic and are not expressible in general as a finite combination of elementary functions. The practical response is numerical integration: advance every body's position and velocity by a small time step, using the gravitational force each body currently exerts on every other, and repeat.
Why the integrator has to be Velocity Verlet
This simulation advances every scenario with Velocity Verlet, not a fancier higher-order method, because orbital mechanics cares about a property most integrators ignore: long-run energy behaviour. Verlet is symplectic — it conserves a shadow energy close to the true energy indefinitely, so a bound orbit stays bound and a periodic orbit stays periodic over millions of steps. A higher-order but non-symplectic method like RK4 is more accurate per step, but leaks energy slowly and steadily, so a planet integrated with RK4 for long enough visibly spirals in or out even though each individual step looks nearly exact.
x += v * h + 0.5 * aOld * h * h; const aNew = gravityFrom(allOtherBodies, x); // sum of GM_i / r_i^2 terms v += 0.5 * (aOld + aNew) * h; aOld = aNew;
Lagrange points and the Trojan asteroids
In the restricted three-body problem (one body's mass is negligible next to the other two, e.g. an asteroid orbiting the Sun–Jupiter system), there are five special positions, the Lagrange points L1–L5, where the combined gravity of the two large bodies and the orbital centrifugal effect balance so a third, massless body can sit in a fixed position relative to the other two, co-rotating with them. L1–L3 lie on the line through both large bodies and are unstable saddle points — useful for spacecraft (like solar observatories at Sun–Earth L1) that need frequent small correction burns, not for anything left alone.
L4 and L5 are different: they sit 60° ahead of and behind the smaller large body along its orbit, forming an equilateral triangle with the two large masses, and for a large enough mass ratio between the two primaries they are dynamically stable. Jupiter's Trojan asteroids are trapped at its L4 and L5 points in exactly this way — tens of thousands of them, some over 100 km across, orbiting the Sun in lockstep with Jupiter without ever needing to be individually integrated as if they were random debris.
Gravity assists: stealing momentum from a planet
A gravity assist (or flyby) changes a spacecraft's speed relative to the Sun without burning any propellant, by exchanging momentum with a planet. In the planet's own reference frame the encounter is elastic — the spacecraft leaves with the same speed it arrived at, only its direction changed by the hyperbolic deflection angle. Transformed back into the Sun's frame, though, that direction change adds (or subtracts) the planet's orbital velocity vector to the spacecraft's, which can produce a substantial net speed change relative to the Sun — the mechanism behind essentially every outer-solar-system mission's actual flight path.
Frequently asked questions
Why does this simulation use Velocity Verlet instead of a more accurate integrator?
Because orbital motion is a long-running conservative system, and Velocity Verlet is symplectic — it keeps the total energy oscillating in a bounded way indefinitely rather than drifting. A higher-order but non-symplectic method like RK4 is more accurate per step but leaks energy over many steps, causing orbits to visibly spiral in or out.
Are the L4 and L5 Lagrange points stable for any two bodies?
No, only when the mass ratio between the two large bodies exceeds roughly 24.96 to 1 (the Routh criterion). The Sun-Jupiter and Sun-Earth systems both satisfy this comfortably, which is why Trojan asteroids accumulate there; L1, L2 and L3 are unstable saddle points regardless of the mass ratio.
Does a gravity assist violate conservation of energy?
No. The spacecraft's speed relative to the flyby planet is unchanged; only its direction changes. The planet's own orbital velocity around the Sun shifts too, by an immeasurably tiny amount because it is vastly more massive, and that transfer is what changes the spacecraft's speed as measured in the Sun's reference frame.
Try it live
Everything above runs in your browser — open Orbital Mechanics and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.
▶ Open Orbital Mechanics simulation