N-Body Gravity

N particles, each attracting every other via Newton's F = G m₁m₂/r². Two particles: stable ellipses. Three or more: chaos punctuated by occasional close encounters that fling members out at huge speeds. Run hundreds of them and you get galaxy-like dynamics: spiral arms, gravitational clustering, dark-matter-style halos. The simulation engine of cosmology.

setup
speed 2.0
trails 0.85
why three bodies break Kepler
Two bodies orbiting each other: solvable analytically (Newton). Conic sections — ellipse, parabola, hyperbola. Conserves energy, angular momentum, runs of the Laplace-Runge-Lenz vector. Beautiful and predictable.

Three bodies: Poincaré (1887) proved no closed-form solution. The trajectories are chaotic: tiny perturbations lead to vastly different futures. Most orbits are unstable; over time, gravitational scattering ejects one body and leaves the other two in a bound system. The famous "figure-8" (Chenciner-Montgomery 2000) is a stable choreographed orbit found by computer search — three equal masses chasing each other along a figure-8.

N > 3: chaos amplifies. But statistical patterns emerge:
• Violent relaxation: clusters thermalize on dynamical timescales (Lynden-Bell 1967). Velocity distribution becomes Maxwellian.
• Gravothermal collapse: the core of a dense cluster keeps shrinking (heat flows outward, core gets hotter, gravity wins).
• Dynamical friction: massive bodies sink toward the center, light ones escape (mass segregation).
• Galaxy formation: tidal interactions strip stars, form spiral arms, drive bar instabilities.

Cosmological N-body simulations: the Millennium Simulation (2005) tracked 10¹⁰ dark matter particles in a 500-Mpc box. The resulting cosmic web — filaments connecting galaxies into a foam of voids — matches observation. Today's IllustrisTNG simulations couple gravity to gas hydrodynamics, magnetic fields, star formation, and black-hole feedback to model entire galaxy populations.