Jump to content
  • Advertisement
Sign in to follow this  

Gravity - planetary style

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!