Barnes-Hut Tree Code for a Spiral Galaxy: Quadtree Grid and Error Against Opening Angle (2D)
A face-on view of the same galaxy with the quadtree cells drawn over it, plus a plot of the force error and the number of interactions per star against the opening angle. Same Barnes-Hut code, leapfrog integrator and numerical checks as the 3D table.
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.
A face-on view of the same galaxy with the quadtree cells drawn over it, plus a plot of the force error and the number of interactions per star against the opening angle. Same Barnes-Hut code, leapfrog integrator and numerical checks as the 3D table.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install