Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Tried writing an electrostatic particle simulator in Turbo Pascal 7 with BGI as a teen, a handful of particles before it crawled. Then saw a galaxy collision sim on a CD-ROM magazine disc handling thousands of bodies smoothly. Thought it was assembly tricks.. now I'm sure it's algorithmic (avoiding N**2 runtime) but never dug into the specifics. Are charges vs gravity sims essentially the same n-body problem?


There's two ways of doing it, I implemented them both in my PhD and didn't have a ton of fun doing it.

(a) There's a method that works well for monopolar sources (gravitational + electrostatic particles) called the Barnes-Hut method. You effectively divide space up into a quadtree (2D) or octree (3D), and in each cell work out the center of mass / total charge. You make particles in "nearby" cells (using a distance criterion that can be adjusted to speed up/slow down the simulation in a trade off with accuracy) interact directly, and far away cells you just use the center of mass to work out the interaction between any given 'far' particle and the particles in that cell. The method is O(N log N) but in practice, this is 'good enough' for many applications.

(b) uses a more rigorous technique called the Fast Multipole Method which is O(N), where rather than just using the center of mass or sum of charges, you expand the potential from particles out into higher order components which captures the distribution of particles within each cell. This also means you can capture more complex potentials. The downside is that this is a nightmare to implement in comparison to the Barnes-Hut method. Each cell has it's own multipole expansion, and it is 'transferred' to work out the additive contribution to every 'far' cell, calculating a 'local' expansion. Typically people use the most compact representation of these potential expansions which uses Lagrange polynomials, but this is a pain.


EGAVGA.BGI

Oh this brings memories. I have tried to create a little bit of 3D→2D renderer in TP 6.0 but precision was never enough for nodes to not fall apart and 80286 speed was too slow to render anything meaningful except maybe a cube.


>Are charges vs gravity sims essentially the same n-body problem?

The force falls off as the inverse square of distance in both cases. So they are essentially the same problem. Except that charge can attract or repel and gravity (as far as we know) only attracts.


They might have been using the fast multipole expansion method




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: