loading...
running...
How to use
Choose a preset or start from the empty sandbox. Drag the sheet to launch a new body: the arrow is its velocity and the dotted line previews its path in the present field. Click a planet to select it and read its orbital elements; the dashed ellipse is its two-body orbit. Wheel zooms, a right-button (or Shift) drag pans, Space pauses and R restarts the preset.
Try: choose Explicit Euler on the comet and watch the energy graph climb, then switch to Leapfrog. Run the Pythagorean problem with RK4 and a smaller step. Add a heavy planet to the Trojan preset and see when the L4 point becomes unstable.
Here the same planar model lives on a deformable gravity-well sheet: the height of the sheet is the Newtonian potential, so deeper wells are heavier bodies. Drag on the sheet to launch; drag outside it to orbit the camera.
The science
Every body attracts every other body with Newton's law of gravity. For body i with mass mi at position ri the equation of motion is
d²ri/dt² = G ∑j≠i mj (rj − ri) / (|rj − ri|² + ε²)3/2
The units are G = 1 and a star of mass 1; length and time follow from that choice (for a star of one solar mass, one length unit is one astronomical unit and one time unit is 1/(2π) year). ε is an optional softening length that removes the singularity when two bodies meet. For two bodies the problem is solved exactly: orbits are conics with
a = −μ / (2 εorb), T = 2π √(a³ / μ), μ = G (m1 + m2), e = |v × h / μ − r/|r||
which is Kepler's third law (T² ∝ a³) and is shown live for the selected body. Three or more bodies have no general closed form (Poincaré), so the equations are integrated numerically. Four methods are offered so that you can see what a numerical method does to the physics:
- Explicit Euler: first order and not symplectic. The energy of an orbit grows without bound and the ellipse spirals out.
- Leapfrog (kick-drift-kick): second order, symplectic and time-reversible. It does not conserve the energy exactly but its error stays bounded for ever and linear and angular momentum are conserved to rounding.
- Yoshida 4th order: three leapfrog steps with weights w1 = 1/(2 − 21/3), w0 = −21/3 w1: much smaller error at the same step, still symplectic.
- Runge-Kutta 4: fourth order, very accurate for short runs, but the energy error accumulates slowly (secular drift) over very many orbits.
E = ∑ ½ mi vi² − G ∑i<j mi mj / √(rij² + ε²), P = ∑ mi vi, L = ∑ mi (xi vy,i − yi vx,i)
The graphs plot the relative errors of these conserved quantities. Presets include the figure-eight orbit of three equal masses (a periodic solution found numerically by Moore in 1993 and proved to exist by Chenciner and Montgomery in 2000), the Lagrange L4 Trojan equilibrium (linearly stable when m2/(m1 + m2) < 0.0385), a gravity assist and the chaotic Pythagorean three-body problem of Burrau (masses 3, 4, 5).
Numerical checks run in the page. (1) the period of an e = 0.6 ellipse against 2π√(a³/GM); (2) leapfrog keeps the relative energy error below 1e-4 over 50 orbits; (3) Euler drifts more than 1000 times more; (4) RK4's error is below 1e-5; (5) after one period 6.32591 the figure-eight bodies are back at their start; (6) linear and angular momentum are conserved in the chaotic Pythagorean run; (7) a Trojan displaced by 4 degrees librates and stays within 15 degrees of L4.
Simplifications. The motion is confined to a plane (so there is no inclination); bodies are point masses with a visual radius only (collisions are optional perfectly inelastic mergers conserving momentum); there is no relativity, tidal forces, radiation pressure or non-gravitational forces; the time step is fixed, so a very close encounter needs a smaller step than the presets use. Every orbit shown is an osculating two-body ellipse, not a prediction of the true N-body path.