Jump to content

KSP Altitude Calculation Inquiry


Luuko

Recommended Posts

Out of morbid curiosity, we know the altimeter provided in stock KSP is Mean Sea Level MSL, not above terrain. To get Above Ground Level (AGL), how would we go about doing this? Do we calculate AGL akin to how we convert between earth's MSL and AGL via comparing them against the WGS84 model (A rough geoid measurement of earth's surface) or are should we measure from the center of mass of the vehicle and straight to the center of the sphereoid and note just where it stops and how far/long the distance is? Thoughts?

Link to comment
Share on other sites

Raycasting is slow and not very accurate. You can get the terrain altitude directly below your ship with Vessel.pqsAltitude. Something like this would get it right and be much faster.

public double TrueAlt()
{
Vector3 pos= this.part.transform.position; //or this.vessel.GetWorldPos3D()
double ASL = FlightGlobals.getAltitudeAtPos(pos);
if (this.vessel.mainBody.pqsController == null) { return ASL; }
double terrainAlt = this.vessel.pqsAltitude;
if (this.vessel.mainBody.ocean && terrainAltitude <= 0) { return ASL; } //Checks for oceans
return ASL - terrainAlt;
}

Link to comment
Share on other sites

Hrm. Well that gives me a few points to consider at least.

To clarify, work has me doing some geopositioning big data stuff and I saw a possibility to try to understand how one might handle such in KSP. Thank you for your time and consideration.

Edited by Luuko
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...