Barnes–Hut simulation

This can dramatically reduce the number of particle pair interactions that must be computed.

An external node has no children and is either empty or represents a single body.

To calculate the net force on a particular body, the nodes of the tree are traversed, starting from the root.

If the internal node is sufficiently close to the body, the process is repeated for each of its children.

The node is sufficiently far away when this ratio is smaller than a threshold value θ.

A 100-body simulation with the Barnes–Hut tree visually as blue boxes.
Dynamic visualization of the quadtree structure of the Barnes-Hut algorithm for the 2D N-body problem