N-Body Simulation

High-throughput gravitational simulation using Barnes–Hut acceleration.

Overview

This project simulates gravitational interactions between over one million particles in real time. The goal was to maximize throughput while preserving physical correctness and numerical stability at scale.

The simulation demonstrates the emergent behavior of gravitational systems, from galaxy formation to planetary orbits, all computed with high fidelity on consumer hardware.

Architecture

Implementation

The simulation uses a fixed timestep integrator with decoupled position and velocity updates. Tree reconstruction occurs each frame to ensure correctness under chaotic motion.

Key optimization techniques include spatial hashing for collision detection, memory pooling to reduce garbage collection overhead, and cache-friendly data structures that maximize CPU throughput.

Performance

1M+ Particles
144 FPS
O(n log n) Complexity

Sustains 144 FPS with over one million particles on consumer hardware. The Barnes–Hut algorithm reduces computational complexity from O(n²) to O(n log n), making real-time simulation of massive systems feasible.

Future Work