eggrobin

[WIP][1.5.1, 1.6.1, 1.7.x] Principia—version Fibonacci, released 2019-09-28—n-Body and Extended Body Gravitation, axial tilt

Recommended Posts

Now I really want to see what a planet collision will look

like, and feel like from the ground.

Share this post


Link to post
Share on other sites
Go big or go home. I don't think on rails planets should be a thing anymore. This does n-body for all, Vall gets kicked out in a few days.

Not only that, it turns out that keeping planets on rails is more expensive than doing n-body for them. It has to do with how the calculations work, basically, you want to avoid doing trigonometry (as it's CPU-intensive) while doing as much as you can with simple operations. On-rails Keplerian orbits are done with trigonometry.

Share this post


Link to post
Share on other sites

Mmmh - regarding planet orbits stability, did someone already tested RSS with it, with real life orbit parameters ?

That would be a nice way to test if the code itself does not add onto the already unstable KSP planetary system :) (if the principia's orbits with real planets are stable and match closely real life parameters :))

Share this post


Link to post
Share on other sites
Now I really want to see what a planet collision will look

like, and feel like from the ground.

That's the problem right now, planets are assumed to be point masses which leads to some really weird interactions if they collide, which basically throws them way further out. Ideally planets shouldn't collide obviously.

Share this post


Link to post
Share on other sites
That's the problem right now, planets are assumed to be point masses which leads to some really weird interactions if they collide, which basically throws them way further out. Ideally planets shouldn't collide obviously.

That sounds like the Kraken to end all Krakens. I still want to see it, though.

Alternatively what would happen if on collision the smaller object were just deleted and its mass added to the larger?

A bunch of asteroids spawning would be a nice touch as well.

Edited by ymir9

Share this post


Link to post
Share on other sites
I am curious are you doing n-body with the planets as well? I am wondering if it would just be easier to keep those on rails.

If you would read the first post you would know that the plan for this mod also includes N-body gravitation. And like Dragon01 already stated, on rails planets requires you to solve Kepler's equation which has a trigonometric function in it, but also has to be solved numerically, such as Newton's method, which would require multiple function evaluations. I am not sure if squad is being smart not to solve this for bodies which have a circular orbit (eccentricity of zero), like Kerbin, Mun, Minmus, Laythe, Vall and Tylo, however for circular orbits you would still have to use trigonometric functions.

Share this post


Link to post
Share on other sites
I am curious are you doing n-body with the planets as well? I am wondering if it would just be easier to keep those on rails.

Dragon01 and fibonatic have given a pretty nice summary of the issue here. Also,

Go big or go home.

That is a very good description how things work in this project. :)

I am not sure if squad is being smart not to solve this for bodies which have a circular orbit (eccentricity of zero), like Kerbin, Mun, Minmus, Laythe, Vall and Tylo, however for circular orbits you would still have to use trigonometric functions.

That's a good point, although orbit calculations aren't really a performance concern in stock KSP.

That sounds like the Kraken to end all Krakens. I still want to see it, though.

Alternatively what would happen if on collision the smaller object were just deleted and its mass added to the larger?

A bunch of asteroids spawning would be a nice touch as well.

Doing planetary collisions right would be a lot of work (and simulating the results properly would severely limit your maximum timewarp). Since for all pratical purposes we want stable solar systems (either the real one or KSP's stock one, stabilized as needed), and since not doing things right is not an option (see AndreyATGB's words above :-p), I do not think that falls within the foreseeable scope of this project.

Mmmh - regarding planet orbits stability, did someone already tested RSS with it, with real life orbit parameters ?

