This is a real-time 3D model of the N-body problem: the gravitational dance of hundreds of masses, each pulling on every other through Newton's law of universal gravitation. The same physics governs how galaxies rotate and merge, how planets settle into stable orbits, and how star clusters evolve over billions of years. It is fascinating because even three bodies can move chaotically with no tidy formula to predict them, so we let the computer integrate the equations step by step.
F = G·m₁·m₂ / (r² + ε²) — the gravitational force between
two bodies, where G is the gravitational constant,
m₁ and m₂ are their masses, r
is the distance between them, and ε is a
softening term that prevents the force from blowing up when
bodies pass very close.
The three-body problem has no general closed-form solution. Henri Poincaré proved this in 1887, and his work on its unpredictable behaviour planted the seeds of chaos theory — 76 years before Edward Lorenz rediscovered chaos in weather models.
3D real-time N-body gravity: watch stars, planets, and galaxies orbit, collide, and merge under Newton's universal law of gravitation.
Every particle gravitationally attracts every other (O(N²) interactions, optimised with a Barnes-Hut octree). Stable orbits, hyperbolic trajectories, orbital resonances, and three-body chaotic motion all emerge naturally.
Click to add bodies; drag to give initial velocity. Choose presets: solar system, binary stars, figure-8 orbit, or galactic collision. Adjust gravitational constant G and time-step with sliders.
The three-body problem — predicting three gravitating masses — has no closed general solution. Henri Poincaré proved this in 1887, marking the birth of chaos theory, 76 years before Lorenz's weather work.
This is a real-time 3D model of the N-body problem, in which hundreds of masses each attract every other through Newton's inverse-square law of gravity. The accelerations are summed with a Barnes-Hut octree that reduces the cost from O(N²) to O(N log N), and positions are advanced by a leapfrog-style integrator run in small sub-steps. You can grow a galactic disk, smash two galaxies together, or watch a scaled Solar System, all governed by the same softened force law F = G·m₁·m₂ / (r² + ε²).
Gravitational dynamics of up to 800 bodies. Each frame the net force on every body is computed from a Barnes-Hut octree (or exact O(N²) summation), then velocities and positions are updated by leapfrog integration. Stable circular orbits, merging discs and chaotic close encounters all emerge from the physics rather than being scripted.
Sliders set the body count (50–800), central star mass (500–8000), the gravitational constant G (0.1–3), the softening ε (0.5–5) and trail length (0–80). A dropdown switches between galaxy disk, galaxy collision and Solar System; a checkbox toggles Barnes-Hut versus direct summation. Use Restart to rebuild, drag to rotate and scroll to zoom.
The three-body problem has no general closed-form solution. Henri Poincaré proved this in 1887, and his study of its sensitive, unpredictable motion sowed the seeds of chaos theory some 76 years before Edward Lorenz rediscovered chaos in weather models.
It is a numerical model of how many masses move under their mutual gravity. Because each body attracts every other, there is no tidy formula for the motion of more than two bodies, so the computer integrates Newton's equations step by step. This simulation handles up to 800 bodies at once and lets you watch galaxies, discs and planetary systems evolve in real time.
A naive N-body calculation evaluates every pair of bodies, which costs O(N²) operations per frame. Barnes-Hut instead builds an octree that groups distant clusters of bodies into a single centre of mass, so a faraway group can be treated as one effective particle. This drops the cost to roughly O(N log N); you can toggle it off to compare against exact direct summation.
Bodies sets how many particles populate the system (50–800). Star mass (500–8000) fixes the mass of the dominant central star and therefore the orbital speeds. G scales the strength of gravity (0.1–3), softening ε (0.5–5) smooths very close encounters, and Trail (0–80) sets how long a fading path is drawn behind each body. The Scenario dropdown swaps between a galaxy disk, a galaxy collision and the Solar System.
The Newtonian force grows without bound as the separation r approaches zero, so two bodies passing very close would receive an enormous, numerically unstable kick. The softened form F = G·m₁·m₂ / (r² + ε²) caps the force at small distances, keeping the integration stable. It is a standard trick in galactic simulations, where particles represent broad mass distributions rather than true point masses.
The force law, Barnes-Hut grouping and orbital velocities are physically faithful, so the qualitative behaviour — stable discs, tidal tails in collisions and chaotic motion — is genuine. However, the masses, distances and the gravitational constant use simplified simulation units rather than real SI values, the softening slightly weakens close-range forces, and the leapfrog steps introduce small numerical drift over long runs. It is an accurate teaching model, not a research-grade ephemeris.