Orbit#

class SpaceCenter.Orbit()#

Describes an orbit. For example, the orbit of a vessel, obtained by calling SpaceCenter.Vessel.getOrbit(), or a celestial body, obtained by calling SpaceCenter.CelestialBody.getOrbit().

Orbit.createFromPositionAndVelocity(body, position, velocity, ut[, referenceFrame])#

Create the orbit that passes through a given position at a given velocity. The orbit coasts freely under the gravity of the body being orbited, so it describes where an object left to fall from that position and velocity would be at any later time.

Arguments:
  • body (SpaceCenter.CelestialBody) – The celestial body being orbited.

  • position ([number, number, number]) – The position, as a position vector.

  • velocity ([number, number, number]) – The velocity, as a vector pointing in the direction of travel, whose magnitude is the speed in \(\mathrm{m/s}\).

  • ut (number) – The universal time, in seconds, at which the object is at position traveling at velocity.

  • referenceFrame (SpaceCenter.ReferenceFrame or null) – The reference frame that position and velocity are in. Defaults to SpaceCenter.CelestialBody.getNonRotatingReferenceFrame() of body.

Return type:

SpaceCenter.Orbit

Note

The orbit is a single conic around body. It never changes sphere of influence, so SpaceCenter.Orbit.getNextOrbit() is null, and no atmosphere slows it. A vessel held on rails follows its own orbit exactly, while one inside the physics bubble is simulated and drifts from it a little.

SpaceCenter.Orbit.getRadius(), SpaceCenter.Orbit.getSpeed(), SpaceCenter.Orbit.position(), SpaceCenter.Orbit.velocity() and the like describe the orbit at ut and stay there. Use SpaceCenter.Orbit.radiusAt(), SpaceCenter.Orbit.speedAt(), SpaceCenter.Orbit.positionAt(), SpaceCenter.Orbit.velocityAt() and SpaceCenter.Orbit.trueAnomalyAtUT() for another time, and SpaceCenter.Orbit.getReferenceFrame() and SpaceCenter.Orbit.getOrbitalReferenceFrame() to follow the orbit as time passes.

The orbit is held until SpaceCenter.Orbit.remove() is called on it or the client that created it disconnects. Remove each one created by a script that creates them repeatedly, for example once per update.

Orbit.createFromOrbitalElements(body, semiMajorAxis, eccentricity, inclination, longitudeOfAscendingNode, argumentOfPeriapsis, meanAnomalyAtEpoch, epoch)#

Create the orbit with the given orbital elements around a given body. The orbit coasts freely under the gravity of that body, so it describes where an object on it would be at any time.

Arguments:
  • body (SpaceCenter.CelestialBody) – The celestial body being orbited.

  • semiMajorAxis (number) – The semi-major axis of the orbit, in meters. Positive for an ellipse and negative for a hyperbola.

  • eccentricity (number) – The eccentricity of the orbit. Below one for an ellipse and above one for a hyperbola.

  • inclination (number) – The inclination of the orbit, in radians.

  • longitudeOfAscendingNode (number) – The longitude of the ascending node, in radians.

  • argumentOfPeriapsis (number) – The argument of periapsis, in radians.

  • meanAnomalyAtEpoch (number) – The mean anomaly at epoch, in radians.

  • epoch (number) – The universal time, in seconds, that meanAnomalyAtEpoch is measured at.

Return type:

SpaceCenter.Orbit

Note

The orbit is a single conic around body. It never changes sphere of influence, so SpaceCenter.Orbit.getNextOrbit() is null, and no atmosphere slows it.

The angles are measured against the reference plane and direction that SpaceCenter.Orbit.getInclination(), SpaceCenter.Orbit.getLongitudeOfAscendingNode() and SpaceCenter.Orbit.getArgumentOfPeriapsis() report them against. SpaceCenter.Orbit.referencePlaneNormal() and SpaceCenter.Orbit.referencePlaneDirection() give these as vectors in a reference frame.

