I'm currently writing a program that attempts to simulate particle movement in a gravitational field with more than one object exerting a force on it.
I decided that I'd have the particle move by constantly assigning it with new velocity vectors. This is determined as follows:
I loop through each object inside the scene that isn't the particle. I use the equation: A = GM/R^2 to determine the acceleration that the particle will feel with respect to the current object. Then I multiply the distance vector (difference X, difference Y) between the particle and the object by the Acceleration and add that to a list.
I loop through the final list of all Acceleration Vectors, and add the X's together and the Y's together in order to determine the resultant acceleration vector will be on the particle.
I take this resultant acceleration vector, and then set it as the velocity vector of the particle.
While I think I've gotten the resultant acceleration down okay, I keep finding myself unable to figure out how I would account for the particles current velocity.
I could add it as a vector to the list of acceleration vectors acting on the particle, but it doesn't behave properly.
For example, if I attempt to get a particle to orbit an object, I expect to use the equation:
V = sqrt(G*M/r) to get myself the appropriate velocity needed to orbit the object.
However, even with both the acceleration vector and velocity vector sharing the same magnitude, the particle behaves as follows:
In Scene 1, R is the resultant vector of both V and A. This will now be set as the particles new velocity vector.
In Scene 2, you can see that R is now again the resultant between V and A, but the problem is that V is now incorrectly represented and thus the resultant will angle even more towards the surface of the object.
I quickly saw that this was a problem, I couldn't be setting velocity as resultant acceleration. But I can't think of how I would properly implement it either. The current velocity would have to be 'angled' 90 degrees to the acceleration vector, but I cannot envision how I could determine this in the infinite amount of other cases where it won't be a perfect 90 degrees.
I'm beginning to feel that I've made some major mistakes in the entire implementation of this model too, and if anyone could suggest how I could properly account for velocity that would be such a help.