Jump to content

KSP inspired me to really learn orbital mechanics


Beduino

Recommended Posts

KSP inspired me to really learn orbital mechanics and now I have my own orbital "map view" of the solar system and "The Ship".

javaw%202013-11-22%2011-18-58-04.png

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2011-18-33-45.png

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2011-19-15-29.png

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2011-19-37-52.png

Taking the ship to the moon.

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2011-31-45-51.png

javaw%202013-11-22%2011-36-23-43.png

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2011-36-31-18.png

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2011-36-44-16.png

And mars

javaw%202013-11-22%2016-30-28-13.png

https://dl.dropboxusercontent.com/u/13532547/javaw%202013-11-22%2016-33-32-31.png

http://i.imgur.com/i013YDw.png

http://www.reddit.com/r/KerbalSpaceProgram/comments/1qpc1l/ksp_inspired_me_to_really_learn_orbital_mechanics/

Great time window to go to mars, which explains why there is a recent outbound of mars probes launching.

After years of studying astronomy and being a Computer Engineer with a extensive knowledge in computer graphics&math myself, doing it was actually much easier than i thought, did most of it in a week. I never had so much fun, wish we could do something fun like this in reality, i mean really doing a manned mission to Mars or something.

Right now I have this working:

Real scale and real time 3d solar system.

Mix of sphere of influence, patched conics and verlet integrator for newtons laws mostly for ships(kind inaccurate but enough for now).

Planets are calculate based on kepler's equations.

Only vector (lines) graphics.

Conics orbits rendering and maneuvering of ship like entities, which you can accelerate towards prograde-retrograde and other direction vectors.

Who knows what's next, not sure about new features, but it's definitely my new playground.

Edited by Beduino
Link to comment
Share on other sites

Actually i'm using libgdx/java just for simplicity, LWJGL is just the backend. So this thing would very likely run on android as well lol

Well i was not thinking about releasing any source/or binaries, also it's a bit messy, but if you are interested in something in particular i could probably explain and show some sample code.

Link to comment
Share on other sites

Mix of sphere of influence, patched conics and verlet integrator for newtons laws mostly for ships(kind inaccurate but enough for now).

Unfortunately, Verlet integration is very bad for gravity problems. If you know anything about general Runge Kutta methods and multi-variable optimization algorithms, I strongly suggest you take the time to build an implicit integration scheme. In particular, 6th order Gauss-Legendre method should work for this much better than anything you can compute explicitly.

Link to comment
Share on other sites

Unfortunately, Verlet integration is very bad for gravity problems. If you know anything about general Runge Kutta methods and multi-variable optimization algorithms, I strongly suggest you take the time to build an implicit integration scheme. In particular, 6th order Gauss-Legendre method should work for this much better than anything you can compute explicitly.

Indeed verlet is just bad, but for some reason my RK4 integrator was even worse. Must be a mistake in code I'm overseeing. Got to try even better implicit integrators, but there was no real reason for these on the beginning when i was just starting :P

Link to comment
Share on other sites

Unfortunately, Verlet integration is very bad for gravity problems. If you know anything about general Runge Kutta methods and multi-variable optimization algorithms, I strongly suggest you take the time to build an implicit integration scheme. In particular, 6th order Gauss-Legendre method should work for this much better than anything you can compute explicitly.

Just got my RK4 working, there was a small mistake in the problem formulation for orbital simulation.

The precision is just amazing compared to verlet.

I was studying the 6th order Gauss-Legendre, but it seems it's way more involved math problem then it appears initially, because the formulation for a gravity field would involve solving a system of polynomials (non linear equations).

Not sure it's worth the precision at this point.

Link to comment
Share on other sites

Also, would it be able to simulate n-body physics, possibly also orbital decay? I'm thinking ISS.

nbody physics is totally doable but other things would then be much harder, like orbital prediction, encounters and so forth. Basically things that can be solved easily by kepler elements/equations would just break down.

Link to comment
Share on other sites

I was studying the 6th order Gauss-Legendre, but it seems it's way more involved math problem then it appears initially, because the formulation for a gravity field would involve solving a system of polynomials (non linear equations).

Not sure it's worth the precision at this point.

Yes, that's why I mentioned optimization problems. There are some cases when it's worth trying to work through polynomial forms analytically, but gravity isn't the case. You are better off treating it as finding a root of a general, non-linear system of equations. There are some solvers for that which you can try, or write your own. So long as you don't have anything too wild, Gauss-Newton algorithm should converge for a gravity problem. If you'll feel like going for NASA grade precision, give it a try. It's a challenge, but the sort that makes you feel good when you get it working.

Whether you need it or not is a different question. If you want to be able to plot space ship trajectories or predict paths of comets, you do. You can test yourself by comparing your integration to data from JPL's Horizons. Pick a comet that passes close to a planet, and see if your computations agree with NASA's predictions.

If you don't need that sort of precision, and you just need something believable, then explicit methods are fine, and yes, higher order methods will definitely work better.

The only reason Verlet is so popular is that it does extremely well with harmonic potentials. So if you model collisions with Hook's law, you don't need anything fancier. Hence for most video game physics, Verlet integration is the only thing one ever needs to know.

Link to comment
Share on other sites

That's really interesting indeed, again thanks for the tips.