SpaceCenter.Orbit.getRadius(), SpaceCenter.Orbit.getSpeed(), SpaceCenter.Orbit.position(), SpaceCenter.Orbit.velocity() and the like describe the orbit at epoch and stay there. Use SpaceCenter.Orbit.radiusAt(), SpaceCenter.Orbit.speedAt(), SpaceCenter.Orbit.positionAt(), SpaceCenter.Orbit.velocityAt() and SpaceCenter.Orbit.trueAnomalyAtUT() for another time, and SpaceCenter.Orbit.getReferenceFrame() and SpaceCenter.Orbit.getOrbitalReferenceFrame() to follow the orbit as time passes.

The orbit is held until SpaceCenter.Orbit.remove() is called on it or the client that created it disconnects. Remove each one created by a script that creates them repeatedly, for example once per update.

Orbit.remove()#

Remove the orbit, releasing the memory the server holds for it.

Note

Only an orbit created by SpaceCenter.Orbit.createFromPositionAndVelocity() or SpaceCenter.Orbit.createFromOrbitalElements() can be removed. Every other orbit belongs to something in the game, and the server holds one of each.

Any further use of this object throws an exception, as does use of a reference frame defined against it. An orbit belongs to the client that created it, and is removed when that client disconnects.

Orbit.getBody()#

The celestial body (e.g. planet or moon) around which the object is orbiting.

Property:

Read-only, cannot be set

Return type:

SpaceCenter.CelestialBody

Orbit.getReferenceFrame()#

The reference frame that moves along the orbit, and is orientated in a fixed direction.

Property:

Read-only, cannot be set

Return type:

SpaceCenter.ReferenceFrame

Note

For the orbit of a vessel, the origin is the point the vessel’s orbit has reached rather than the vessel’s own center of mass. The two are a few meters apart, as a vessel inside the physics bubble is simulated rather than being held on its orbit.

Orbit.getOrbitalReferenceFrame()#

The reference frame that moves along the orbit, and is orientated with its prograde/normal/radial directions.

  • The origin is at the point the orbit has reached at the current time.

  • The axes rotate with the orbital prograde/normal/radial directions.

  • The x-axis points in the orbital anti-radial direction.

  • The y-axis points in the orbital prograde direction.

  • The z-axis points in the orbital normal direction.

Property:

Read-only, cannot be set

Return type:

SpaceCenter.ReferenceFrame

Note

For the orbit of a vessel, the origin is the point the vessel’s orbit has reached rather than the vessel’s own center of mass, which is what SpaceCenter.Vessel.getOrbitalReferenceFrame() is centered on.

Orbit.getApoapsis()#

Gets the apoapsis of the orbit, in meters, from the center of mass of the body being orbited.

Property:

Read-only, cannot be set

Return type:

number

Note

For the apoapsis altitude reported on the in-game map view, use SpaceCenter.Orbit.getApoapsisAltitude().

Orbit.getPeriapsis()#

The periapsis of the orbit, in meters, from the center of mass of the body being orbited.

Property:

Read-only, cannot be set

Return type:

number

Note

For the periapsis altitude reported on the in-game map view, use SpaceCenter.Orbit.getPeriapsisAltitude().

Orbit.getApoapsisAltitude()#

The apoapsis of the orbit, in meters, above the sea level of the body being orbited.

Property:

Read-only, cannot be set

Return type:

number

Note

This is equal to SpaceCenter.Orbit.getApoapsis() minus the equatorial radius of the body.

Orbit.getPeriapsisAltitude()#

The periapsis of the orbit, in meters, above the sea level of the body being orbited.

Property:

Read-only, cannot be set

Return type:

number

Note

This is equal to SpaceCenter.Orbit.getPeriapsis() minus the equatorial radius of the body.

Orbit.getSemiMajorAxis()#

The semi-major axis of the orbit, in meters.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getSemiMinorAxis()#

The semi-minor axis of the orbit, in meters.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getSemiLatusRectum()#

The semi-latus rectum of the orbit, in meters.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getRadius()#

The current radius of the orbit, in meters. This is the distance between the center of mass of the object in orbit, and the center of mass of the body around which it is orbiting.

Property:

Read-only, cannot be set

Return type:

number

Note

This value will change over time if the orbit is elliptical.

Orbit.getAltitude()#

The current altitude of the object, in meters above the sea level of the body being orbited.

Property:

Read-only, cannot be set

Return type:

number

Note

This is equal to SpaceCenter.Orbit.getRadius() minus the equatorial radius of the body.

Orbit.radiusAt(ut)#

