The Physics of the Universe
Home › Simulations › Gravity Simulation — Interactive N-Body Orbital Sandbox

Gravity Simulation — Interactive N-Body Orbital Sandbox

Experiment with universal gravitation in a symplectic N-body gravity simulation sandbox: tap anywhere to spawn an orbiting planet, pull back and drag to slingshot comets at custom velocities, or watch binary stars and planetary mergers evolve live.

Presets:
Click once in open space to spawn a planet on an automatic circular orbit, or click-and-drag to aim a custom slingshot trajectory!

Key Equations & Physics Model

Newton's Law of Universal Gravitation: Fᵢ = ∑_{j≠i} G mᵢ mⱼ (rⱼ − rᵢ) / |rⱼ − rᵢ|³
Circular vs. Escape Speed at Radius r: v_circ = √(G M / r), v_esc = √(2 G M / r) ≈ 1.414 v_circ
Vis-Viva Elliptical Orbit Speed: v² = G M ( 2 / r − 1 / a )

Because orbital trajectories drift rapidly under naive Euler steps, this gravity simulator runs a 4th-order symplectic Yoshida integrator that preserves angular momentum and energy bounds across hundreds of revolutions.

How the Physics Works

Every mass in space attracts every other mass simultaneously along the line connecting their centers, shrinking inversely with squared distance. Unlike fixed circular animations, a genuine N-body gravity simulation recomputes all mutual pairwise pulls between stars, planets, and launched probes at every substep.

Whether an object stays in a closed orbit or escapes forever depends strictly on speed compared to local escape speed √(2GM/r). Launching slower than circular speed √(GM/r) drops the object inward toward a tight ellipse; launching right around circular speed traces near-circles; exceeding √2 times circular speed unleashes an unbound hyperbolic escape.

In Binary Stars mode, two massive companions orbit their shared center of mass while a distant circumbinary planet loops stably around both suns—demonstrating how real Tatooine-style exoplanets survive.

With Inelastic Planetary Mergers toggled on, colliding bodies conserve total linear momentum (m₁v₁ + m₂v₂)/(m₁+m₂) while merging mass and cross-sectional radius just like planetesimal accretion in early protoplanetary disks.

Solar System Orbital & Escape Velocities

PlanetSemi-Major Axis (AU)Orbital PeriodMean Orbital Speed v_circSurface Escape Speed v_esc
Mercury0.387 AU88.0 days47.36 km/s4.25 km/s
Venus0.723 AU224.7 days35.02 km/s10.36 km/s
Earth1.000 AU365.25 days29.78 km/s11.19 km/s
Mars1.524 AU687.0 days24.07 km/s5.03 km/s
Jupiter5.204 AU11.86 years13.07 km/s59.50 km/s
Neptune30.07 AU164.8 years5.43 km/s23.50 km/s

What separates a closed orbit from escape?

A 41-second animation: mutual N-body gravity, circular vs. escape speed (√2), and gravitational slingshots.

Experiments to Try

Double Star Mass Mid-Orbit

Run Solar System Orbits, double Central Star Mass M from 18 to 36 M☉, and watch circular orbits pull inward into tighter faster ellipses.

Launch Custom Ellipses vs. Hyperbolas

Open Empty Star Sandbox, drag slowly near the star for a steep grazing comet orbit, then drag strongly beyond v_esc to fling a probe out to infinity.

Observe a Planetary Gravity Assist

Select Slingshot Gravity Assist and watch the fast blue probe swing behind the giant orange planet to gain or redirect orbital speed without firing rockets.

Frequently Asked Questions

Why doesn't the central Sun sit completely frozen in place?

Newton's third law cuts both ways: every planet tugs back on the star, so both orbit their shared system barycenter. The effect becomes dramatic with heavy binary stars or massive gas giants.

What happens if a planet moves slower than circular speed?

A slower tangential speed cannot balance gravity at the launch radius, so the planet falls inward into an eccentric ellipse whose periapsis dips closer to the star before whipping back outward.

How does a gravitational slingshot speed up a spacecraft without fuel?

In the Sun's frame, swinging behind a moving planet steals an imperceptible fraction of the planet's orbital momentum—accelerating the tiny spacecraft by kilometers per second.

Why do orbits stay closed for years in this simulation?

Using a 4th-order symplectic Yoshida composition avoids artificial energy damping or spiral bloat typical of basic arcade physics engines.

Related Topics & Tools