3D N-Body Simulation
Experience gravitational dynamics in 3D space with our interactive N-Body simulation powered by the Barnes-Hut algorithm for optimal performance. Watch stars move through three-dimensional space with realistic lighting and depth effects.
Simulation Statistics
Camera Controls
Mouse: Click and drag to pan the view
Shift + Mouse: Click and drag to rotate the camera
Mouse Wheel: Scroll to zoom in/out
Touch: Single finger to pan, pinch to zoom
About the Barnes-Hut Algorithm
The Barnes-Hut algorithm is an approximation algorithm for performing n-body simulations. Instead of calculating forces between every pair of bodies (O(n²) complexity), it groups distant bodies and treats them as single masses, reducing complexity to O(n log n).
The algorithm works by constructing a quadtree (2D) or octree (3D) spatial data structure, where each node represents a region of space. Bodies that are sufficiently far away are approximated as a single body located at their center of mass.
The theta parameter controls the precision of the approximation. Lower values (0.1-0.5) provide higher accuracy but slower performance, while higher values (1.0-2.0) offer faster computation with reduced precision.
Enable Show Quadtree to visualize the spatial partitioning structure. Green lines show the boundaries of each quadtree node, and red dots indicate centers of mass.