3D Galaxy N-body Simulation
Watch gravitational dynamics unfold in real-time with up to 5,000 particles. This simulation demonstrates how NNC k=-1 optimization enables larger timesteps for 1/r^2 singularities, achieving 2x performance improvement while maintaining energy conservation.
Real-time Physics
Velocity Verlet integration with spatial hashing for O(n) neighbor search. 30+ FPS on integrated graphics.
NNC Optimization
k=-1 soft-core regularization prevents singularity at r=0, enabling 2x larger timesteps than classical methods.
Proof of Live Computation
Orbit the camera, change particle counts, toggle NNC mode - all changes reflect immediately proving this is not pre-recorded.
Loading 3D Galaxy Simulation...
Requires WebGL 2.0
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.
NNC Solution: Soft-Core Regularization
Using NNC with k=-1 is equivalent to applying a soft-core potential:
F = G * m1 * m2 * r / (r^2 + r_soft^2)^(3/2) Where r_soft is the regularization radius. This transforms the singularity into a smooth maximum, allowing ~15x larger timesteps at close approaches.
Performance Characteristics
| Metric | Classical | NNC k=-1 |
|---|---|---|
| Timestep | 0.005 | 0.010 (2x) |
| Steps/second | ~60 | ~30 (same physics time) |
| Energy drift | <5% | <5% |
| Max particles @ 30 FPS | ~25,000 | ~50,000 |
Try It Yourself
- Toggle NNC: Press N or use the toggle to compare classical vs NNC
- Rotate: Click and drag to orbit the galaxy
- Zoom: Scroll wheel to zoom in/out
- Presets: Try different galaxy configurations
- Pause: Press Space to pause and inspect the state