Barnes-Hut N-body Gravitational Simulation!
Digging up an old project! This is an n-body gravitational simulation using the Barnes Hut approximation. In short, \(n^2\) interactions between \(n\) particles is prohibitively expensive, but if you start lumping particles together into larger groups that attract a given particle, you can reduce the number of operations to \(O(n\\log(n))\). You have to go down the Fast Multiple road for it to approach 'correct', but at least it looks great!
Also interesting: setting up initial conditions that produce a stable galaxy is surprisingly difficult! You need lots of dark matter!
Here's a screenshot of the OpenGL interface with the octree nodes influencing a single particle superimposed:
On Github: https://github.com/rreusser/octree-gravity









