3D Galaxy N-body Simulation
Up to 2,000 stars, every pair pulling on every other. Flip the integrator between RK4 and Verlet on the same galaxy and watch the energy readout.
Loading 3D galaxy (WebGL 2.0)
Illustrative browser model: a softened N-body sketch, not a galaxy-formation result
Gravitational dynamics with up to 2,000 particles, every pair summed directly. The toggle switches the integrator between RK4 and velocity Verlet on the same seeded initial conditions, so the energy readout compares integrators and nothing else. The disks start from a rough enclosed-mass estimate, not an equilibrium model.
Direct Summation
RK4 vs Verlet
Interactive Computation
Technical Details
The 1/r^2 Singularity Problem
Gravitational force follows an inverse-square law: F = Gm1m2/r^2. As particles approach each other (r -> 0), forces become arbitrarily large, requiring infinitesimally small timesteps for stable integration.
Plummer Softening
Both integrators use the same softened force law. It is a standard numerical choice in N-body codes, not a meta-calculus result, and it changes the physics below the softening length:
F = G * m1 * m2 * r / (r^2 + r_soft^2)^(3/2) r_soft = 1 (code units), G = 1e-4. The force has a finite maximum, so close pairs do not force tiny timesteps; physical gravity is still 1/r^2.
Try It Yourself
- Toggle integrator: Compare RK4 and Verlet energy drift on the same galaxy
- Rotate: Click and drag to orbit the galaxy
- Zoom: Scroll wheel to zoom in/out
- Presets: Try different galaxy configurations
- Pause: Click the scene, then press Space