Difference between revisions of "API:CelestialBody"

From Kerbal Space Program Wiki
Jump to: navigation, search
m (N3X15 moved page CelestialBody to API:CelestialBody)
Line 1: Line 1:
A CelestialBody represents a [[Celestials|planet, moon, or star]] that acts as a source of gravity and has some sphere of influence. You can find the CelestialBody whose sphere of influence you are currently in with the vessel.mainBody field.
+
{{class
 
+
|name=CelestialBody
== Useful members ==
+
|summary=A CelestialBody represents a [[Celestials|planet, moon, or star]] that acts as a source of gravity and has some sphere of influence. You can find the CelestialBody whose sphere of influence you are currently in with the vessel.mainBody field.
 
+
}}
Note: this is not a complete listing of the class's members. It includes only the members that someone has figured out how to use and written an explanation for. If you figure out what the other members that aren't listed here do, you should add them to the list!
+
{{PropertiesStart}}
 
+
{{Property
<table border="1">
+
|type=string
<tr>
+
|name=name
<td><code>double GetAltitude(Vector3d worldPos)</code></td>
+
|hasget=1
<td> The altitude above sea level of a given world position, in meters.</td>
+
|desc=The name of the body, as it appears in e.g. the map view.
</tr>
+
}}
<tr>
+
{{Property
<td><code>double GetLatitude(Vector3d worldPos)</code> </td>
+
|type=Vector3d
<td>The latitude of a given world position, in degrees.</td>
+
|name=position
</tr>
+
|hasget=1
<tr>
+
|hasset=1
<td><code>double GetLongitude(Vector3d worldPos)</code> </td>
+
|desc=The position of the center of the body in world space.
<td>The longitude of a given world position, in degrees. The returned value doesn't seem to stay in any particular range. It may be > 360 or < 0. Probably you'll want to do some modulo arithmetic to force this into a certain range like -180 to 180 or 0 to 360.</td>
+
}}
</tr>
+
{{PropertiesEnd}}
<tr>
+
{{MethodsStart}}
<td><code>Vector3d GetRFrmVel(Vector3d worldPos)</code> </td>
+
{{Method
<td>The reference frame of the planet's surface rotates with respect to an inertial reference frame. For example, a ship landed on the planet's surface is actually moving with respect to an inertial frame, because the planet is rotating. This function gives the difference between a velocity in the rotating frame and the same velocity in the inertial frame. You can use it to convert an inertial frame velocity (like the one returned by Orbit.GetVel()) to a rotating frame velocity by (rotating frame velocity) = (inertial frame velocity) - body.GetRFrmVel(position). </td>
+
|returntype=double
</tr>
+
|returndesc=
<tr>
+
|name=GetAltitude
<td><code>Vector3d GetSurfaceNVector(double lat, double lon)</code> </td>
+
|args={{arg|Vector3d|worldPos}}
<td>Returns a unit vector that is normal to the sphere of the planet at the given latitude and longitude.</td>
+
|desc=The altitude above sea level of a given world position, in meters.
</tr>
+
}}
<tr>
+
{{Method
<td><code>Vector3d GetWorldSurfacePosition(double lat, double lon, double alt)</code> </td>
+
|returntype=double
<td>Probably this returns the world position corresponding to a given latitude, longitude, and altitude above sea level?</td>
+
|returndesc=
</tr>
+
|name=GetLatitude
<tr>
+
|args={{arg|Vector3d|worldPos}}
<td><code>string name { get; }</code> </td>
+
|desc=The latitude of a given world position, in degrees.
<td>The name of the body, as it appears in e.g. the map view.</td>
+
}}
</tr>
+
{{Method
<tr>
+
|returntype=double
<td><code>Vector3d position { get; set; } </code> </td>
+
|returndesc=
<td>The position of the center of the body in world space.</td>
+
|name=GetLongitude
</tr>
+
|args={{arg|Vector3d|worldPos}}
 +
|desc=The longitude of a given world position, in degrees. The returned value doesn't seem to stay in any particular range. It may be > 360 or < 0. You'll probably want to do some modulo arithmetic to force this into a certain range like -180 to 180 or 0 to 360.
 +
}}
 +
{{Method
 +
|returntype=Vector3d
 +
|returndesc=
 +
|name=GetRFrmVel
 +
|args={{arg|Vector3d|worldPos}}
 +
|desc=The reference frame of the planet's surface rotates with respect to an inertial reference frame. For example, a ship landed on the planet's surface is actually moving with respect to an inertial frame, because the planet is rotating. This function gives the difference between a velocity in the rotating frame and the same velocity in the inertial frame. You can use it to convert an inertial frame velocity (like the one returned by Orbit.GetVel()) to a rotating frame velocity by (rotating frame velocity) = (inertial frame velocity) - body.GetRFrmVel(position).
 +
}}
 +
{{Method
 +
|returntype=Vector3d
 +
|returndesc=
 +
|name=GetSurfaceNVector
 +
|args={{arg|double|lat}}, {{arg|double|lon}}
 +
|desc=Returns a unit vector that is normal to the sphere of the planet at the given latitude and longitude.
 +
}}
 +
{{Method
 +
|returntype=Vector3d
 +
|returndesc=
 +
|name=GetWorldSurfacePosition
 +
|args={{arg|double|lat}}, {{arg|double|lon}}, {{arg|double|alt}}
 +
|desc=Probably this returns the world position corresponding to a given latitude, longitude, and altitude above sea level?
 +
}}
 +
{{MethodsEnd}}
 +
