Archived

This topic is now archived and is closed to further replies.

zipless

equations for calculation planetary orbits

Recommended Posts

I think this is quite a simple question, so simple in fact that although there are hundreds of references to the equations all over the net noone actually bothers to write it down. I''m writting my first proper game and i''ve just finished the planning stage and i''m working on some of the base code. The game is going to feature some moons in orbit around a plannet and i need any equations relating to elliptical orbits. I can work out circular orbit easily enough and i''m pretty sure that i can work out the equations for a static elliptical orbit if i put my mind to it (i''d rather not) but i have no idea where to start on variable elliptical orbits. By static i mean on each rotation it passes through the same points, a variable orbit will *turn*, the elliptical shape itself rotating. The plannet is assumed to be static, it has a mass and thats it (i''m using point forces). I''m plnnaing on giving the moons a mass, distance from the plannet center and an initial angular velocity. Feel free to pick holes in my design, i just hope that my explnation has been clear enough, it''s been a while since i''ve used any physics. So, anyone got an idea where i start? zipless /* Ignorance is bliss, then you go and spoil it by learning stuff */

Share this post


Link to post
Share on other sites
Well. I think, I would try to go for basic laws that would automatically give you your nice complex orbits.
The only formula I can think that is appliable is
Gm1m2 / d^2.
Basically, G is universal gravitional constant. Forgot it. Look it up =P. D = distance, m1 = mass 1, m2 = mass2.
That should give you the gravity''s force.
Then, use F = ma to get the acceleration. But, you should work out all the forces from all objects, of sizable mass (planet, other moons, etc.) and sum them all, in 3d I guess to -use vectors =P
Then take the final, summed up force, and divide by mass of current object, that will give you a in 3d. Then, add that to the velocity (which is kept from frame to frame). Then, take the position, and add the velocity * time. But, all in 3d
Hmm. I''m having a hard time seeing how this would get you actual orbits. I think the model needs angular momemtum, maybe? or perhaps centrigual force... or both... or maybe impulse? argh!
See - I haven''t learnt about angular momentum, just linear momeemtum and centrigual force. But that is in a circular orbit.

That''s all I know!
Good luck

------------------------------
BCB DX Library - RAD C++ Game development for BCB

Share this post


Link to post
Share on other sites
You could run a search on google for Kepler's Laws, though I doubt they would get you any farther than you already are. I would try c++freak's suggestion by applying impulses at fixed timesteps, using the equation:

Fg = G * (m1m2)/r2

This would be my first attempt. If you find that this type of integration is unstable then you can first decrease the step size, and then, if that doesn't work, attempt another form of integration.



Edited by - TerranFury on February 5, 2002 7:51:29 PM

Share this post


Link to post
Share on other sites
The issue of orbiting bodies has been discussed many times in this forum. I would urge you to search the archives for more information.

The majoy consideration is though that the period of orbit of most planetary bodies is much greater than the period of time spent in a planetary system. This would mean that the players would barely notice the motion of the planet, even if they sat and stared at the screen for hours (which might equate to days of game time). You would be better served by pre-compiling a look-up table of positions of the planet for the period of orbit (most planetoids have periods of months to years) and simply placing the planet at the appropriate location when the players enter the planetary system.

Use Keplar''s laws to compute these positions.

Cheers,

Timkin

Share this post


Link to post
Share on other sites
Cheers guys, i had already worked my way through the equations that C++freak mentioned and i know how i can plot the course of an orbital. The real problem is creating the variables for a stable orbit, at the moment if i give the plannet a mass and the orbital a mass, spearation and velocity it''s likely to crash into the plannet or spin off into space, i was hoping that there was some formula for determining a stable orbit.

I''m sure i can work out the velocity needed for a static elliptical orbit based on the orbitals intial velocity being x,90degrees then when quater of the way round it being x,180degrees. Or to put it another way vert=0 horz=x, vert = Z, horz=0. But this won''t work for variable elliptical orbits.

