2D orbit sim - reworked

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
Hi everyone!

I posted a thread a while back about a simple orbit simulator I'd managed to make. That one was based on the Kepler 2 body problem, which is not a real-time simulation, but rather a pre-determined assumed path.

Today, I found the PDF in the orbiter documentation called 'dynamics' which tells you all about the real-time algorithms Orbiter uses to simulate motion. I really liked the idea of implementing the simplest of these (the single-step linear interpolation) in my own simulation, and I just managed to get it working! It was so rewarding to see the small blue circle doing a perfect elliptical orbit around the red one, based on the raw forces acting on it and nothing else!

I also added the ability to give the small satellite a kick by pressing the space bar, and indeed, the orbit changes based on the new forces applied to the satellite.

Anyway, it's not much, but it is, at the core, a really basic 2d version of Orbiter :)
 

Attachments

  • simlinear.png
    simlinear.png
    1.7 KB · Views: 75

RisingFury

OBSP developer
Addon Developer
Joined
Aug 15, 2008
Messages
6,427
Reaction score
492
Points
173
Location
Among bits and Bytes...
Drop the periapsis to a point really low, close to 0 and watch as the orbit falls apart. The reason for it will be numerical instability. You can then try implementing some of the more advanced methods described in the PDF and you'll notice how much better they perform.
 

mojoey

Bwoah
Joined
May 26, 2011
Messages
3,623
Reaction score
0
Points
61
Hi everyone!

I posted a thread a while back about a simple orbit simulator I'd managed to make. That one was based on the Kepler 2 body problem, which is not a real-time simulation, but rather a pre-determined assumed path.

Today, I found the PDF in the orbiter documentation called 'dynamics' which tells you all about the real-time algorithms Orbiter uses to simulate motion. I really liked the idea of implementing the simplest of these (the single-step linear interpolation) in my own simulation, and I just managed to get it working! It was so rewarding to see the small blue circle doing a perfect elliptical orbit around the red one, based on the raw forces acting on it and nothing else!

I also added the ability to give the small satellite a kick by pressing the space bar, and indeed, the orbit changes based on the new forces applied to the satellite.

Anyway, it's not much, but it is, at the core, a really basic 2d version of Orbiter :)

What language did you write this in?
 

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
It was in C++. You've been learning python, right?
 

statickid

CatDog from Deimos
Donator
Joined
Nov 23, 2008
Messages
1,683
Reaction score
4
Points
38
cool what is the simulated size of the red spot?
 

Rtyh-12

New member
Joined
Sep 12, 2010
Messages
918
Reaction score
0
Points
0
Location
Kraken Mare
I have a short question. How would you describe writing a program with graphics like yours, compared to writing a console application that does the exact same thing? in other words, how much work did it take for you to implement the 'graphics client' of this app?
 

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
cool what is the simulated size of the red spot?

It's 20km in diameter (to calculate the acceleration, the sim uses a scale of 1 pixel = 1km) but the altitude/velocity displays show incorrect units (I changed the scale just to make the orbit progress faster).

I have a short question. How would you describe writing a program with graphics like yours, compared to writing a console application that does the exact same thing? in other words, how much work did it take for you to implement the 'graphics client' of this app?

It actually takes no time at all - I created a 'template' bit of code which I can copy into whenever I make a new graphics program. If you want to learn about graphics and you haven't met windows apps before, then it could take a bit of time to understand what the graphics part of the code means.
 

Rtyh-12

New member
Joined
Sep 12, 2010
Messages
918
Reaction score
0
Points
0
Location
Kraken Mare
It actually takes no time at all - I created a 'template' bit of code which I can copy into whenever I make a new graphics program. If you want to learn about graphics and you haven't met windows apps before, then it could take a bit of time to understand what the graphics part of the code means.

Could you perhaps share any tips with a newbie programmer? How did you learn to make the graphics part?
 

Rtyh-12

New member
Joined
Sep 12, 2010
Messages
918
Reaction score
0
Points
0
Location
Kraken Mare
What programming language/environment are you interested in?

Mostly C++. I used Visual C++ 2010.

To get started with Win32 and GDI (the graphics library used, comes default with windows), take a look at these:

http://www.functionx.com/win32/index.htm

http://www.winprog.org/tutorial/

They are where I got going! Try messing about with the examples - that's how I learn this stuff most effectively.

I'll take a closer look at these after I get home from school, thanks!

If you're interested, try this: codeacademy.com

I had forgotten about that one, thank you for reminding me!
 

Loru

Retired Staff Member
Retired Staff
Addon Developer
Donator
Joined
Sep 30, 2008
Messages
3,731
Reaction score
6
Points
36
Location
Warsaw
Cool little thingie :D Now we wait for UMMu compatibility
 

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
I've made a few changes - added some better graphical touches, and the ability to have up to 10 bodies into the sim. I also used the 'linear interpolation, double pass' algorithm to improve the simulation, especially at high time compressions. In this setup, it only seems to be stable up to about 512x time comp.
 

Attachments

  • orb2d2.jpg
    orb2d2.jpg
    106.5 KB · Views: 35

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
It's not really in a state where I could release it yet, it is actually not very friendly to use. I'm really hoping to post a link soon though :)
 

mojoey

Bwoah
Joined
May 26, 2011
Messages
3,623
Reaction score
0
Points
61
Hey, what equations did you use for the physics, if you dont mind me asking.
 

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
Hey, sure - it's described in the Orbiter docs - in the technotes folder. The PDF is called 'dynamics'. This uses the 'linear interpolation, double pass' method.
 

george7378

DON'T PANIC
Addon Developer
Donator
Joined
Jun 26, 2009
Messages
1,045
Reaction score
0
Points
36
It turns out that the same algorithms can be used pretty well to simulate galaxy collisions too:
 

Attachments

  • galaxycrash.png
    galaxycrash.png
    6 KB · Views: 22
Top