I have many particles in space.
Each particle knows its position in space as well as some things like mass, velocity, and acceleration.
public class Particle
{
float mass;
float velocity;
float acceleration;
}
I have a class that controls the gravity. This class has a List
of all Particles
. I can calculate the force of gravity of two Particles using the formula below.
F1 = F2 = G*M1*M2/d^2
How do I calculate this when I have 5 particles in my List? There will be more in the future.
Element 0 with 1, Element 1 with 2, Element 2 with 3, Element 3 with 4, and Element 4 with 0? (This doesn't seem to be a good idea).