Skip to main content
gamedev.net
🔒 Locked

Gravity - planetary style

Started by Sc4Freak 7 replies 1.5k views
Original Post
Sc4Freak
Sc4Freak
I have a question: how do I implement gravity on a planetary scale? Implementing it for an object on Earth so that it falls to the ground isn't too hard. But how in hell do I implement it for 2 or more planetary objects so that they are all attracted to each other? What are the formulae for this? Provided that nothing but their masses, sizes, positions and distances are known. Thanks.
DrakeSlayer
DrakeSlayer
You use newtons formula : the force attracts the 2 planets, and the intensity of the force is given by M1M2/d^{2}. that is, the force is proportional to the product of the planetary masses and the inverse of the square of the distance between them.

go here : gravitation
McCoy
McCoy
This site, for all your physics needs.
-0100110101100011010000110110111101111001
Raghar
Raghar
dAB = B - A

aproximation vab = k * norm(dAB)* mB/dAB^2

va = vab + vac + vad...

Are you trying to find this?
Things would become more complicated when you'd have nonspherical gravity field.
van Flandern has interesting pages about gravity here : metaresearch.org
Raghar
Raghar
Actually considering the dAB is vector, it should be dAB DOT dAB.
JohnBolton
JohnBolton
2 or more? Just make sure you aren't trying to solve this: n-body problem
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
stuh505
stuh505
Quote:
aproximation vab = k * norm(dAB)* mB/dAB^2


No, that's wrong. Acceleration != velocity.

Quote:
2 or more? Just make sure you aren't trying to solve this: n-body problem


The current equations are impossible to solve ALGEBRAICALLY but numerical solutions can still be 'very' good, good enough for opengl.

Here is my implementation of the nbody problem on our universe (my first opengl program). As you can see, the orbits of every planet even pluto is almost dead on.

http://www.cems.uvm.edu/~sheinric/starfield/
stuh505
stuh505
Raghar's equations look a little bit confusing, it goes like this:

Newton's law of gravity: Each particle of matter attracts every other particle with a force which is directly proportional to the product of their masses and inversely proportional to the square of the distance between them.

Stated mathematically, that is:
Fg = Gm1m2/r^2

Where

m1 = mass 1
m2 = mass 2
Fg = force of gravity on m1 in the direction of m2
= force of gravity on m2 in the direction of m1
G = gravitational constant
r = distance between m1 and m2

Newton's second law: F=ma

Let's say we want to find the motion of m1. Then we want to find F(m1) = m1*a(m1)

Rearranging,

a(m1) = F(m1)/m1
a(m1) = (Gm1m2/r^2)/m1 = Gm2/r^2

So the acceleration of m1 is proportional to the mass of m2 divided by the distance squared.

If you have multiple masses, just sum up the accleration caused by each one.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.