Skip to main content
gamedev.net
🔒 Locked

Planet Gravity Physics

Started by Nightwalk Nov 11, 2004 at 10:17 AM 17 replies 3.3k views
Original Post
Nightwalk
Nightwalk
yahoo! I think I have done it! I have made a gravity Simulator for a Planetary Solar System! I have not implemented all 9 planets, Just the first 4. And the Hale Bopp comet. Take A look at this VB Source Code. You can download the .exe too. Can someome tell me if I have actually implemented the gravity correctly? I used 2D cartesian Vectors to combine the forces of gravity and planet momentum to get the new planet vectors. And why is it so hard to get a parabolic orbit, mostly they are circular or eliptical? Is it like this in reality? I guess so! Nightwalk
Squirm
Squirm
A parabolic orbit?

If something is going very very fast you will get a hyperbolic and it will never come back. If something is going slowly enough it will form an ellipse. If it is going exactly at the point where it ceases to be an ellipse and becomes hyperbolic, it will be a parabola. The circular ones are just special cases of the elliptical ones.
Nightwalk
Nightwalk
ohh i see, so it is just very unlikely to become a parabola?
So to become parabolic, Does the planet have to slightly drift out of orbit for a second and then come back in at a different ellipse?
That seems to make sense! cool
My simulator also doeesn't apply gravity of other planets to each other :(

NightWalk
jperalta
jperalta
Quote:
Original post by Nightwalk
My simulator also doeesn't apply gravity of other planets to each other :(
NightWalk

Take a course in astronautics and you'll see that that's how most scientists model the universe as well. The two-body system makes modelling much easier and due to the fact that the sun is several orders of magnitude more massive than any other planet you can assume that its gravity force is also several orders of magnitude larger than the gravity force of any other planet on the other. Picture an object of mass 1e30 kg exerting a gravitic force at 1e8 m on a mass of 6e24 kg, F = Gc(Mm)/r^2 = Gc(1e30*6e24)/(1e8)^2 = Gc*6e38. Now consider a mass of 1e27 kg exerting a gravitic force at 7.5e8m on a mass of 1 6e24 kg, F = Gc(1e27*6e24)/(7.5e8)^2 = 1e34. That's the force of Jupiter on Earth. The force of Jupiter on earth is 4 orders of magnitude smaller than the force of the sun on earth, therefore it can basically be ignored in calculations.
chowe6685
chowe6685
the shape of the orbit is determined by the energy of the system E =1/2*mv^2 - G*M*m/r
if this is <0 the orbit is circular or elliptical, if it is >0 the orbit is hyperbolic, if it is =0 the orbit is parabolic
rtw1701
rtw1701
Thats a pretty cool demo.
Mayrel
Mayrel
Quote:
Original post by jperalta
Quote:
Original post by Nightwalk
My simulator also doeesn't apply gravity of other planets to each other :(
NightWalk

Take a course in astronautics and you'll see that that's how most scientists model the universe as well. ... The force of Jupiter on earth is 4 orders of magnitude smaller than the force of the sun on earth, therefore it can basically be ignored in calculations.

For planetary orbits, that's generally true. Mainly because planets stay within their orbits.

Things like comets, on the other hand, may pass very close to planets and be effected by them.
jperalta
jperalta
Quote:
Original post by Mayrel
Quote:
Original post by jperalta
Quote:
Original post by Nightwalk
My simulator also doeesn't apply gravity of other planets to each other :(
NightWalk

Take a course in astronautics and you'll see that that's how most scientists model the universe as well. ... The force of Jupiter on earth is 4 orders of magnitude smaller than the force of the sun on earth, therefore it can basically be ignored in calculations.

For planetary orbits, that's generally true. Mainly because planets stay within their orbits.

Things like comets, on the other hand, may pass very close to planets and be effected by them.


Yeah, that's when you get into spheres of influence, and changing from a two-body system between the body and the sun and the body and the planet. But it's still always done as a two-body system.
Squirm
Squirm
The observation of discrepencies in the motion of a planet which then leads to the discovery of a new planet further out would be a counter example :)
darookie
darookie
Quote:
Original post by Squirm
The observation of discrepencies in the motion of a planet which then leads to the discovery of a new planet further out would be a counter example :)

Indeed. Current observations suggest at least one earth-sized planet far beyond Neptune's orbit (I for one don't regard Pluto a planet[smile]). I don't think a simple simulation is able to reflect such effects, though, so I would ignore it, too.

Kurioes
Kurioes
I took a look at the source code... You should just do maths with the planets' velocity and position vectors (don't calculate angles), and try RK4 integration instead of Euler integration.

The comet's orbit will probably show less "drift" because numerical errors are lots smaller when using RK4 (Runge-Kutta 4). In general it'll be a lot more stable.

If you're interested you can read about RK4 here. Chapter 16.

EDIT: this is the result of 10 orbits on my adaptive RK4 implementation (in mathematica). Nearly an ellipse (It shows signs of numerical error - note how fat the line is).

So... it's really worth the effort.
King of Men
King of Men
While planet-planet interaction is usually ignored for simple applications like space flight, it is not usually ignored for this sort of model. It's true that the equations cannot be solved analytically, but then, that's not a computer's forte anyway, and the numerical calculation is pretty simple to implement even for a many-body system.

I think your cometary orbit is a bit too small. Where are you getting your numbers?
To win one hundred victories in one hundred battles is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Nice Coder
Nice Coder
ok, your using a timer. Thats a pretty big no no.

Look Here

I would recommend you make a render loop. (more fps, faster simulation, more steps/second.)

Look at the link abouve on how to make it.

All in all, nice sim. But avoid timers like the plague.
From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
darookie
darookie
Quote:
Original post by Nice Coder
ok, your using a timer. Thats a pretty big no no.

I don't think so. This is a sim, not a game and timers provide you with a pretty stable base for numerical integration.
While your advise is good for games, it is not so important for simulations like this. Decoupling fixed-step physics simulation from rendering would be possible, though.

Regards,
Pat.
Nice Coder
Nice Coder
Timers do not time accuratly (not good for sims).

Render loops can be good for sims too.

From,
Nice coder
Click here to patch the mozilla IDN exploit, or click Here then type in Network.enableidn and set its value to false. Restart the browser for the patches to work.
rakoon2
rakoon2

Isnt the gravity force calculated by this formula:


F = (G * m1 * m2) / r²


G.. Gravity constant 6.6742e-11
m1.. Mass of object one.
m2.. Mass of object two.
r.. Distance btwn the objects.


Eg:
const double cGravity = 6.6742e-11d;Vector2 Gravity = Vector2.Zero;double distancex = planet1.x - planet2.x;double distancey = planet1.y - planet2.y;double cgf = cGravity  * planet1.mass * planet2.mass;Gravity.x = cgf / distancex;Gravity.y = cgf / distancey;planet1.AddForce( Gravity );

Topic Locked

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

Sign in to reply to this topic.