== Fields ==
 +
<table class="wikitable">
 
<tr>
 
<tr>
 
<td><code>double Mass</code> </td>
 
<td><code>double Mass</code> </td>

Revision as of 19:53, 12 October 2012

CelestialBody Class

A CelestialBody represents a planet, moon, or star that acts as a source of gravity and has some sphere of influence. You can find the CelestialBody whose sphere of influence you are currently in with the vessel.mainBody field.

Properties

The following are public properties available in CelestialBody.

Signature Description
string name { get; } The name of the body, as it appears in e.g. the map view.
Vector3d position { get; set; } The position of the center of the body in world space.

Methods

The following are methods included in CelestialBody.

Signature Description
double GetAltitude(Vector3d worldPos) The altitude above sea level of a given world position, in meters.
double GetLatitude(Vector3d worldPos) The latitude of a given world position, in degrees.
double GetLongitude(Vector3d worldPos) The longitude of a given world position, in degrees. The returned value doesn't seem to stay in any particular range. It may be > 360 or < 0. You'll probably want to do some modulo arithmetic to force this into a certain range like -180 to 180 or 0 to 360.
Vector3d GetRFrmVel(Vector3d worldPos) The reference frame of the planet's surface rotates with respect to an inertial reference frame. For example, a ship landed on the planet's surface is actually moving with respect to an inertial frame, because the planet is rotating. This function gives the difference between a velocity in the rotating frame and the same velocity in the inertial frame. You can use it to convert an inertial frame velocity (like the one returned by Orbit.GetVel()) to a rotating frame velocity by (rotating frame velocity) = (inertial frame velocity) - body.GetRFrmVel(position).
Vector3d GetSurfaceNVector(double lat, double lon) Returns a unit vector that is normal to the sphere of the planet at the given latitude and longitude.
Vector3d GetWorldSurfacePosition(double lat, double lon, double alt) Probably this returns the world position corresponding to a given latitude, longitude, and altitude above sea level?

Fields

double Mass the mass of the body, in KSP's arbitrary mass units. For calculating gravity, KSP seems to use a gravitational constant of G = 6.674E-11 (SI units), which is the same as the real one rounded to 3 decimal places.
double gravParamter This is probably equal to G * Mass?
double maxAtmosphereAltitude The height above sea level at which the atmosphere ends, in meters.
Orbit orbit Contains all information about the body's orbit around whatever other body it is orbiting.
List<CelestialBody> orbitingBodies A list of all the bodies that orbit this one (e.g., the moons of a planet)
PQS pqsController An object that can give you information about the planet's terrain height as a function of position. See the documentation on the PQS class to see how to use it.
double Radius The radius of the planet in meters. This defines sea level.
double rotationPeriod How long it takes the planet to revolve once about its axis, in seconds.
double sphereOfInfluence The radius of the body's sphere of influence, in meters, measured from the center of the planet (not sea level).