Skip to main content

Playground · Three-Body Problem

Three-body problem

Two bodies orbiting under gravity is a solved, predictable problem. Add a third and it becomes chaotic — no general closed-form solution, and tiny changes in the start send the whole thing somewhere else. This simulates real Newtonian gravity, step by step. Pick a setup and press play.

Setup:

Total energy

Energy drift

should stay ≈0

Sim time

0.0

Ghost separation

how far chaos has pushed the twin

Why three is hard

Each body pulls on every other with Newton's inverse-square gravity, so their paths are coupled and feed back on each other. For two bodies that yields tidy ellipses; for three there's no general formula — you have to step the equations forward numerically. Most starts are chaotic: turn on the chaos ghost to launch an identical system nudged by one part in a thousand, and watch the two copies peel apart. A few special starts are stable — the figure-eight choreography and the Lagrange triangle are exact periodic solutions.

How it's built

Pure vanilla JavaScript on a <canvas> — no physics engine. Bodies are Newtonian point masses in normalised units (G = 1). Each frame advances the system with your chosen integrator: velocity Verlet (symplectic, conserves energy well), RK4 (accurate, slowly leaks energy), or explicit Euler (simple, energy visibly blows up — great for seeing why integrator choice matters). The energy drift read-out is the live scorecard.

Inspired by the open-source Three-Body Lab project — reimplemented from the physics in bigspark's house style. Figure-eight initial conditions from Chenciner & Montgomery (2000); the “Pythagorean” three-body setup is the classic Burrau problem (masses 3, 4, 5). Numbers are approximations — that's the whole point of the drift meter.