PDA

View Full Version : Orbit Gravity Simulator Assistance Required

DanThaiWang
2011-Feb-04, 01:30 PM
Hello,

Thanks for stopping by.

I'm a web developer with a keen interest in Astronomy. I've been working on an Orbiter application using Flash Actionscript 3.0 (since this is my native language to use). Please have a look here :

http://danthaiwang.wordpress.com/2010/11/05/pldm-orbiter/

It's very early in development, as is pretty obvious I think.

I have managed to create lots of pretty patterns resembling the Spirograph toy I remember as a kid but when I try to make a uniform collection of bodies orbiting a single larger massive object I get a little stuck.

For example the inner bodies I added close to the massive object (let's call it The Sun from now on) orbit nicely and continuously without any problems. I seem to, however, hit a bit of a wall when I get to a certain area away from The Sun. Please see the picture below :

Apologies, it's a bit of a mess. Now, inner most you see a small dot, this is The Sun. Next you have an orbit of a much smaller body and outside that a blue orbit of similar size. Let's call these Venus and Earth for now (sorry Mercury).

I add these bodies to the environment by giving them a mass, a starting xPosition, starting yPosition, xVelocity and yVelocity.

Now then, it seemed to me the most logical way of doing this is by giving The Sun the starting position of x:0 and y:0. For the sake of the test I gave it a mass of 500.

Venus, the closest planet in this system, has a mass of 6, starting x:-750 and a y:0. So, this means that when she starts off I only need to give her a y-Velocity, since she's in line with The Sun, she can only go upwards in order to be pulled around. So, after a bit of trial and error I figured out that a start y-Velocity of -56 (these are actually pixels per frame) swings her around and produces a more-or-less circular obit. Nice.

Earth has a mass of 6.25, starting x:-3000, y:0, x-Vel:0, y-Vel:-50. This also brings it around into a nice circular orbit. Not perfectly but nothing's perfect so that's good enough for me.

Mars... that pesky little planet, is where I run into problems. As you can see by the diagram I can't find the perfect y-Velocity to get it going in a circular orbit. The most it manages at any time is about 1.5 orbits before either diving into the centre or flying off into the wilderness. Here are it's attributes :

Mass : 2.5
x : -5000;
y:0;
x-Vel : 0
y-Vel : Varies, see diagram.

On top of this, I find that I can keep splitting the velocity down to 6 or 7 decimal points and it still goes either inwards in a death spiral or outwards to oblivion.

My question is this :

Am I struggling to nail these outer orbits for any of the following reasons, or a combination of all of them.

1. Actionscript simply can't support the number of decimal points required to get an accurate starting velocity. This could be a rounding issue.

2. I haven't taken into consideration the rotation of The Sun and the extra momentum this would give these bodies in real life. If this is the case, why do the inner planets work fine?

3. Anything to do with me just using pseudo figures pseudo units? I figured although it's not accurate figures, it's using the basic rules of physics which seems to work closer to the sun.

Sorry it's such an open question. I can imagine it's quite a nightmare one to have to deal with. Anyway, if you follow the link to the app at the top of this thread, there's a download link where you can play with the starting values and add/remove planets.

DanThaiWang
2011-Feb-04, 04:05 PM
Thanks for posting this up.

Since posting I thought of the following:

a) I assumed that since this is Fraser's background (software development) he may be able to assist from an actionscript/javascript POV?

b) I've seen the simelar posts at the bottom and am now reading through these, so sorry if it's repative, I did a search but couldn't find anything specific.

c) Cheers for Astronomy Cast. Listen to it every week, got the t-shirt. And Phil Plait, I read your book over Christmas (Death from the Skys!). Most enjoyable!

Thanks again.

Hornblower
2011-Feb-04, 05:39 PM
My hunch is that interplanetary gravitational perturbations are doing you in here. Your hypothetical planets are huge in proportion to the central body. Our Sun is over 300,000 times Earth's mass, while yours is less than 100 times the mass of your largest planet. Try starting with the central mass at 1,000,000 and see what happens.

DanThaiWang
2011-Feb-04, 06:05 PM
Ah, I forgot to mention that I did actually begin with my experiments with my sun having a mass of 330'000. I then made the earth mass 1. This made it even more difficult to control and alas, I ended up in the same position I find myself in now. I get much more stable results when I use similar masses, such as ratios of 1/1 2/1 3/1 and even up to 10/1. In the case of my example at the top earth is actually comfortably in the zone that I can handle.

Thanks for the suggestion though.

grav
2011-Feb-05, 12:27 AM
Hi DanThaiWang. You could try looking through this thread (http://www.bautforum.com/showthread.php/57336-More-precise-orbital-simulation-program?highlight=simulator) for some programming code. It also includes a link to Tony873004's simulator programming forum and an experimental "qq method" in post #117 which might help to better stabilize the orbits.

cjameshuff
2011-Feb-05, 05:22 AM
Ah, I forgot to mention that I did actually begin with my experiments with my sun having a mass of 330'000. I then made the earth mass 1. This made it even more difficult to control and alas, I ended up in the same position I find myself in now. I get much more stable results when I use similar masses, such as ratios of 1/1 2/1 3/1 and even up to 10/1. In the case of my example at the top earth is actually comfortably in the zone that I can handle.

Well, you're not going to get realistic results with unrealistic masses...

Do you get the same outward spiral without the other bodies in the system? It seems likely the large masses are at least part of the issue, but if a 2-body system also has problems, there's something else going on. Are you perhaps updating the position of each planet in turn? You should compute the future locations (or just the forces or accelerations) of all planets and then step them ahead simultaneously.

Here's a working 2D JavaScript model of the inner solar system, basing the orbital distances and velocities on the actual planets:
http://tmp.arklyffe.com/solarsim.html

frankuitaalst
2011-Feb-05, 05:22 PM
I have managed to create lots of pretty patterns resembling the Spirograph toy I remember as a kid but when I try to make a uniform collection of bodies orbiting a single larger massive object I get a little stuck.
.
This sentence caught my eye .
Planets usually dot not spiral in or out . At most they circulate in elliptical orbits . I think it's a good idea to go through the code of integration . The link Grav provided may give some clues .

DanThaiWang
2011-Feb-07, 09:54 AM
Are you perhaps updating the position of each planet in turn? You should compute the future locations (or just the forces or accelerations) of all planets and then step them ahead simultaneously.

I hadn't considered this but I will try this next. I am actually programming this in an object orientated manner so each body has makes a calculation and then applies a "pull" method on each other body. I suppose I could instead pass each calculation to a central proxy type class which then applies it simultaneously each frame. Thanks for the suggestion.

Hi DanThaiWang. You could try looking through this thread for some programming code.

Thanks grav for the link. I'll have a read through and see what comes up.

cjameshuff
2011-Feb-07, 11:49 PM
I hadn't considered this but I will try this next. I am actually programming this in an object orientated manner so each body has makes a calculation and then applies a "pull" method on each other body. I suppose I could instead pass each calculation to a central proxy type class which then applies it simultaneously each frame. Thanks for the suggestion.

Sounds like you're overcomplicating things. Just have separate force calculation and position/velocity update steps, or have each body keep two sets of positions/velocities and use a simulation-wide iteration counter to decide which one is the current position/velocity and which is the future position/velocity being calculated at the current step.

John Mendenhall
2011-Feb-08, 02:20 AM
Hm, yes, you're reinventing the wheel, or in this case the 'software orrery'. Search for them on the Web. There are free ones.

DanThaiWang
2011-Mar-31, 08:24 AM
Ah yes... that old chestnut. The way I see it is not reinventing.... no, but building for myself, to learn and gain knowledge and on top of everything to have fun. I did indeed search the web, this is page 1 of "I'm starting a new project". Besides, the free ones out there have been built, are in stone. I can add as much functionality as I want I am in control. This for me is the key to these projects. If we always use the existing products then we'll never have any need to more forward.

Thank you everyone for helping me with this. When/if it's ever finished I'll stick it out there and then this too will be another free one for others to use and more so, enjoy playing with.

Cougar
2011-Apr-01, 03:08 AM
On top of this, I find that I can keep splitting the velocity down to 6 or 7 decimal points and it still goes either inwards in a death spiral or outwards to oblivion.

Rejoice. You have discovered chaos. :)

Yes, you should use test bodies, which are essentially massless, and you needn't calculate their effect.

Your orbits should be more robust. The distance determines what lateral velocity will produce a circular orbit. Reducing or increasing that velocity will give you ellipses of increasing eccentricity. Where are your ellipses? Yes, they will likely precess if you are time-stepping as opposed to integrating time, but you can say the precession is just taking Einsteinian gravitation into account. :rolleyes: