Home▸Algorithms & AI▸Barnes-Hut Tree Code for a Spiral Galaxy: Opening Angle, Force Error and N log N Cost

Barnes-Hut Tree Code for a Spiral Galaxy: Opening Angle, Force Error and N log N Cost

Computing the gravity of every star on every other star costs N squared operations; the Barnes-Hut tree code replaces distant groups of stars by a single point mass and needs only about N log N. Set the number of stars, the opening angle theta, the softening length and the initial spiral and watch a Blender-built hologram table carry a rotating galaxy whose quadtree grid is drawn beneath it, while the force error against direct summation, the interaction count and the rotation curve update live. Checked against direct summation, error growth with theta, N log N scaling and the Kepler period of a leapfrog orbit.

Algorithms & AI3DModerate60 FPS📱 Mobile-adapted🟠 Blender⇄ 2D version
Barnes-Hut Tree Code for a Spiral Galaxy: Opening Angle, Force Error and N log N Cost ↗ Open standalone

Computing the gravity of every star on every other star costs N squared operations; the Barnes-Hut tree code replaces distant groups of stars by a single point mass and needs only about N log N. Set the number of stars, the opening angle theta, the softening length and the initial spiral and watch a Blender-built hologram table carry a rotating galaxy whose quadtree grid is drawn beneath it, while the force error against direct summation, the interaction count and the rotation curve update live. Checked against direct summation, error growth with theta, N log N scaling and the Kepler period of a leapfrog orbit.

⚙ Under the hood

Computing the gravity of every star on every other star costs N squared operations; the Barnes-Hut tree code replaces distant groups of stars by a single point mass and needs only about N log N. Set the number of stars, the opening angle theta, the softening length and the initial spiral and watch a Blender-built hologram table carry a rotating galaxy whose quadtree grid is drawn beneath it, while the force error against direct summation, the interaction count and the rotation curve update live. Checked against direct summation, error growth with theta, N log N scaling and the Kepler period of a leapfrog orbit.

Barnes-HutN-Body SimulationTree CodeGalaxyLeapfrogComputational AstrophysicsAlgorithms

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)