I want to simulate gravity like a planet around the sun or galaxies colliding but how do I use the equations in my particle class which uses the projectile motion equation
//update position
x = (int)((0.5 * gx * SQRD(t)) + (ivx * t) + ix);
y = (int)((0.5 * gy * SQRD(t)) + (ivy * t) + iy);
z = (int)((0.5 * gz * SQRD(t)) + (ivz * t) + iz);
where gx, gy and gz is gravity, t is time, ivx is initial velocity and ix is initial position.
And the formula for gravity:
F = (m2)a = G(m1)(m2)/r^2
a = G(m1)/r^2
so if I find the distance x between the planet particle and the sun particle I simply use
gx = GRAVITY_CONSTANT / distancex^2?
and when the particle updates it's position it'll integrate the acceleration due to gravity x,y,z and get the position. Seeing as distance y and z = 0 then the only acceleration is x which makes the planet move straight instead of an orbit.. And in the opposite direction to the sun as well! It comes back eventually though which is a bit weird..
i must be missing out something..
edit: Please don't say Kepler's laws

i want to do this using gravity equation first
[edited by - Kyo on August 30, 2002 3:44:38 PM]