# Gravity - planetary style

This topic is 4499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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

##### Share on other sites
This site, for all your physics needs.

##### Share on other sites
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

##### Share on other sites
Actually considering the dAB is vector, it should be dAB DOT dAB.

##### Share on other sites
2 or more? Just make sure you aren't trying to solve this: n-body problem

##### Share on other sites
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/

##### Share on other sites
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.

##### Share on other sites
Ah, thanks. Clears things up quite a bit.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 15
• 14
• 46
• ### Forum Statistics

• Total Topics
634061
• Total Posts
3015302
×