Orbital mechanics simulator in Flash

Thanks for the links! Vessels are an interesting idea, but I'll keep that for later. I'll need much more stuff beforehand, like collision detection. Right now I still have problems to solve with the integration...
For example, the calculation of the velocity using acceleration is still primitive and quite inaccurate, for the next update I'll make it calculate positions using P=p+vt+(1/2)at^2 instead of just adding acceleration to velocity for every timestep.
And there's still RK4 waiting on my "todo list". To implement that, I think I'll have to recode some parts.
By the way my code also needs some tidying up, otherwise it's going to be hell for me to read it in a few years.
 
I think I'm done coding the RK4 part, but the results are rather disappointing. The simulation still seemed to be much affected by the size of the time-steps. Any tips?

Maybe it's a problem with my scenarios. If the distances involved are too small, does that make the scenario very physically unstable, and does this instability pose a problem to the accuracy of RK4?
 
Lots of things updated this time.

http://contland.110mb.com/perso/ob/
test20090604.swf update:
- ADD: Can now center the view on an object.
- ADD: Names and labels for the orbiting objects.
- ADD: Object list shows the names of the orbiting objects.
- ADD: Button to dump some information about the objects, like name, position and velocity.
- ADD: RK4 added! Seems like it's working, because the results of 5fps, 30fps, 40fps and 60fps are quite similar (at least, less difference than the Euler method).
- CHANGE: The viewport displacement buttons used to move only up, down, left and right. Now it can move the viewport in any direction.
- CHANGE: Time acceleration maximum limit has been extended to 600 (positive and negative).
- SCENE: Distances, diameters and masses are now much greater (about 100x). The "Sun"'s color is now changed from black to yellow. Added "Blue planet" orbiting at a great distance. Still trying to make a long-lasting satellite for the "Red planet"...

The time acceleration needs more testing. I want to make sure it's "right". And, the sim seems to have slowed down a lot since last update, how could I fix that?
Feedback is welcome :)

EDIT: Sorry for triple-posting
 
Thanks! :)
The problem now is that the nicer it looks, the slower it is. On my computer, it went from 125fps (test20090506B) to an average of 66fps (test20090604)... That's fps being halved in less than a month.
I don't think this can continue like this, because if it does, the fps will eventually reach zero.

So for the following updates I'll try to focus on performance.

Is this an issue to worry about? If it is, any tips? :)
 
Sometimes centering the view on either Red Planet or Red Moon results in one separating from the other, such that Red Planet is chasing Red Moon around the sun...
 
That also happens if you center on the Sun only. Anyways as I said I'm still trying to make Red Moon a satellite of Red Planet :S and doesn't seem to work yet...

And here another update
http://contland.110mb.com/perso/ob/
test20090604_2ponggame update:
- ADD: Basic collision detection (calculates distances between two objects and compares it to the sum of their radii). When there is a collision, the gravity between the two objects is removed to prevent "planets" from being ejected too easily, so this means the two objects will just "go through" each other. They still are affected by the gravity of other planets they are not in collision with.
- ADD: When an item in the objects list is selected, the "planet" on the screen is also "highlighted" (though smaller planets' highlighters are kind of invisible).
- ADD: Sim info dumping now also includes objects' mass and diameter, besides position and velocity. Units are also added (kg, m, m/s).
- SCENE: Time acceleration arbitrarily set to 2400x (beyond the 600x limit!) just for fun.

I named this "pong game" because... just wait and see :)
The collision detection is doing all sorts of weird things with the planets interacting with the Sun.
 
When I made a Java gravity sim, collisions just never quite looked right to me either because of unrealistic motion or the fact that bouncing causes chaos in a system. So in the end, I just made it so that when two objects collided they would combine into one larger object with the mass being the sum of the two forming it. I actually 'cheated' and just made the larger object increase in mass and the smaller object have mass (and graphical size) of 0 and put it off-screen. It makes it appear as though the smaller object is 'absorbed' into the larger one. This usally doesn't cause near as much chaos as bouncing them off of each other.
 
Nice sim, it's been a while since I last posted here.

That also happens if you center on the Sun only. Anyways as I said I'm still trying to make Red Moon a satellite of Red Planet :S and doesn't seem to work yet...

Be sure that the moon lies well within the sphere of influence of the planet (http://en.wikipedia.org/wiki/Sphere_of_influence_(astrodynamics) and check its references):

r_soi = a_p (m_p / m_s)^(2/5),

where

r_soi is the radius of the planet sphere of influence,
a_p the planet semi-major axis,
m_p the planet mass and
m_s the mass of the central body (the body around which the planet orbits).

I'd put the initial distance between a planet and its moon at 0.8 r_soi or less: for instance, the moon lies at less than 0.5 r_soi of Earth. To check if it works, remove the second planet to reduce the simulation to a 3-body problem.

Edit: the Earth has a soi of 925*10^3 km. It is 0.6% of its mean distance from the sun (~150*10^6 km). On the other hand Jupiter has a soi that is roughly 6% of its sma. If you want to easily visualize the moon, then use a mass ratio between the planet and the central body that is close to the one of Jupiter: ~(10^27 kg)/(10^30 kg) = 10^(-3).

Besides, I ran the simulation at 200x, 400x and 600x and seems slightly unstable. I think that an higher order RK (even reaching 7 or 8) method should be used. How do you determine and control the step size?

A good way to check whether or not the simulation is stable is to sum the mechanical energies (kinetic + potential) of each planet and the primary. Since the system is conservative (no external forces), it should remain constant.
 
Last edited:
Back
Top