Imagine trying to simulate a galaxy. Every star exerts a gravitational pull on every other star. With stars, that is pairs â roughly force calculations per time step. At one million stars you need a trillion calculations every frame. At a billion stars the number becomes astronomical in both senses of the word.
This is the N-body problem: given point masses, compute the net gravitational force on each one so you can advance their positions by a tiny time step and repeat. It underlies everything from planetary mechanics to cosmological simulations.
The naive algorithm is exact but hopeless at scale. In 1986 Josh Barnes and Piet Hut published a clever approximation: instead of summing every pairwise interaction, group distant particles together and treat the group as a single mass at its center of mass. Their algorithm runs in â fast enough to simulate millions of bodies on ordinary hardware.
The key data structure is a quadtree (in 2-D) or octree (in 3-D): a recursive spatial subdivision that lets you decide, for each particle, which distant clusters are far enough away to be summarized safely.
Comments
Loading comments...