forked from MuMech/MechJeb2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lamont Granquist <[email protected]>
- Loading branch information
1 parent
824e322
commit 9bc2fb8
Showing
47 changed files
with
16,550 additions
and
16,550 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace MuMech | ||
{ | ||
public static class CelestialBodyExtensions | ||
{ | ||
public static double TerrainAltitude(this CelestialBody body, Vector3d worldPosition) | ||
{ | ||
return body.TerrainAltitude(body.GetLatitude(worldPosition), body.GetLongitude(worldPosition)); | ||
} | ||
|
||
//The KSP drag law is dv/dt = -b * v^2 where b is proportional to the air density and | ||
//the ship's drag coefficient. In this equation b has units of inverse length. So 1/b | ||
//is a characteristic length: a ship that travels this distance through air will lose a significant | ||
//fraction of its initial velocity | ||
public static double DragLength(this CelestialBody body, Vector3d pos, double dragCoeff, double mass) | ||
{ | ||
double airDensity = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(pos, body), FlightGlobals.getExternalTemperature(pos, body)); | ||
|
||
if (airDensity <= 0) return Double.MaxValue; | ||
|
||
//MechJebCore.print("DragLength " + airDensity.ToString("F5") + " " + dragCoeff.ToString("F5")); | ||
|
||
return mass / (0.0005 * PhysicsGlobals.DragMultiplier * airDensity * dragCoeff); | ||
} | ||
|
||
public static double DragLength(this CelestialBody body, double altitudeASL, double dragCoeff, double mass) | ||
{ | ||
return body.DragLength(body.GetWorldSurfacePosition(0, 0, altitudeASL), dragCoeff, mass); | ||
} | ||
|
||
public static double RealMaxAtmosphereAltitude(this CelestialBody body) | ||
{ | ||
return !body.atmosphere ? 0 : body.atmosphereDepth; | ||
} | ||
|
||
|
||
public static double AltitudeForPressure(this CelestialBody body, double pressure) | ||
{ | ||
if (!body.atmosphere) | ||
return 0; | ||
double upperAlt = body.atmosphereDepth; | ||
double lowerAlt = 0; | ||
while (upperAlt - lowerAlt > 10) | ||
{ | ||
double testAlt = (upperAlt + lowerAlt) * 0.5; | ||
double testPressure = FlightGlobals.getStaticPressure(testAlt, body); | ||
if (testPressure < pressure) | ||
{ | ||
upperAlt = testAlt; | ||
} | ||
else | ||
{ | ||
lowerAlt = testAlt; | ||
} | ||
} | ||
return (upperAlt + lowerAlt) * 0.5; | ||
} | ||
|
||
} | ||
} | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace MuMech | ||
{ | ||
public static class CelestialBodyExtensions | ||
{ | ||
public static double TerrainAltitude(this CelestialBody body, Vector3d worldPosition) | ||
{ | ||
return body.TerrainAltitude(body.GetLatitude(worldPosition), body.GetLongitude(worldPosition)); | ||
} | ||
|
||
//The KSP drag law is dv/dt = -b * v^2 where b is proportional to the air density and | ||
//the ship's drag coefficient. In this equation b has units of inverse length. So 1/b | ||
//is a characteristic length: a ship that travels this distance through air will lose a significant | ||
//fraction of its initial velocity | ||
public static double DragLength(this CelestialBody body, Vector3d pos, double dragCoeff, double mass) | ||
{ | ||
double airDensity = FlightGlobals.getAtmDensity(FlightGlobals.getStaticPressure(pos, body), FlightGlobals.getExternalTemperature(pos, body)); | ||
|
||
if (airDensity <= 0) return Double.MaxValue; | ||
|
||
//MechJebCore.print("DragLength " + airDensity.ToString("F5") + " " + dragCoeff.ToString("F5")); | ||
|
||
return mass / (0.0005 * PhysicsGlobals.DragMultiplier * airDensity * dragCoeff); | ||
} | ||
|
||
public static double DragLength(this CelestialBody body, double altitudeASL, double dragCoeff, double mass) | ||
{ | ||
return body.DragLength(body.GetWorldSurfacePosition(0, 0, altitudeASL), dragCoeff, mass); | ||
} | ||
|
||
public static double RealMaxAtmosphereAltitude(this CelestialBody body) | ||
{ | ||
return !body.atmosphere ? 0 : body.atmosphereDepth; | ||
} | ||
|
||
|
||
public static double AltitudeForPressure(this CelestialBody body, double pressure) | ||
{ | ||
if (!body.atmosphere) | ||
return 0; | ||
double upperAlt = body.atmosphereDepth; | ||
double lowerAlt = 0; | ||
while (upperAlt - lowerAlt > 10) | ||
{ | ||
double testAlt = (upperAlt + lowerAlt) * 0.5; | ||
double testPressure = FlightGlobals.getStaticPressure(testAlt, body); | ||
if (testPressure < pressure) | ||
{ | ||
upperAlt = testAlt; | ||
} | ||
else | ||
{ | ||
lowerAlt = testAlt; | ||
} | ||
} | ||
return (upperAlt + lowerAlt) * 0.5; | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.