I'm a bit familiar with Horizons, used it to obtain the parameters for the siding spring comet coming close to mars in 2014, to view it in Celestia.

As for the 6th order Gauss-Legendre and the non linear system, if I have some extra time i might give it a try. Not sure I would implement it all by myself. There's a alternative to Guass-Newton called Levenberg-Marquardt method, both are implemented in apache commons math and is based on MINPACK, http://commons.apache.org/proper/commons-math/userguide/optimization.html

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/optimization/general/LevenbergMarquardtOptimizer.html

I'm not sure if it's possible to adapt the problem and use this library as the solver, that would be a time saver.

Guess i can also improve the Rk4 with variable step size and there are other higher order RK's that also can give better results.

Yes, that's why I mentioned optimization problems. There are some cases when it's worth trying to work through polynomial forms analytically, but gravity isn't the case. You are better off treating it as finding a root of a general, non-linear system of equations. There are some solvers for that which you can try, or write your own. So long as you don't have anything too wild, Gauss-Newton algorithm should converge for a gravity problem. If you'll feel like going for NASA grade precision, give it a try. It's a challenge, but the sort that makes you feel good when you get it working.

Whether you need it or not is a different question. If you want to be able to plot space ship trajectories or predict paths of comets, you do. You can test yourself by comparing your integration to data from JPL's Horizons. Pick a comet that passes close to a planet, and see if your computations agree with NASA's predictions.

If you don't need that sort of precision, and you just need something believable, then explicit methods are fine, and yes, higher order methods will definitely work better.

The only reason Verlet is so popular is that it does extremely well with harmonic potentials. So if you model collisions with Hook's law, you don't need anything fancier. Hence for most video game physics, Verlet integration is the only thing one ever needs to know.

Link to comment
Share on other sites

You are probably going to start seeing diminishing returns with higher order RK. This is a bit hand-wavey, but basically, the Nth order RK is going to be "seeing" a polynomial expansion of your potential. Unfortunately, expansion of 1/r around some r=R is given by a series (-1)nxn/Rn+1. This is geometric convergence, which isn't the worst thing in the world, but it still means you have to fight for each digit of precision. What's worse, when x/R is small, such as slow moving object far from source of the potential, the series converges quickly, and you can get away with low order RK anyways. When you start seeing RK giving poor results, it tells you x/R is large, and higher order RK method is going to give improvements that much slower. So going to higher order RK ends up giving you least improvement where you need it most.

Variable time step is a good idea. It's going after that very x/R term. Since x is roughly proportional to time step and velocity, you can actually keep it constant and have the same quality of integration everywhere. Of course, as R gets smaller, velocity increases, so the time step would have to get very small close to sources. And you'll have to figure out how to keep track of different time steps for different objects in simulation. So it's still not trivial, but definitely something to try.

I have been wondering whether it's possible to build a set of collocation points for a 1/r potential to integrate it exactly. I haven't seen anything like that in the literature, so I'm guessing that even if possible, it probably goes really bad when multiple sources are present. Still, I think I'll try it at some point to see how and when things go wrong.

Link to comment
Share on other sites

Found this very interesting site with more detailed info on the jpl horizon integrator.

http://www.moshier.net/ssystem.html

They use another integrator, which leads me to believe it's very cumbersome to solve the polynomial system in 6th order gauss legendre method

You are probably going to start seeing diminishing returns with higher order RK. This is a bit hand-wavey, but basically, the Nth order RK is going to be "seeing" a polynomial expansion of your potential. Unfortunately, expansion of 1/r around some r=R is given by a series (-1)nxn/Rn+1. This is geometric convergence, which isn't the worst thing in the world, but it still means you have to fight for each digit of precision. What's worse, when x/R is small, such as slow moving object far from source of the potential, the series converges quickly, and you can get away with low order RK anyways. When you start seeing RK giving poor results, it tells you x/R is large, and higher order RK method is going to give improvements that much slower. So going to higher order RK ends up giving you least improvement where you need it most.

Variable time step is a good idea. It's going after that very x/R term. Since x is roughly proportional to time step and velocity, you can actually keep it constant and have the same quality of integration everywhere. Of course, as R gets smaller, velocity increases, so the time step would have to get very small close to sources. And you'll have to figure out how to keep track of different time steps for different objects in simulation. So it's still not trivial, but definitely something to try.

I have been wondering whether it's possible to build a set of collocation points for a 1/r potential to integrate it exactly. I haven't seen anything like that in the literature, so I'm guessing that even if possible, it probably goes really bad when multiple sources are present. Still, I think I'll try it at some point to see how and when things go wrong.

Link to comment
Share on other sites

Just improved the orbital simulator a little bit.

Added force of drag, quite cool for aerobraking, orbits change in real time much like in KSP.

Added some moons (for mars and jupiter), although couldn't find the rate of orbital elements for moons in a nice format except here, can't get the rates correct so moons just dont seem right at any given time.

javaw%202013-11-22%2011-18-33-45.png

javaw%202013-11-22%2011-18-58-04.png

javaw%202013-11-22%2011-19-15-29.png

javaw%202013-11-22%2011-19-37-52.png

Taking the ship to the moon.

javaw%202013-11-22%2011-31-45-51.png

javaw%202013-11-22%2011-36-23-43.png

javaw%202013-11-22%2011-36-31-18.png

javaw%202013-11-22%2011-36-44-16.png

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...