The orbital radius at the given time, in meters.

Arguments:
  • ut (number) – The universal time to measure the radius at.

Return type:

number

Orbit.radiusAtTrueAnomaly(trueAnomaly)#

The orbital radius at the point in the orbit given by the true anomaly.

Arguments:
  • trueAnomaly (number) – The true anomaly.

Return type:

number

Orbit.position([referenceFrame])#

The position the orbit has reached at the current time, in the given reference frame.

Arguments:
Returns:

The position as a vector.

Return type:

[number, number, number]

Orbit.positionAt(ut[, referenceFrame])#

The position at a given time, in the specified reference frame.

Arguments:
Returns:

The position as a vector.

Return type:

[number, number, number]

Orbit.positionAtTrueAnomaly(trueAnomaly[, referenceFrame])#

The position at the point in the orbit given by the true anomaly, in the specified reference frame.

Arguments:
Returns:

The position as a vector.

Return type:

[number, number, number]

Orbit.velocity([referenceFrame])#

The velocity the orbit has reached at the current time, in the given reference frame.

Arguments:
Returns:

The velocity as a vector. The vector points in the direction of travel, and its magnitude is the speed in \(\mathrm{m/s}\).

Return type:

[number, number, number]

Orbit.velocityAt(ut[, referenceFrame])#

The velocity at a given time, in the specified reference frame.

Arguments:
Returns:

The velocity as a vector. The vector points in the direction of travel, and its magnitude is the speed in \(\mathrm{m/s}\).

Return type:

[number, number, number]

Orbit.velocityAtTrueAnomaly(trueAnomaly[, referenceFrame])#

The velocity at the point in the orbit given by the true anomaly, in the specified reference frame.

Arguments:
Returns:

The velocity as a vector. The vector points in the direction of travel, and its magnitude is the speed in \(\mathrm{m/s}\).

Return type:

[number, number, number]

Orbit.getSpeed()#

The current orbital speed of the object in \(\mathrm{m/s}\).

Property:

Read-only, cannot be set

Return type:

number

Note

This value will change over time if the orbit is elliptical.

Orbit.speedAt(ut)#

The orbital speed at the given time, in \(\mathrm{m/s}\).

Arguments:
  • ut (number) – The universal time to measure the speed at.

Return type:

number

Orbit.speedAtRadius(radius)#

The orbital speed at the given orbital radius, in \(\mathrm{m/s}\).

Arguments:
  • radius (number) – The orbital radius in meters.

Return type:

number

Note

This is the vis-viva speed. A radius the orbit never reaches is accepted. On an ellipse the speed is NaN above twice the semi-major axis.

Orbit.speedAtTrueAnomaly(trueAnomaly)#

The orbital speed at the point in the orbit given by the true anomaly, in \(\mathrm{m/s}\).

Arguments:
  • trueAnomaly (number) – The true anomaly.

Return type:

number

Orbit.getSpecificEnergy()#

The specific orbital energy, in \(\mathrm{J/kg}\).

Property:

Read-only, cannot be set

Return type:

number

Note

This is the sum of the orbit’s specific kinetic and potential energy, \(v^{2}/2 - \mu/r\), where \(v\) is the orbital speed, \(\mu\) the gravitational parameter of the body and \(r\) the orbital radius. It is negative for a bound (elliptical) orbit.

Orbit.getSpecificAngularMomentum()#

The specific relative angular momentum, in \(\mathrm{m^{2}/s}\).

Property:

Read-only, cannot be set

Return type:

number

Orbit.getPeriod()#

The orbital period, in seconds.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getMeanMotion()#

The mean motion, in \(\mathrm{rad/s}\).

Property:

Read-only, cannot be set

Return type:

number

Orbit.getTimeToApoapsis()#

The time until the object reaches apoapsis, in seconds.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getTimeToPeriapsis()#

The time until the object reaches periapsis, in seconds.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getEccentricity()#

The eccentricity of the orbit.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getInclination()#

The inclination of the orbit, in radians.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getLongitudeOfAscendingNode()#

The longitude of the ascending node, in radians.

Property:

Read-only, cannot be set

Return type:

number

Note

For a near-equatorial orbit, the ascending node is ill-defined and this value may vary erratically over time.

Orbit.getArgumentOfPeriapsis()#

