Frequently Asked Question
Contents
Frequently Asked Question¶
How do I get the position and/or velocity of a ship/body?¶
The current state of a body in a GECore
is retreived by GECore.StateById()
with signature:
ge.StateById(bodyId, ref shipState);
Here shipState
is an instance of a struct that holds the position, velocity and current time (all in world units).
bodyId
is the id assigned to the body when added to the GECore
. If the body is a GSBody
added by a GSController
this can be retrived using
GSBody.Id()
.
If only the position is required use:
public double3 RWorldById(int id)
public struct GEBodyState {
public double3 r;
public double3 v;
public double t;
...
}
Note that StateById
has some additional arguments to allow retreival of internal GE units and to manage co-rotating frames, but
these are not commonly used.
The state retrieved by StateById
is a global state. If a ship is orbiting a moon that is moving this velocity will be included in the
state that is returned. It is often useful to get a state of a body relative to the body it is orbiting. In this case the API to use is:
public bool RelativeState(int bodyId, int centerId, ref GEBodyState bodyState, bool geUnits = false)
in which the state relative the body indicated by centerId
is returned.
How do I change the position and/or velocity of a ship body.¶
The state of a body can be set by creating a GEBodyState
(see above) and then using GECore.StateSetById.
How do I get the orbital elements of a body?¶
The classical orbital elements of a body with respect to a the body it is orbiting can be retreived by GECore.COE()
/// <summary>
/// Get the classical orbital elements (COE) for the indicated body with respect to the center body.
///
/// The most common way to do this is to take the R, V state of the body and use an algorithm (RVtoCOE)
/// to determine the COE elements. This algorithm imposes a choice of when an orbit is to be considered
/// flat or circular.
///
/// A flat orbit (i=0) has it's OmegaU/RAAN set to 0.
/// A circular orbit has it's argp set to zero (this is the reference point for the phase, nu).
///
/// Of course the zero detect is not exactly zero, so there will be some threshold (usually E-6) where e.g.
/// an orbit can transition from flat to non-flat. When this happens the argp and phase may have a discontinuity
/// (athough their sum will remain constant).
///
/// </summary>
/// <param name="bodyId"></param>
/// <param name="centerId"></param>
/// <param name="usePropCOE">If propagator has internal COE, use that instead of recomputing from R, V</param>
/// <returns></returns>
public Orbital.COE COE(int bodyId, int centerId, bool usePropCOE = true)
This returns a class Orbital.COE
. See [Orbits]{orbits}.