← Back to Labs

Solar System — N-Body Gravity Simulation

Newtonian Gravity N-Body

Each body exerts gravitational force on every other. Newton's law of gravitation and second law give the acceleration of body i:


a_i = G Σ_{j≠i} m_j (r_j − r_i) / |r_j − r_i|³

Integrated using the Velocity-Verlet (Störmer-Verlet) symplectic integrator, which conserves energy much better than Euler for orbital mechanics:


x(t+dt) = x + v·dt + ½a·dt²
v(t+dt) = v + ½(a + a')·dt

Actual planetary masses, orbital radii, and velocities are used. Kepler's third law T² ∝ a³ means outer planets move much slower — Neptune takes 165 Earth years to orbit.