views:

439

answers:

8

I'm interested in doing a "Solar System" simulator that will allow me to simulate the rotational and gravitational forces of planets and stars.

I'd like to be able to say, simulate our solar system, and simulate it across varying speeds (ie, watch Earth and other planets rotate around the sun across days, years, etc). I'd like to be able to add planets and change planets mass, etc, to see how it would effect the system.

Does anyone have any resources that would point me in the right direction for writing this sort of simulator?

Are there any existing physics engines which are designed for this purpose?

+7  A: 

It's everything here and in general, everything that Jean Meeus has written.

alt text

Stefano Borini
Nice! Didn't even know this existed. Many of the other books are expensive monographs.
Ade Miller
+4  A: 

You need to know and understand Newton's Law of Universal Gravitation and Kepler's Laws of Planetary Motion. These two are simple and I'm sure you've heard about them, if not studied them in high school. Finally, if you want your simulator to be as accurate as possible, you should familiarize yourself with the n-Body problem.

You should start out simple. Try making a Sun object and an Earth object that revolves around it. That should give you a very solid start and it's fairly easy to expand from there. A planet object would look something like:

Class Planet {
  float x;
  float y;
  float z; // If you want to work in 3D
  double velocity;
  int mass;
}

Just remember that F = MA and the rest just just boring math :P

David Titarenco
Yuo probably want to consider polar coordinates. They're often easier when it comes to orbital mechanics.
MSalters
True, but you'll have to plot the planets on screen (I assume), so might as well do the initial calculations on a Cartesian plane.
David Titarenco
Converting between Cartesian and polar coordinates is trivial, so do the calculations in whatever is more convenient and convert as necessary.
David Thornley
+3  A: 

You might want to take a look at Celestia, a free space simulator. I believe that you can use it to create fictitious solar systems and it is open source.

High Performance Mark
+2  A: 

All you need to implement is proper differential equation (Keplers law) and using Runge-Kutta. (at lest this worked for me, but there are probably better methods)

There are loads of such simulators online.

Here is one simple one implemented in 500lines of c code. (montion algorhitm is much less) http://astro.berkeley.edu/~dperley/programs/ssms.html.

Also check this:
http://en.wikipedia.org/wiki/Kepler_problem
http://en.wikipedia.org/wiki/Two-body_problem
http://en.wikipedia.org/wiki/N-body_problem

ralu
Do not use Runge-Kutta (RK4)!. Use Velocity Verlet (or a higher-order symplectic method, such as Lobatto IIIA-IIIB) instead. RK4 is higher order but lacks the structure preserving properties of the latter, and using it will result in your planets eventually drifting out to space or crashing into the sun.
You should post an answer as well mr. unknown!
Gaius
Well in high school we checked few numerical derivation methods. Leapfrog (Velocity Verlet) had property that it did not preserve energy. (Differential equation was actually Keplers law). From what i have checked, Runge - Kutta preserved energy (other methods had so called energy drift) and I implemented aprox 5 methods and if somebody wants to see my first programming attempts there should be still some matlab files somewhere on my backup.
ralu
A: 

If you're simulating physics, I highly recommend Box2D.
It's a great physics simulator, and will really cut down the amount of boiler plate you'll need, with physics simulating.

Ink-Jet
+2  A: 

This is a great tutorial on N-body problems in general.

http://www.artcompsci.org/#msa

It's written using Ruby but pretty easy to map into other languages etc. It covers some of the common integration approaches; Forward-Euler, Leapfrog and Hermite.

Ade Miller
A: 

Check out nMod, a n-body modeling toolkit written in C++ and using OpenGL. It has a pretty well populated solar system model that comes with it and it should be easy to modify. Also, he has a pretty good wiki about n-body simulation in general. The same guy who created this is also making a new program called Moody, but it doesn't appear to be as far along.

In addition, if you are going to do n-body simulations with more than just a few objects, you should really look at the fast multipole method (also called the fast multipole algorithm). It can the reduce number of computations from O(N^2) to O(N) to really speed up your simulation. It is also one of the top ten most successful algorithms of the 20th century, according to the author of this article.

Justin Peel
A: 

Fundamentals of Astrodynamics by Bate, Muller, and White is still required reading at my alma mater for undergrad Aerospace engineers. This tends to cover the orbital mechanics of bodies in Earth orbit...but that is likely the level of physics and math you will need to start your understanding.

+1 for @Stefano Borini's suggestion for "everything that Jean Meeus has written."

semiuseless