- #1

walter

- 4

- 0

Is there anybody that's done this that could give me some tips?

You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter walter
- Start date

- #1

walter

- 4

- 0

Is there anybody that's done this that could give me some tips?

- #2

chroot

Staff Emeritus

Science Advisor

Gold Member

- 10,275

- 40

- Warren

- #3

Nereid

Staff Emeritus

Science Advisor

Gold Member

- 3,401

- 3

It's probably a good idea to start with some simplifying assumptions.

For example, treat the Earth as a homogeneous sphere, and consider it the only massive object (other than the satellite - I'm assuming you want to simulate the orbits of satellites around the Earth). You could also ignore general relativity for your first few versions.

- #4

marcus

Science Advisor

Gold Member

Dearly Missed

- 24,770

- 791

walter said:

Is there anybody that's done this that could give me some tips?

I did, years and years ago. Probably chroot and nereid did too but they are not volunteering the information

Did you ever write a bouncing ball program?

Nereid is right about simplifying. For starters make the problem real real simple.

the Earth is just a point with a certain mass

the satellite is just a dot going around the earth

you even can work ONLY IN TWO DIMENSIONS so all vectors are just two numbers, an x component and a y component

you fix on some time interval like one second, or ten seconds, or a minute

at each iteration you calculate the acceleration of something at the sat's position

you add that to the existing velocity to get the new velocity

you see how his position changes (in one time interval) using that new velocity

you find his new position

then you go around the loop again (find new accel. find new veloc. find new position, find new accel find new veloc find new position...)

doubtless there are refinements but what the heck this will make the dot move on your screen!

- #5

enigma

Staff Emeritus

Science Advisor

Gold Member

- 1,757

- 17

- #6

marcus

Science Advisor

Gold Member

Dearly Missed

- 24,770

- 791

enigma said:

do you remember the bouncing ball in "Men in Black" which keeps picking up energy?

Tommy Lee Jones and Rip Torn have to duck

you will find out lots of interesting things

small numerical errors can accumulate and the orbits can blossom

I urge you to try ASAP to write the simplest orbit program and then

you can refine it if you want

- #7

walter

- 4

- 0

I guess I can start with the Sun & Earth.

- #8

marcus

Science Advisor

Gold Member

Dearly Missed

- 24,770

- 791

walter said:

I guess I can start with the Sun & Earth.

great

you will be able to specify some initial conditions in your program

like say the Earth starts 100 units out

and you can specify the initial speed and direction that it is moving

perhaps you can specify 4 numbers

positionX, positionY, velocX, and velocY

perhaps you decide to start with posX = 100, and posY = 0

and perhaps velocY = 1

with velocX = 0

then the program will take over and move the dot around on the screen

please tell us when you have something running

it may be possible later to refine it so it can work better or to have several planets or make it work in 3D

- #9

enigma

Staff Emeritus

Science Advisor

Gold Member

- 1,757

- 17

What language are you planning on writing this in?

- #10

walter

- 4

- 0

My plan was to use visual basic 6.0

- #11

ceptimus

- 299

- 1

I did one in Java, which is the same as C really.

You can see it http://www.mround.pwp.blueyonder.co.uk/programming/orbits/orbits.htm.

You can see it http://www.mround.pwp.blueyonder.co.uk/programming/orbits/orbits.htm.

Last edited by a moderator:

- #12

litghost

- 2

- 0

- #13

walter

- 4

- 0

Could you give me a couple of pointers where to start?

- #14

ceptimus

- 299

- 1

You need to specify the masses, initial position, and initial velocities of all the planets. The only other things you need are 'Big G', the gravitational constant, and as you don't really want to wait for a whole year for the Earth to go round once, you need a time multiplier (how many times faster than reality the simulation is to run).

If you do 'view source' from your web browser while my sim is displaying, you will see how they are defined for my program (and you can play with the values if you copy the page to your own machine).

The program works in time slices. You only need the simplest of calculations to work out the new position and velocity of each body after each time slice.

The force, f, between any two bodies, M1, and M2 separated by distance d is:

f = G * M1*M2 / d * d

You can totalize all the forces acting on a body from each other body - the easiest way is if you resolve the forces into X and Y (and Z if you work in 3D) components.

The acceleration, a is given by a = m / f

The new velocity v, from previous one u is given by v = u + a * t

New position is just the old position plus the velocity times the time (you can use either the old or the new velocity - it doesn't really matter if the time increment is small).

I'll send you the source code if you wish (it's in java, which is similar to C) Drop me a PM if you want it.

A Visual Basic implementation should be pretty easy to do - I only did it in java, rather than some other language, as I wanted to stick it on a web page.

If you do 'view source' from your web browser while my sim is displaying, you will see how they are defined for my program (and you can play with the values if you copy the page to your own machine).

The program works in time slices. You only need the simplest of calculations to work out the new position and velocity of each body after each time slice.

The force, f, between any two bodies, M1, and M2 separated by distance d is:

f = G * M1*M2 / d * d

You can totalize all the forces acting on a body from each other body - the easiest way is if you resolve the forces into X and Y (and Z if you work in 3D) components.

The acceleration, a is given by a = m / f

The new velocity v, from previous one u is given by v = u + a * t

New position is just the old position plus the velocity times the time (you can use either the old or the new velocity - it doesn't really matter if the time increment is small).

I'll send you the source code if you wish (it's in java, which is similar to C) Drop me a PM if you want it.

A Visual Basic implementation should be pretty easy to do - I only did it in java, rather than some other language, as I wanted to stick it on a web page.

Last edited:

- #15

turin

Homework Helper

- 2,323

- 3

Do your simulations incorporate GR? (I don't speak java, C, or probably any other language you can think of, so I don't think I would be able to figure it out from there.)

- #16

ceptimus

- 299

- 1

No turin. It only uses Newtonian mechanics, and even that is only approximated - the velocities and positions are only calculated at each time interval, so the orbits would actually consist of many small straight line jumps, if you could zoom in enough to see them up close.

Providing the time intervals are short enough, relative to the orbital period though, this is quite accurate enough, and even NASA uses such methods to calculate the trajectories of its space probes.

You only really get a noticable difference between Newtonian calculations and General Relativity ones when the speeds become an appreciable fraction of the speed of light - and for situations where the speeds (compared to light speed) are low, Newtonian calculations are much simpler and faster to do. :)

Providing the time intervals are short enough, relative to the orbital period though, this is quite accurate enough, and even NASA uses such methods to calculate the trajectories of its space probes.

You only really get a noticable difference between Newtonian calculations and General Relativity ones when the speeds become an appreciable fraction of the speed of light - and for situations where the speeds (compared to light speed) are low, Newtonian calculations are much simpler and faster to do. :)

Last edited:

- #17

tony873004

Science Advisor

Gold Member

- 1,753

- 143

Sorry for pulling up such an old thread, but I've only been a member of this facinating forum for about 2 weeks. But I did exactly what you described. I wrote an orbit simulator in VB 6.0. You can download it here: www.gravitysimulator.comwalter said:

Is there anybody that's done this that could give me some tips?

It performs its calculations on a 3d universe. It uses Euler's method, a first-order method. I'm hoping to post a new version in about a month or two that will use a Runge-Kutta4 engine as well.

Walter, it doesn't look like you've posted since April, so I doubt you'll read this, but if you do, and you still want to tackle such a project, let me know and I'll be happy to help you.

Actually, the first order Euler method works remarkably well. With a timestep as large as 16767 seconds per time step, the solar system holds together for over a million years. Probably more, as I ended the simulation at 1 million years because it took my computer a month to do. I can speed this up to 65536 if I remove moons from the solar system. Faster than that causes Mercury to deviate from its orbit.enigma said:

In fact, the Euler Method is accurate enough that if I use JPL's Horizons system to accurately place the planets in their January 1, 2003 position, Mars and Earth pass each other at exactly the right time and distance as the real Mars did August 2003 when it made its closest approach in 60000 years. Running the simulation further into the future, Mars also passed Earth at the correct time and distance for its next opposition (2005? I think). But the 2007 opposition came about 2 days early or late, but at the right distance, and the 2009 or 2010 opposition was about 7 days off its predicted date, but the correct distance. I'm not sure if Runge Kutta would give better results here. I might just need a more accurate value for G or for Sun mass.

In the post titled Sedna in this forum, check posts an article about the origin of Sedna's orbit. Doing a Google on the scientist's name in that article I located his paper at http://www.boulder.swri.edu/~hal/PDF/CR105.pdf . I was able to use my program to reproduce his simulation of a 0.05 solar-mass brown dwarf with bodies orbiting in the 20-100 AU range, passing 200 AU from the Sun with a starting velocity of 1km/s. My simulation unfolded almost exactly like theirs did. 8 of the 20 test particles orbiting the brown dwarf entered solar orbits after the passage.

The new version I hope to release soon is over 10x faster because I've cleaned up the code and put the Euler engine in a C++ dll. It may be even faster still if I can get my RK4 engine working.

- #18

- 10,188

- 1,351

Here is what I would suggest, as far as the general layout of your program goes.

As far as the differential equation solver, I'd recommend starting with an out-of-the-book Runge Kutta method. Apparently there are no "Numerical Recipies in Visual Basic" books. This isn't necessarily the best alogrithm, but it's rugged and standard and "good enough", and once you get it up and running, you'll be in a position to plug in a different algorithm using the same interface if you really want to.

http://www.vb-helper.com/books_recommended.html#numerical_algorithms [Broken]

suggests that the "Numerical recipies in Fortran" will be the easiest to translate into visual basic. If you've got the money, buy the book, but if you don't, get a copy from the library.

I would suggest getting your numerical integrator to correctly solve

dx/dt = x. (The soluiton is of course x=exp(t)).

before attempting to actually use it to generate orbits. The next step is to get it to solve the equations of motion for a circular orbit.

Because it's canned, I'd suggest starting with the differental equation solver. Using the data structures of the canned solver will impact the design decisions made in the rest of your programming project.

- An initial conditions input module, which accepts the planets masses, initial velocities, and positions
- A module which generates the equations of motion. I would suggest using the Hamiltonian formulation of the equations of motion if at all possible, unless the math turns out to be beyond your level.
- A differential equation solver module. Use a standardized interface so you can replace this module with different variants as the program evolves. See the notes below about using a "canned" differential equation solver.
- A plotting/graphing display module, which displays the results.

As far as the differential equation solver, I'd recommend starting with an out-of-the-book Runge Kutta method. Apparently there are no "Numerical Recipies in Visual Basic" books. This isn't necessarily the best alogrithm, but it's rugged and standard and "good enough", and once you get it up and running, you'll be in a position to plug in a different algorithm using the same interface if you really want to.

http://www.vb-helper.com/books_recommended.html#numerical_algorithms [Broken]

suggests that the "Numerical recipies in Fortran" will be the easiest to translate into visual basic. If you've got the money, buy the book, but if you don't, get a copy from the library.

I would suggest getting your numerical integrator to correctly solve

dx/dt = x. (The soluiton is of course x=exp(t)).

before attempting to actually use it to generate orbits. The next step is to get it to solve the equations of motion for a circular orbit.

Because it's canned, I'd suggest starting with the differental equation solver. Using the data structures of the canned solver will impact the design decisions made in the rest of your programming project.

Last edited by a moderator:

Share:

- Last Post

- Replies
- 2

- Views
- 405

- Replies
- 10

- Views
- 334

- Last Post

- Replies
- 1

- Views
- 1K

- Last Post

- Replies
- 2

- Views
- 753

- Last Post

- Replies
- 4

- Views
- 572

- Last Post

- Replies
- 19

- Views
- 939

- Last Post

- Replies
- 4

- Views
- 947

- Last Post

- Replies
- 9

- Views
- 334

- Last Post

- Replies
- 2

- Views
- 745

- Last Post

- Replies
- 2

- Views
- 994