PDA

View Full Version : Kepler's laws demo



cragwolf
15-05-2006, 05:33 AM
Here's an OpenGL demonstration of Kepler's three laws of planetary motion (source code only):

http://www.ludicity.org/files/kepler.tar.gz (190 KB)

The movement of the planet(s) is determined by numerically integrating Newton's equations of motion, rather than simply applying the analytical solution to those equations (which Newton worked out over three centuries ago, inventing calculus in the process!) But it's nice to see for oneself that numerical techniques can reproduce (to reasonable accuracy) the behaviour described by Kepler's laws.

A few screenshots are here (http://www.ludicity.org/images/kepler1ss.png), here (http://www.ludicity.org/images/kepler2ss.png) and here (http://www.ludicity.org/images/kepler3ss.png).

You can switch from one law to the next/previous by using the RIGHT/LEFT arrow keys. SPACE pauses/resumes the simulation, and ENTER returns it to the starting state. L shows labels (and other info). You can click and drag the Sun and planet(s) around (when in the starting state) to change various orbital parameters. F1 for help on all these options and more.

I've only tested it on Linux with the Free Pascal compiler. It uses the JEDI-SDL headers. Compilation is as simple as fpc -Mobjfpc kepler.pp :)

WILL
15-05-2006, 08:17 AM
Very nice work! :)

I'll have to hold on to this one for future reference. One of my other projects may be able to incorporate something from it. (Space shooter)

Robert Kosek
15-05-2006, 05:19 PM
Awesome job! This one is a keeper for sure, and I'll be looking real close at Kepler's Law. I'm going to be hacking apart every line of code over the next few hours/days.

I just thought of this, but FPC has never worked well on my PC (the compiler and not the compiled apps) so is there I chance I can get a compiled version from you?

cragwolf
16-05-2006, 02:15 AM
Here's an executable compiled on WinXP:

http://www.ludicity.org/files/kepler.zip (278 KB)

I think there may be a bug with the 3rd law demonstration. The movement of the inner planet is a bit jerky. I'll look into it. I just wish I knew how to code in a more structured, less spaghetti-like manner.

Robert Kosek
16-05-2006, 03:03 AM
Thanks! :) Very, very interesting to see it for myself.

Mind if I ask a few questions at this or other points? I might make use of this when I've the time to get back into game design.

Just a heads up, but fullscreen and mouse input don't operate in the compiled version. I just remembered that I have access to a linux comp though.

aidave
16-05-2006, 04:52 AM
But Keplers Law doesnt work if you attach a rocket to a planet and fly around randomly.

cragwolf
16-05-2006, 06:03 AM
Mind if I ask a few questions at this or other points? I might make use of this when I've the time to get back into game design.

You can ask questions, but I can't guarantee an answer. I'm just an amateur at this sort of thing. I'll do my best, though.


Just a heads up, but fullscreen and mouse input don't operate in the compiled version.

Mouse input only works when the planets are paused and in their starting states. Press ENTER to get them into this state. You can drag the Sun in all three laws (this changes the eccentricity of the orbit), you can drag the two planets in the second law (this changes their starting position), and the inner planet in the third law (this changes its semi-major axis). I hope that works for you.

The fullscreen problem is a Windows bug or limitation: SDL_WM_ToggleFullScreen doesn't work in Windows. But I know of a workaround for that problem, and so I'll add that in when I get the chance. For now, you can run the demo in fullscreen mode by using the appropriate command-line option. For example,

kepler -f -g=1600x900

will run the demo in fullscreen mode at a resolution of 1600x900. Run kepler -h to see some more command-line options.


But Keplers Law doesnt work if you attach a rocket to a planet and fly around randomly.

Kepler's laws work for their intended domain of applicability: the gravitational two-body problem. For other problems in mechanics, one should apply Newton's laws, and take into account all the forces that are relevant to the situation. Like I did in my demo. :)

aidave
16-05-2006, 08:03 PM
Kepler's laws work for their intended domain of applicability: the gravitational two-body problem. For other problems in mechanics, one should apply Newton's laws, and take into account all the forces that are relevant to the situation. Like I did in my demo.

fair enough :wink: