Steven Mading

Where in the API is the value of G the game is using?

Recommended Posts

I assume KSP *has* to have Newton's Gravatational Constant, G, somewhere as a constant in the API.  But I cannot find it in the PhysicsGlobals, which is where I'd expect a thing like that to be.

In kOS I had given up trying to find it and just typed it in myself as a literal value in the kOS C# code, from a Wiki search.

But this caused a problem.  I did that back before NIST had adjusted the official value of G from 6.67384E-11  to 6.67408E-11.  And KSP apparently has at some point adapted to using the newer value, and kOS hadn't.  This small difference caused a few users to have kOS scripts with slightly wrong results when trying to be extremely precise in their calculations for things like geostationary orbits, etc.

So the right thing to do seems to be NOT to just hardcode the newer value into kOS, but rather to actual read the value that KSP itself is using.  After all, inside the KSP universe, it's the value KSP is using that is more "correct" and gives the right answers.

So far the only thing I've got is to find G indirectly, by picking a CelestialBody at random, and taking its gravParameter and dividing out its mass.

Share this post


Link to post
Share on other sites
1 hour ago, Steven Mading said:

Not surface gravity, but the "G" in this formula:

KSP has no need for such formula and does not use it.

Share this post


Link to post
Share on other sites
8 hours ago, Boris-Barboris said:

KSP has no need for such formula and does not use it.

It still has an implicit G that it's using, and it switched from 6.67384E-11  to 6.67408E-11 at some point in development, using the newer value NIST published more recently.  It may be that it *encodes* this G indirectly by embedding it inside the gravitational parameter of each body and never storing it anywhere else independently of that, but it still did change.  So the answer is, that it doesn't exist and I have to compute it by using one of the CelestialBody objects and calculating it backward from that.  While it could be that this is how KSP does it, it seems like a weird design choice to have to have a human being "write" the mass of each body, and then ALSO redundantly write down the gravitational parameter of each body.  If G had been stored somewhere globally, then writing the mass of the planet would be sufficient to get its gravitational parameter without having to type that in too.  Typing in both mass and mu leaves room for them to disagree with each other if it's not done right, which is why that's a very strange decision to do it that way.

Share this post


Link to post
Share on other sites

KSP does not use N-Body physics. All planets are on rails. As stated above. Therefore it does not need G in any orbit calculations.
It stores a gravParameter for each CelestialBody in their Unity prefabs. So, if you want to know what it is you can divide CelestialBody.gravParameter by CelestialBody.mass for any given planet.
It's 6.67408e-11 btw.

 

Share this post


Link to post
Share on other sites
On 1/15/2019 at 3:00 PM, JPLRepo said:

KSP does not use N-Body physics. All planets are on rails. As stated above. Therefore it does not need G in any orbit calculations.

Which is why nobody writes a kOS script to try to push a planet.  We're not talking about using G to calculate planetary movement.  These are scripts that pilot vessels, so of course we're talking about things happening inside the physics bubble, where it is possible to rotate a vessel and apply thrust to a vessel.  The reason for exposing G was that a lot of people were running the standard physics equations about gravity inside their scripts that pilot vessels.  Granted, it's possible to get that information from the SoI body's Mu which has G embedded inside it.  But the fact that you *HAD* to because G doesn't even exist nor is it being enforced to remain constant across the solar system was the part that wasn't intuitive.  Thus I looked for a G because it never occurred to me that the devs wouldn't actually *want* one and would instead prefer to have to hardcode the ratio of mass to mu on every body as hardcoded values.  (I ran a check on each stock body to make sure they kept the ratio of mass to mu consistent across all of them and they do, but it really sounds like you're saying nothing in the data model checks for or enforces this as a guarantee.  Thus someone could design a weird solar system for KSP where in that universe Newton was wrong and G wasn't really a universal constant - it changes depending on what planet you're orbiting.)

Share this post


Link to post
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.