Recommended Posts

I started writing my own game + engine a while ago. After a bit of struggling i managed to write a decent math library for my physics. And a today i finally started working on my physics engine.
After going threw some basic physic formula's i strumpled across a problem. Newtons law of gravitation..
F = G * ((m1 * m2) / r)
a1 = G * (m2 / r)
G = 6.67e-11
The result of these formulas seem to be a float, however i figured using a three-dimensional vector would be more decent for accelerations and forces. So I was kind of wondering how I could alter this formula to result in a vector.
Could I replace the distance (r) with a position1 - position2 vector, or would that corrupt the result?

Share this post

Link to post

Share on other sites

I'm fairly certain that r should be squared. You want gravity to have a larger impact as the objects are closer, and the impact should be smaller as they are farther away.

What is a1 in this system?

But you're a little bit off. The distance should be magnitude(position1 - position2). You need a vector, I'll call it d, which indicates the direction of the force. For your first body, d = position2 - position1 (a vector pointing to position2), and for your second, d = position1 - position2. You can multiply your force equation by this vector (normalize it first) to have your system work with vectors.

I don't know that what I'm telling you is strictly mathematically accurate (there are better physicists around here than me), but it worked fine in the game I made that used gravity. :-)

Cheers,--Brian

0

Share this post

Link to post

Share on other sites

Get the magnitude of the force through f = G*m1*m2/r2 and then multiply by the unitary/normalized vector that goes from body b1 to body b2 dirVec = (body2.position - body1.position)/|body2.position - body1.position|. And you finally get F = dirVec*(G*m1*m2/r2).