Making a particle engine, need help!
Hi! I have started creating a particle engine. It is going to simulate air and water.
Now I have a question. To make it look realistic you will have to make the particles react with each other, since every water molecule pushes or pulls in other water molecules. How do I calculate the force between two water molecules (or in this case, particles)? Between two air molecules? I have made a simulation program for air turbulence before, but the physics became much simpler then since I used a map over the densities at different places instead of particles, and a map for the velocities (I also limited the simulation to two dimensions). However that type of simulation has disadvantages, like air that moves just horizontally or vertically, or that the air in one square (like pixels in the map) will get “blurred” when moving between two squares.
Besides, how can you calculate the pressure in water with a certain density at a certain temperature? That is simple to do with gasses since you can use the ideal gas law. Since I also had a map over the temperature at different places, this was possible. I could even make a lens by decreasing the temperature inside of it to make the sound travel slower. A sound wave could then be concentrated at a specific point by using such a “temperature lens”, that was pretty cool.
My other question is about optimizing the algorithm so that advancing one frame ahead doesn’t take O(n^2) time to do, but O(n) time. By only looking at say the 8 or 20 or something like that closest particles, you can still get a realistic simulation right? You don’t have to look at every particle in the whole system. I guess then you will also have to modify the physics to make it do about the same thing as it would have done if you would have looked at every particle? Now my question is, how do I know which particles I should look at? And when I know which particles to look at, I need to have access to those particles in constant time to make the whole simulation run in O(n) time, do I have to use some special kind of structure for that? Like a dynamic grid between particles or something? I know that this s not a question about physics, but sometimes mathematicians happen to be pretty good at programming to.
I would love to get as much help as possible with this thing, information about how to do it is welcome, also if you can refer to some good site maybe a Wikipedia article I could read about this in I would be thankful. Thanks in advance.