The argument of periapsis, in radians.

Property:

Read-only, cannot be set

Return type:

number

Note

For a near-circular orbit, the periapsis is ill-defined and this value may vary erratically over time.

Orbit.getMeanAnomalyAtEpoch()#

The mean anomaly at epoch.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getEpoch()#

The universal time, in seconds, at which the mean anomaly at epoch is measured.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getMeanAnomaly()#

The mean anomaly.

Property:

Read-only, cannot be set

Return type:

number

Orbit.meanAnomalyAtUT(ut)#

The mean anomaly at the given time.

Arguments:
  • ut (number) – The universal time in seconds.

Return type:

number

Orbit.getEccentricAnomaly()#

The eccentric anomaly.

Property:

Read-only, cannot be set

Return type:

number

Orbit.eccentricAnomalyAtUT(ut)#

The eccentric anomaly at the given universal time.

Arguments:
  • ut (number) – The universal time, in seconds.

Return type:

number

Orbit.getTrueAnomaly()#

The true anomaly.

Property:

Read-only, cannot be set

Return type:

number

Orbit.trueAnomalyAtUT(ut)#

The true anomaly at the given time.

Arguments:
  • ut (number) – The universal time in seconds.

Return type:

number

Orbit.trueAnomalyAtRadius(radius)#

The true anomaly at the given orbital radius.

Arguments:
  • radius (number) – The orbital radius in meters.

Return type:

number

Orbit.utAtTrueAnomaly(trueAnomaly)#

The universal time, in seconds, corresponding to the given true anomaly.

Arguments:
  • trueAnomaly (number) – True anomaly.

Return type:

number

Orbit.trueAnomalyAtAN(target)#

The true anomaly of the ascending node with the given target orbit.

Arguments:
Return type:

number

Orbit.trueAnomalyAtDN(target)#

The true anomaly of the descending node with the given target orbit.

Arguments:
Return type:

number

Orbit.getOrbitalSpeed()#

Warning

Deprecated. Use SpaceCenter.Orbit.getSpeed() instead.

The current orbital speed in \(\mathrm{m/s}\).

Property:

Read-only, cannot be set

Return type:

number

Orbit.orbitalSpeedAt(ut)#

Warning

Deprecated. Use SpaceCenter.Orbit.speedAt() instead.

The orbital speed at the given time, in \(\mathrm{m/s}\).

Arguments:
  • ut (number) – The universal time to measure the speed at.

Return type:

number

Orbit.getOrbitalEnergy()#

Warning

Deprecated. Use SpaceCenter.Orbit.getSpecificEnergy() instead.

The specific orbital energy of the orbit, in \(\mathrm{J/kg}\).

Property:

Read-only, cannot be set

Return type:

number

Orbit.referencePlaneNormal(referenceFrame)#

The direction that is normal to the orbits reference plane, in the given reference frame. The reference plane is the plane from which the orbits inclination is measured.

Arguments:
Returns:

The direction as a unit vector.

Return type:

[number, number, number]

Orbit.referencePlaneDirection(referenceFrame)#

The direction from which the orbits longitude of ascending node is measured, in the given reference frame.

Arguments:
Returns:

The direction as a unit vector.

Return type:

[number, number, number]

Orbit.relativeInclination(target)#

Relative inclination of this orbit and the target orbit, in radians.

Arguments:
Return type:

number

Orbit.getTimeToSOIChange()#

The time until the object changes sphere of influence, in seconds. Returns NaN if the object is not going to change sphere of influence.

Property:

Read-only, cannot be set

Return type:

number

Orbit.getNextOrbit()#

If the object is going to change sphere of influence in the future, returns the new orbit after the change. Otherwise returns null.

Property:

Read-only, cannot be set

Return type:

SpaceCenter.Orbit or null

Orbit.nextClosestApproach(target)#

The next closest approach to a target orbit.

Arguments:
Return type:

SpaceCenter.ClosestApproach

Orbit.closestApproaches(target, orbits)#

A list of the closest approaches to a target orbit, one for each of the next orbits orbital periods.

Arguments:
  • target (SpaceCenter.Orbit) – Target orbit.

  • orbits (number) – The number of future orbits to search.

Return type:

Array of SpaceCenter.ClosestApproach