Hi, Ive got a list of particles (where each particle has it's coordinates in space and velocity)(adsbygoogle = window.adsbygoogle || []).push({});

these particles can interact with each-other ([tex]f=\frac{a}{r^4}-\frac{b}{r^8}[/tex])

(i'll add 6 - 12 soon too)

anyway, as it is now, the program has a complexity of [tex]O(\frac{n(n-1)}{2})[/tex]

because every pair has to be calculated to get the force.

the problem is - its too slow for realtime simulation - and i want it to be interactive (changing the temperature, zooming in and out, etc.)

so, i started thinking about approximations i could do to make it work with O(n), and still get good results...

I think calculating the force for near neighbors is enough - but then i need a quick way to know who those neighbors are for a given particle (in less then O(n)).

I thought i'd use an octree (for 3D case) or quadtree (for 2D case), but i can't think of a way to maintain it - because the particles are always moving from place to place... i need to rebuild it each time...

I hope i was clear enough.. my question is - do you think my approach is the best one?

do you have any suggestion as to how to maintain the tree, or alternatively use a better approximation?

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Speeding up particle simulation

**Physics Forums | Science Articles, Homework Help, Discussion**