Sign in to follow this  
Nightwalk

Planet Gravity Physics

Recommended Posts

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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Why is venus going the wrong way? Don't all of the planets move in the same direction?

Keep it up though, let's see all the planets.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by Anonymous Poster
Why is venus going the wrong way? Don't all of the planets move in the same direction?


Nightwalk seems to have confused two things here: Venus is orbiting the sun in the same direction as the other planets, but Venus' rotation is retrograd.

You'll probably know that, but the planets and the sun are way too large compared to the distances between them (but else there would be barely visible dots....). The distances of the planets also don't seem to be correct - especially Jupiter should be farther from sun compared to the other planets.

If you want to make the simulator more realistic, besides calculating gravity of one planet acting on the other ones, you've to take into account that the planets are not in one plane and the sun is also moveable.

Quote:
Original post by Nightwalk
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


No, if the orbit is parabolic the planet will drift out of the system and won't come back.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by 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
NightWalk


Your comet changes its orbit but that's probably only due to limited accuracy - if it is at its perihel the errors are larger because the acceleration is proportional to 1/r^2.

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites

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 );



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this