That would be a nice way to test if the code itself does not add onto the already unstable KSP planetary system :) (if the principia's orbits with real planets are stable and match closely real life parameters :))

This project has tests. In order to test the integration of the gravitational N-body problem, we evolve the solar system between the launches of áÿутýøú-1 and áÿутýøú-2. The data comes from the JPL's HORIZONS system.

The results are pretty good.

Share this post


Link to post
Share on other sites

Hi, just passing by: did you have any time to work on stationkeeping, maybe, or are you leaving it for later? (I'm curious to know what solutions you would adopt)

Share this post


Link to post
Share on other sites
Hi, just passing by: did you have any time to work on stationkeeping, maybe, or are you leaving it for later? (I'm curious to know what solutions you would adopt)

Sadly, not yet, since I don't even have intrinsic acceleration yet, even outside of timewarp (working on it at the moment).

Share this post


Link to post
Share on other sites

Wow! I had no Idea this was in the works. So very cool! I really hope you are able to finish this at some point and release. Truly impressive, especially since based on what I am reading this will actually improve game performance. Tell me though, since there is no known solution for the 3 body problem how do you deal with three or more body interactions? (sorry if you already answered this, if you did just link the post, don't mean to make you chew your cabbage twice.)

Share this post


Link to post
Share on other sites

Just wanted to say looking at different reference frames is mesmerizing. It looks so wrong but the vessel follows the path exactly even if it looks completely wrong, really cool stuff but I can't handle corotating at all.

Share this post


Link to post
Share on other sites

mcirish3, it's true that there is no closed-form solution to the 3-body problem (or N-body problem for N > 2), but this addon doesn't need one because it basically adds up the forces of gravity from all of the bodies on each other. The same could be done for two bodies, but it turns out that, in that case, the differential equation can be simplified so that Kepler's laws fall out and we can solve for the position of both bodies at any point in time. However, doing so requires solving some tricky inverse-trigonometric functions to link the area swept out by a body (which increases linearly in time) to its actual position, which (I gather) adds up to a fairly hefty computing load when this happens every time-step for every body in the solar system, while AndreyATGB's N-body solver (and eggrobin's plugin, presumably) just has to add up the forces and tweak each body's velocity at every time-step. (There's probably a bit more to it than that, since there's some prediction and filtering, but everything is being solved "forward", which is much easier than solving backwards.)

This comes at a price: because the solution is no longer closed-form, and because our computers only have a finite amount of precision, we cannot predict with certainty where any body will be at any given time. This is where the property of symplecticity comes in (and this is where my knowledge starts to run out -- I am an aerospace engineer and have some coursework in numerical analysis and astrodynamics, but I'm not eggrobin or AndreyATGB, so if any of this is different from how they're doing it, listen to them...). Eggrobin's solver is set up so that it can guarantee that certain system properties (things like energy or angular momentum) are conserved. This will preserve the "character" of each body's trajectory, even if the exact details might vary -- if I leave a spacecraft sufficiently deep in Kerbin's gravity well, for example, I won't find it zooming out of the solar system if I let my system run in time-warp for a while. That said, it probably won't be in exactly the same orbit (as happens to real satellites).

This also opens up possibilities for recreating advanced space missions. By placing a satellite's energy at key threshold values, I can sit back and wait and let it pop out of the Kerbin system (for example) without having to spend the fuel to escape (at the cost of having to wait). This is great for getting larger scientific payloads to other planets, if not so helpful for crewed missions (though it might be good for getting ISRU and other infrastructure pre-deployed).

Share this post


Link to post
Share on other sites

It's a common misconception. There is no analytic solution to the N-body problem. You can have a numerical solution just fine, but you have to solve differential equations. It's much harder than solving the simple Kepler's equation, but by no means impossible. In fact, it turns out that there is a perfectly good method of solving those equations well enough for the purpose of a computer simulation. Principia will be using that to solve the N-body problem numerically, in real time. This does not, contrary to popular belief, require a supercomputer. N-body problem is not any sort of insurmountable obstacle. It does take a certain amount of expertise on the subject to know that, which is why Squad didn't stumble on this idea (they have no actual physicists on the team, and have been dismissing community suggestions about that).

I wouldn't expect a performance gain, quite the opposite, in fact. Stock KSP uses a variation of the Keplerian orbit model (patched conics), which is not very computationally intensive. Numerical integration will not require a supercomputer to run, but it will not improve CPU load, either.

EDIT: Ninja'ed, the above is a more in-depth explanation.

Edited by Dragon01

Share this post


Link to post
Share on other sites

Well, that is what I get for not going beyond a BS in Astrophysics. Very informative, I assumed a numeric solution but indeed I thought it would be prohibitive due to the number of calculations and was really amazed that any sort of practical solution could be arrived at. This concept may be a bit advanced for KSP, I fear, at least beyond its use as a mod. BUT for KSP2 in about 10 years it should be perfect. By the way how will this work with the current game mechanics in regards to nodes and the complexities of transfers.

Edit: By advanced, I mean beyond the scope of what Squad will be willing to implement.

Edited by mcirish3

Share this post


Link to post
Share on other sites

10 years for a sequel is far fetched. Assuming KSP isn't going to use the "continuous expansion" development model (which it may), and assuming Squad doesn't simply move on, then I'd expect 3-5 years between games, at most. Bohemia Interactive seems to have a release timeline like this, with 5 years between ArmA2 and 3. It could be less if they chose a different model. 10 years between games is not a healthy dev time for a single game. And of course, that's talking full releases. Even less time could elapse between full KSP release and the first KSP2 alpha.

That said, implementing such a model would require Squad to hire a physicist who knows the way around those things. Generally, those things don't occur to laymen. Same with features FAR is implementing - "normal" people can work with these things, but an understanding deep enough for implementing it in a game requires one to either already have a degree or at least be on the way to it.

Share this post


Link to post
Share on other sites

Wow, so glad this is still in development !

But as it stands how stable is the current version ?

Others: don't let this derail the thread

Share this post


Link to post
Share on other sites
This is where the property of symplecticity comes in (and this is where my knowledge starts to run out -- I am an aerospace engineer and have some coursework in numerical analysis and astrodynamics, but I'm not eggrobin or AndreyATGB, so if any of this is different from how they're doing it, listen to them...).

Bummer because my next question would be, what is 'symplecticity'?

Eggrobin's solver is set up so that it can guarantee that certain system properties (things like energy or angular momentum) are conserved.

So since we have to use discrete increments determined by the computer's finite precision the output is normalized in a manner that ensures conservation of energy and momentum?

This will preserve the "character" of each body's trajectory, even if the exact details might vary -- if I leave a spacecraft sufficiently deep in Kerbin's gravity well, for example, I won't find it zooming out of the solar system if I let my system run in time-warp for a while. That said, it probably won't be in exactly the same orbit (as happens to real satellites).

We are sticking with newtonian physics in KSP since it is not necessary to include special relativity... or does that add too much complexity?

Edit: Nevermind this question SP is only for non-inertial reference frames and Eggrobin said he was not implementing GR.

Edited by mcirish3

Share this post


Link to post
Share on other sites
10 years for a sequel is far fetched. Assuming KSP isn't going to use the "continuous expansion" development model (which it may), and assuming Squad doesn't simply move on, then I'd expect 3-5 years between games, at most.

Hmm... yes, I was assuming a "semi-continuous expansion" model with some larger DCC along the way over the next two years after 1.0 (which I am grandfathered in to not have to pay for, as are you :) (Squad has indicated as much in their development blog) Since squad itself is a PR firm I rather expect them to sell off the game at some point to a regular gaming company(not that I want them to). My fear is they will sell it to some cooky cutter company like activision with no imagination and no clue what makes the game great.

Please let this be the last post on this though I don't want to derail the main discussion.

That said, implementing such a model would require Squad to hire a physicist who knows the way around those things. Generally, those things don't occur to laymen. Same with features FAR is implementing - "normal" people can work with these things, but an understanding deep enough for implementing it in a game requires one to either already have a degree or at least be on the way to it.

Wouldn't that be cool, a game for physicists by physicists(or rocket scientists), and still easy enough to play that the average Joe could still love the game. On that note I wish it was possible to buy a private copy of KSP EDU. I can see so much learning potential there, I hate being locked out.

Share this post


Link to post
Share on other sites
Bummer because my next question would be, what is 'symplecticity'?

Sorry for not being clear -- symplecticity (when talking about numerical integrators) *is* the property of guaranteeing that certain quantities that are conserved in reality are also conserved by the simulation, to ensure that closed orbits don't accidentally become escape or entry trajectories (for example), even if the exact orbital parameters might drift over time. I know that much, though I couldn't tell you how to implement such a thing. From what I've picked up, it seems that it's achieved by making some predictions at what conditions will be at tn+2 and maybe even beyond, and using that information to "smooth out" the resulting tn+1 so that total energy doesn't jitter as much. (I'm going to echo eggrobin's plea for LaTeX support on the forum.) From the end of eggrobin's explanatory post on Hamiltonian mechanics, it seems the next explanatory post will go into more detail on that.

We are sticking with newtonian physics in KSP since it is not necessary to include special relativity... or does that add too much complexity?

For precision guidance and scientific measurement, "real" aerospace engineers (especially those involved in space systems) have to take relativity into account because the only way to measure distances and speeds is to measure the propagation of radio waves, which means lots of clocks measuring signals passing through various gravity levels and traveling at different speeds have to figure out what time it "really" is. One of the problems in a class I took on relativity was to compute the rate of GPS error that would accumulate if the system didn't take relativity into account, and it's something like hundreds of kilometers per day. The clocks would drift out of sync by tiny fractions, but when multiplied by the speed of light, that adds up to a big distance error.

However, KSP has everything embedded in a game engine, so we can know exactly what time it is and exactly how far apart things are. We also don't have to measure any actual scientific data -- we click the button and get the science points. Given that, relativity would only matter if things were moving around at large fractions of the speed of light (the gamma factor, which governs length contraction and time dilation, only increases from 1 to 1.01 at 14% of c), which they aren't (bugs aside).

That said, if Squad (or anyone) ever did feel like including relativistic effects, the MIT Game Lab has produced a Unity package for doing exactly that (and made a game with it).

On that note I wish it was possible to buy a private copy of KSP EDU. I can see so much learning potential there, I hate being locked out.

  1. Become a volunteer at a school
  2. ??? (host after-school space/science club, perhaps)
  3. Obtain KerbalEdu!

Share this post


Link to post
Share on other sites
while AndreyATGB's N-body solver

I didn't write a single line of code for this project, wish I could. I have a basic understanding of the physics and math involved but nowhere near enough to actually contribute. I just like sniffing around code and for the most part, silently compile unfinished stuff.

Share this post


Link to post
Share on other sites
For precision guidance and scientific measurement, "real" aerospace engineers (especially those involved in space systems) have to take relativity into account because the only way to measure distances and speeds is to measure the propagation of radio waves, which means lots of clocks measuring signals passing through various gravity levels and traveling at different speeds have to figure out what time it "really" is. One of the problems in a class I took on relativity was to compute the rate of GPS error that would accumulate if the system didn't take relativity into account, and it's something like hundreds of kilometers per day. The clocks would drift out of sync by tiny fractions, but when multiplied by the speed of light, that adds up to a big distance error.

This is exactly what I wanted to say. Even in real life, relativity is relevant if you want to get things right.

Share this post


Link to post
Share on other sites
That said, if Squad (or anyone) ever did feel like including relativistic effects, the MIT Game Lab has produced a Unity package for doing exactly that (and made a game with it).

  1. Become a volunteer at a school
  2. ??? (host after-school space/science club, perhaps)
  3. Obtain KerbalEdu!

Thanks for the game tip I am going to try the game out today :)

As for volunteering at a school I wish I could but I have 4 children under the age of 5 and a full time job as a data analyst. KSP is really the only way I still keep in touch with any science at all other than the occasional FB post that come my way from former classmates.

Share this post


Link to post
Share on other sites
Just wanted to say looking at different reference frames is mesmerizing. It looks so wrong but the vessel follows the path exactly even if it looks completely wrong, really cool stuff but I can't handle corotating at all.

The corotating reference frame is confusing, but it's the only frame in which you can see orbits around Lagrange points.

the next explanatory post will go into more detail on that.

It will. :)

Symplectic actually means that it preserves the symplectic map, but this also means that first integrals (total energy, momentum, and angular momentum) don't drift (they aren't exactly conserved, but the error doesn't get worse with time). Moreover, the result of the integration is the exact solution of a system defined by some perturbed Hamiltonian.

Note while you could make an integrator that preserves first integrals exactly (by projecting onto a state with the right H, p and L), this actually turns out to be useless, the result is aberrant (e.g. stable orbits degenerate), since it is not the solution of a perturbed Hamiltonian.

For precision guidance and scientific measurement, "real" aerospace engineers (especially those involved in space systems) have to take relativity into account because the only way to measure distances and speeds is to measure the propagation of radio waves, which means lots of clocks measuring signals passing through various gravity levels and traveling at different speeds have to figure out what time it "really" is. One of the problems in a class I took on relativity was to compute the rate of GPS error that would accumulate if the system didn't take relativity into account, and it's something like hundreds of kilometers per day. The clocks would drift out of sync by tiny fractions, but when multiplied by the speed of light, that adds up to a big distance error.

This is exactly what I wanted to say. Even in real life, relativity is relevant if you want to get things right.

This would be a job for RemoteTech. Of more relevance to this mod is, e.g., the precession of the perihelion of Mercury. It appears that a perturbation can be added to account for GR, so I might do that at some point.

  1. Become a volunteer at a school
  2. ??? (host after-school space/science club, perhaps)
  3. Obtain KerbalEdu!

If you actually want to learn things about physics (or engineering) beyond the Kepler problem (which you can readily investigate in stock KSP, and is about the only thing KSP does right), I'd suggest a different list:

  • Install KSP for 2-body gravitation;
  • Install FAR for reasonable aerodynamics;
  • Install RSS for reasonable planet sizes, densities, etc.;
  • Install Real Fuels for reasonable chemistry;
  • Install Realism Overhaul (I was just listing some requirements for it anyway);
  • Have fun while waiting for Principia to be released, learn about aerodynamics, chemistry, engineering... in the process;
  • ???
  • Install Principia.

Of course you can also take a look at the recommended reading.

Share this post


Link to post
Share on other sites
The co-rotating reference frame is confusing, but it's the only frame in which you can see orbits around Lagrange points.

Ah... I wish I could say now I get it, and I am determined to get it, at one time I think I did get it. Let me see if my memory serves me well or not. L1,L3 and L5 are unstable equilibrium points and L2 and L4 are stable equilibrium points. L5 is special in that it the single point where a satellite could remain stationary relative to the barycent. (I am betting I got this all wrong so please no one smack me up side the head for being stupid)

If you actually want to learn things about physics (or engineering) beyond the Kepler problem (which you can readily investigate in stock KSP, and is about the only thing KSP does right), I'd suggest a different list:

  • Install KSP for 2-body gravitation;

Did I miss this mod? I guess I will look for it thanks for the tip.

  • Install FAR for reasonable aerodynamics;
  • Install RSS for reasonable planet sizes, densities, etc.;
  • Install Real Fuels for reasonable chemistry;
  • Install Realism Overhaul (I was just listing some requirements for it anyway);
  • Have fun while waiting for Principia to be released, learn about aerodynamics, chemistry, engineering... in the process;
  • ???
  • Install Principia.

Of course you can also take a look at the recommended reading.

Yes, I installed RSS for 0.23 I am thinking of trying again on 0.25. But I do think I will need to take your advice on the recommended reading before I do.

Thank You all your hard work. I really think what you are doing is one of the greatest contributions made to the KSP community so far. (right up there with all the work done by NathanKell).

Share this post


Link to post
Share on other sites

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.