Timkin : A very valid point but the entire system will be visible on screen and i''m going to speed things up by moving the masses closer so that the orbit is around 1 to 2 minutes in length (hopefully). I can''t just plot a course because there *may* be other bodies that pass through the system which can influence the orbitals path.

I think i''m just going to finish off an app tht plots the course of the bodies and put figures in and see what happens. Im guessing velocity A will result in plannetfall, velocity Z will spin the mass out of orbit, Z-a wee bit will be a circular orbit, M will be a static ellipse and either side will be variable ellipses. Just a guess though.


zipless


/* Ignorance is bliss, then you go and spoil it by learning stuff */

Share this post


Link to post
Share on other sites
quote:
Original post by zipless
Timkin : A very valid point but the entire system will be visible on screen and i''m going to speed things up by moving the masses closer so that the orbit is around 1 to 2 minutes in length (hopefully). I can''t just plot a course because there *may* be other bodies that pass through the system which can influence the orbitals path.



That''s fair enough. You''re in for some real troubles though. Simulating a stable 3-body system is a complete nightmare. There is no analytic solution. If you really do want to simulate the gravitational dynamics of your planetary system then you should apply a small viscousity to the space that the plaents are moving in. This will have the affect of damping the oscillations induced by wayward objects flying through your system; like space ships or asteroids. It wont guarantee stability though.

Good luck! You''ll need it!

Timkin

Share this post


Link to post
Share on other sites
Kickass!

I''ve got my app running to simulate orbits (took ages thanks to my coders block) and it''s turned up some rather interesting results.

It turns out that in a simple system with only 2 masses beign taken into account, the plannet and the orbital, that almost all orbits are stable. A rotating elliptical orbit appears to degrade into a circular orbit although i''m not yet sure what factor affect this rate of decay. It seems to take <100 orbits to decay but thats more than enough for my needs.

One possible reason for this is that there is no escape velocity, nothing apart from the plannet can pull on the orbital so it always drags the moon back



zipless


/* Ignorance is bliss, then you go and spoil it by learning stuff */

Share this post


Link to post
Share on other sites
dammit. looks like i was wrong. although the ellipses do becomme more circular the orbits always increase, so give it enought time and the plannet will just get further and further away.

I''m hoping that this is due to my scrappy way of calculating the movement. I''m using the acceleration applied over a second to get the new velocity then use it to plot the new position. I''m almost certain thats where the extra energy is entering the system. I''ll put on my calculus hat and work out the equations for the REAL displacement tomorrow.

I''ll post the results cos as far as i know noone has posted anything similar to this before.

zipless

/* Ignorance is bliss, then you go and spoil it by learning stuff */

Share this post


Link to post
Share on other sites
quote:
Original post by zipless
dammit. looks like i was wrong. although the ellipses do becomme more circular the orbits always increase, so give it enought time and the plannet will just get further and further away.



This can happen with simple integration methods such as Euler''s method. E.g. if you do pos = pos + vel * time, but the time interval is long enough that the velocity is non-constant, then the position calculated can be slightly out. For orbits like this adding a vector in the direction of motion each time places you further and further outside the orbit, so gradually increases the orbit radius.

You can try various things. Simplest is decrease the time step/increse the frequency of calculations. In a calculation like this doubling the frequency makes the calculations 4x as accurate. The same effect can be achieved by slowing down the rate of revolution, so if you make your simulator run in real time, where orbits take months or years, it will probably be much more accurate.

Another way is force energy conservation by calculating the energy (kinetic and gravitational-potential) after each step, and rescaling the velocity, radius or both to make sure the energy stays the same. This might not preserve the shape though.

Third use a more sophisticated integration step, such as a higher order Runge-Kutta integrator. They are easy to use, and just carry out many more calculations to achieve a far more accurate result.

Share this post


Link to post
Share on other sites