public static double AltitudeAtPosition(Vector3D coords, PlanetEntity planet) { if (planet.Closed) { return(-1000000); } var surfaceCoords = planet.Planet.GetClosestSurfacePointGlobal(coords); var myDistToCore = Vector3D.Distance(coords, planet.GetPosition()); var surfaceDistToCore = Vector3D.Distance(surfaceCoords, planet.GetPosition()); return(myDistToCore - surfaceDistToCore); }