Planet Gravity Physics

Started by
17 comments, last by rakoon2 19 years, 5 months ago
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.
Advertisement
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 :)
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.

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.
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.
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.
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.
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.

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

This topic is closed to new replies.

Advertisement