SARATH THARAYILST
WRITEUPSPROJECTSLABABOUT
SARATH THARAYIL
മ
SARATH THARAYIL
/ SYSTEM

Building thoughtful software, writing notes, and shipping experiments across data, AI, and the web.

No cookies, no tracking. Preferences are stored locally in your browser. Anonymous view counts are kept server-side.

Hey, there's a story for the river above/© 2026 Sarath Tharayil/IST --:--:--/--- LOC
/ System--:--:-- IST

Building thoughtful software, writing notes, and shipping experiments across data, AI, and the web.

© 2026 Sarath Tharayil--- LOC

No cookies, no tracking. Preferences stored locally. Anonymous view counts server-side.

Hey, there's a story for the river above→
← LAB

N-Body Gravity

Jun 8, 2026

Every body attracts every other body with a force proportional to their masses and inversely proportional to the square of their distance. With two bodies, the motion is a perfect ellipse. Add a third, and the system becomes chaotic. This simulation uses a symplectic Euler integrator with softening to prevent singularities.

PRESET
G100
SPEED
TRAILS
LENGTH
VELOCITY
/ NOTES
HOW IT WORKS

Every pair of bodies exerts a gravitational pull on each other. The force is computed each frame for all N×(N-1)/2 pairs. A softening term ε prevents numerical blow-up when bodies pass close. Velocities are updated first (symplectic Euler), which conserves energy better than standard Euler.

PRESETS
Solar SystemOne large star with five planets in stable circular orbits at varied radii.
Binary StarTwo equal-mass stars orbiting a shared center of mass, with test particles.
Figure-8The famous three-body choreography where all three bodies trace a single figure-8.
ChaosFive to eight bodies with random masses and velocities — unpredictable every time.
RandomConfigurable count of bodies (3–20) with randomised positions and velocities.
WHAT TO TRY

Click anywhere on the canvas to add a new body. Hover over a body to see its mass and speed. Crank up G to watch orbits tighten. Lower the speed multiplier on Figure-8 to appreciate its symmetry.