N-body gravity
Every mass pulls every other mass. The two-body problem is solved; the three-body problem is chaos. Add bodies and watch the universe do what it does.
F = G m₁m₂ / r² → velocity Verlet integration → orbits, chaos, ejections
What you're seeing
This is an N-body gravitational simulation: every body on the canvas attracts every other body with a force inversely proportional to the square of the distance between them. There is no spatial partitioning, no approximation hierarchy — it computes all N(N−1)/2 pairwise interactions each frame, which is honest if expensive. The integration uses the velocity Verlet method, a symplectic integrator that conserves energy far better than naive Euler stepping.
The two-body problem
Kepler solved it. Two masses orbiting their common center of mass trace closed ellipses, forever and exactly. You can write down the solution in terms of elementary functions — position as a function of time, for all time. This is the exception, not the rule. The two-body problem is one of the rare dynamical systems where the future is analytically knowable. The Binary Star preset above shows you this tidy world: two equal masses in a perpetual waltz.
The three-body problem
Add one more body and the universe becomes fundamentally unpredictable. Poincaré proved in 1890 that the general three-body problem admits no closed-form solution — the system is non-integrable, meaning there are not enough conserved quantities to pin down the trajectory. Tiny differences in initial conditions grow exponentially, the hallmark of chaos. This is where celestial mechanics stops being engineering and starts being philosophy.
The figure-eight
In 2000, Alain Chenciner and Richard Montgomery proved the existence of a remarkable solution: three equal masses chasing each other around a single figure-eight-shaped curve. It was discovered numerically by Cristopher Moore in 1993 and then proved rigorously. The solution is beautiful, periodic, and unstable — the slightest perturbation sends the bodies spiraling off into chaos. Try the preset and watch how long it survives before numerical noise unravels it.
Softening and numerical tricks
When two bodies pass very close, r approaches zero and the gravitational force diverges to infinity. Real simulations cannot handle this, so we add a small softening parameter ε to the denominator: F = G m₁m₂ / (r² + ε²). This caps the maximum force and prevents numerical explosions. It is physically wrong — real gravity has no minimum distance — but it is computationally necessary. Every large-scale astrophysical simulation uses some variant of this trick.
Why this matters
Galaxy formation, the stability of planetary systems, the trajectory of every spacecraft ever launched — all of it reduces to this calculation. The N-body problem is the backbone of computational astrophysics. And its irreducible difficulty is not a failure of mathematics but a feature of the universe: most gravitational systems are genuinely chaotic, their long-term futures unknowable in principle. We can simulate forward, step by step, but we cannot leap ahead. The universe, it turns out, is its own fastest simulator.