Overview
Principia is an interactive N-body gravity sandbox: drop masses and every body attracts every other one under Newton's law. The design goal is honesty, the only quantity that should stay constant is total energy, and if it drifts the integrator is lying. A live energy-drift readout keeps the simulation accountable.
What it demonstrates
- Correctness-first physics: a symplectic integrator chosen so energy is conserved, not just approximated
- Scaling from exact forces to an approximation without losing visible accuracy
- Keeping the UI responsive by running the physics core off the main thread
Key features
- Velocity Verlet symplectic integrator, with optional 4th-order Yoshida
- Exact O(N squared) force calculation by default, optional Barnes-Hut O(N log N) approximation
- Plummer softening and sub-step collision timing for accurate merges
- Live energy-drift readout surfacing integrator honesty
- Physics core runs in a Web Worker to prevent UI blocking
- Scene sharing via URL serialization, no backend required
- Preset scenarios: Solar System, three-body choreography, chaos
- Test suite validating momentum and energy conservation
Stack
- Vite, React, TypeScript
- Canvas 2D rendering, CSS Modules
- No backend