.. default-domain:: js .. highlight:: js .. module:: SpaceCenter :no-index: Orbit ===== .. class:: Orbit Describes an orbit. For example, the orbit of a vessel, obtained by calling :meth:`SpaceCenter.Vessel.getOrbit`, or a celestial body, obtained by calling :meth:`SpaceCenter.CelestialBody.getOrbit`. .. function:: 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. :param body: The celestial body being orbited. :type body: :class:`SpaceCenter.CelestialBody` :param position: The position, as a position vector. :type position: ``[number, number, number]`` :param velocity: The velocity, as a vector pointing in the direction of travel, whose magnitude is the speed in :math:`\mathrm{m/s}`. :type velocity: ``[number, number, number]`` :param ut: The universal time, in seconds, at which the object is at *position* traveling at *velocity*. :type ut: ``number`` :param referenceFrame: The reference frame that *position* and *velocity* are in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of *body*. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :rtype: :class:`SpaceCenter.Orbit` .. note:: The orbit is a single conic around *body*. It never changes sphere of influence, so :meth:`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. :meth:`SpaceCenter.Orbit.getRadius`, :meth:`SpaceCenter.Orbit.getSpeed`, :meth:`SpaceCenter.Orbit.position`, :meth:`SpaceCenter.Orbit.velocity` and the like describe the orbit at *ut* and stay there. Use :meth:`SpaceCenter.Orbit.radiusAt`, :meth:`SpaceCenter.Orbit.speedAt`, :meth:`SpaceCenter.Orbit.positionAt`, :meth:`SpaceCenter.Orbit.velocityAt` and :meth:`SpaceCenter.Orbit.trueAnomalyAtUT` for another time, and :meth:`SpaceCenter.Orbit.getReferenceFrame` and :meth:`SpaceCenter.Orbit.getOrbitalReferenceFrame` to follow the orbit as time passes. The orbit is held until :meth:`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. .. function:: 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. :param body: The celestial body being orbited. :type body: :class:`SpaceCenter.CelestialBody` :param semiMajorAxis: The semi-major axis of the orbit, in meters. Positive for an ellipse and negative for a hyperbola. :type semiMajorAxis: ``number`` :param eccentricity: The eccentricity of the orbit. Below one for an ellipse and above one for a hyperbola. :type eccentricity: ``number`` :param inclination: The inclination of the orbit, in radians. :type inclination: ``number`` :param longitudeOfAscendingNode: The longitude of the ascending node, in radians. :type longitudeOfAscendingNode: ``number`` :param argumentOfPeriapsis: The argument of periapsis, in radians. :type argumentOfPeriapsis: ``number`` :param meanAnomalyAtEpoch: The mean anomaly at *epoch*, in radians. :type meanAnomalyAtEpoch: ``number`` :param epoch: The universal time, in seconds, that *meanAnomalyAtEpoch* is measured at. :type epoch: ``number`` :rtype: :class:`SpaceCenter.Orbit` .. note:: The orbit is a single conic around *body*. It never changes sphere of influence, so :meth:`SpaceCenter.Orbit.getNextOrbit` is ``null``, and no atmosphere slows it. The angles are measured against the reference plane and direction that :meth:`SpaceCenter.Orbit.getInclination`, :meth:`SpaceCenter.Orbit.getLongitudeOfAscendingNode` and :meth:`SpaceCenter.Orbit.getArgumentOfPeriapsis` report them against. :meth:`SpaceCenter.Orbit.referencePlaneNormal` and :meth:`SpaceCenter.Orbit.referencePlaneDirection` give these as vectors in a reference frame. :meth:`SpaceCenter.Orbit.getRadius`, :meth:`SpaceCenter.Orbit.getSpeed`, :meth:`SpaceCenter.Orbit.position`, :meth:`SpaceCenter.Orbit.velocity` and the like describe the orbit at *epoch* and stay there. Use :meth:`SpaceCenter.Orbit.radiusAt`, :meth:`SpaceCenter.Orbit.speedAt`, :meth:`SpaceCenter.Orbit.positionAt`, :meth:`SpaceCenter.Orbit.velocityAt` and :meth:`SpaceCenter.Orbit.trueAnomalyAtUT` for another time, and :meth:`SpaceCenter.Orbit.getReferenceFrame` and :meth:`SpaceCenter.Orbit.getOrbitalReferenceFrame` to follow the orbit as time passes. The orbit is held until :meth:`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. .. method:: remove() Remove the orbit, releasing the memory the server holds for it. .. note:: Only an orbit created by :meth:`SpaceCenter.Orbit.createFromPositionAndVelocity` or :meth:`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. .. method:: getBody() The celestial body (e.g. planet or moon) around which the object is orbiting. :Property: Read-only, cannot be set :rtype: :class:`SpaceCenter.CelestialBody` .. method:: getReferenceFrame() The reference frame that moves along the orbit, and is orientated in a fixed direction. * The origin is at the point the orbit has reached at the current time. * The axes do not rotate. They point in the same fixed directions as those of :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :Property: Read-only, cannot be set :rtype: :class:`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. .. method:: 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 :rtype: :class:`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 :meth:`SpaceCenter.Vessel.getOrbitalReferenceFrame` is centered on. .. method:: 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 :rtype: ``number`` .. note:: For the apoapsis altitude reported on the in-game map view, use :meth:`SpaceCenter.Orbit.getApoapsisAltitude`. .. method:: getPeriapsis() The periapsis of the orbit, in meters, from the center of mass of the body being orbited. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: For the periapsis altitude reported on the in-game map view, use :meth:`SpaceCenter.Orbit.getPeriapsisAltitude`. .. method:: getApoapsisAltitude() The apoapsis of the orbit, in meters, above the sea level of the body being orbited. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: This is equal to :meth:`SpaceCenter.Orbit.getApoapsis` minus the equatorial radius of the body. .. method:: getPeriapsisAltitude() The periapsis of the orbit, in meters, above the sea level of the body being orbited. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: This is equal to :meth:`SpaceCenter.Orbit.getPeriapsis` minus the equatorial radius of the body. .. method:: getSemiMajorAxis() The semi-major axis of the orbit, in meters. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getSemiMinorAxis() The semi-minor axis of the orbit, in meters. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getSemiLatusRectum() The semi-latus rectum of the orbit, in meters. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: 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 :rtype: ``number`` .. note:: This value will change over time if the orbit is elliptical. .. method:: getAltitude() The current altitude of the object, in meters above the sea level of the body being orbited. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: This is equal to :meth:`SpaceCenter.Orbit.getRadius` minus the equatorial radius of the body. .. method:: radiusAt(ut) The orbital radius at the given time, in meters. :param ut: The universal time to measure the radius at. :type ut: ``number`` :rtype: ``number`` .. method:: radiusAtTrueAnomaly(trueAnomaly) The orbital radius at the point in the orbit given by the true anomaly. :param trueAnomaly: The true anomaly. :type trueAnomaly: ``number`` :rtype: ``number`` .. method:: position([referenceFrame]) The position the orbit has reached at the current time, in the given reference frame. :param referenceFrame: The reference frame that the returned position vector is in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :returns: The position as a vector. :rtype: ``[number, number, number]`` .. method:: positionAt(ut[, referenceFrame]) The position at a given time, in the specified reference frame. :param ut: The universal time to measure the position at. :type ut: ``number`` :param referenceFrame: The reference frame that the returned position vector is in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :returns: The position as a vector. :rtype: ``[number, number, number]`` .. method:: positionAtTrueAnomaly(trueAnomaly[, referenceFrame]) The position at the point in the orbit given by the true anomaly, in the specified reference frame. :param trueAnomaly: The true anomaly. :type trueAnomaly: ``number`` :param referenceFrame: The reference frame that the returned position vector is in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :returns: The position as a vector. :rtype: ``[number, number, number]`` .. method:: velocity([referenceFrame]) The velocity the orbit has reached at the current time, in the given reference frame. :param referenceFrame: The reference frame that the returned velocity vector is in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :returns: The velocity as a vector. The vector points in the direction of travel, and its magnitude is the speed in :math:`\mathrm{m/s}`. :rtype: ``[number, number, number]`` .. method:: velocityAt(ut[, referenceFrame]) The velocity at a given time, in the specified reference frame. :param ut: The universal time to measure the velocity at. :type ut: ``number`` :param referenceFrame: The reference frame that the returned velocity vector is in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :returns: The velocity as a vector. The vector points in the direction of travel, and its magnitude is the speed in :math:`\mathrm{m/s}`. :rtype: ``[number, number, number]`` .. method:: velocityAtTrueAnomaly(trueAnomaly[, referenceFrame]) The velocity at the point in the orbit given by the true anomaly, in the specified reference frame. :param trueAnomaly: The true anomaly. :type trueAnomaly: ``number`` :param referenceFrame: The reference frame that the returned velocity vector is in. Defaults to :meth:`SpaceCenter.CelestialBody.getNonRotatingReferenceFrame` of :meth:`SpaceCenter.Orbit.getBody`. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` or ``null`` :returns: The velocity as a vector. The vector points in the direction of travel, and its magnitude is the speed in :math:`\mathrm{m/s}`. :rtype: ``[number, number, number]`` .. method:: getSpeed() The current orbital speed of the object in :math:`\mathrm{m/s}`. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: This value will change over time if the orbit is elliptical. .. method:: speedAt(ut) The orbital speed at the given time, in :math:`\mathrm{m/s}`. :param ut: The universal time to measure the speed at. :type ut: ``number`` :rtype: ``number`` .. method:: speedAtRadius(radius) The orbital speed at the given orbital radius, in :math:`\mathrm{m/s}`. :param radius: The orbital radius in meters. :type radius: ``number`` :rtype: ``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. .. method:: speedAtTrueAnomaly(trueAnomaly) The orbital speed at the point in the orbit given by the true anomaly, in :math:`\mathrm{m/s}`. :param trueAnomaly: The true anomaly. :type trueAnomaly: ``number`` :rtype: ``number`` .. method:: getSpecificEnergy() The specific orbital energy, in :math:`\mathrm{J/kg}`. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: This is the sum of the orbit's specific kinetic and potential energy, :math:`v^{2}/2 - \mu/r`, where :math:`v` is the orbital speed, :math:`\mu` the gravitational parameter of the body and :math:`r` the orbital radius. It is negative for a bound (elliptical) orbit. .. method:: getSpecificAngularMomentum() The specific relative angular momentum, in :math:`\mathrm{m^{2}/s}`. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getPeriod() The orbital period, in seconds. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getMeanMotion() The mean motion, in :math:`\mathrm{rad/s}`. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getTimeToApoapsis() The time until the object reaches apoapsis, in seconds. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getTimeToPeriapsis() The time until the object reaches periapsis, in seconds. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getEccentricity() The `eccentricity `_ of the orbit. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getInclination() The `inclination `_ of the orbit, in radians. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getLongitudeOfAscendingNode() The `longitude of the ascending node `_, in radians. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: For a near-equatorial orbit, the ascending node is ill-defined and this value may vary erratically over time. .. method:: getArgumentOfPeriapsis() The `argument of periapsis `_, in radians. :Property: Read-only, cannot be set :rtype: ``number`` .. note:: For a near-circular orbit, the periapsis is ill-defined and this value may vary erratically over time. .. method:: getMeanAnomalyAtEpoch() The `mean anomaly at epoch `_. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getEpoch() The universal time, in seconds, at which the `mean anomaly at epoch `_ is measured. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: getMeanAnomaly() The `mean anomaly `_. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: meanAnomalyAtUT(ut) The mean anomaly at the given time. :param ut: The universal time in seconds. :type ut: ``number`` :rtype: ``number`` .. method:: getEccentricAnomaly() The `eccentric anomaly `_. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: eccentricAnomalyAtUT(ut) The eccentric anomaly at the given universal time. :param ut: The universal time, in seconds. :type ut: ``number`` :rtype: ``number`` .. method:: getTrueAnomaly() The `true anomaly `_. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: trueAnomalyAtUT(ut) The true anomaly at the given time. :param ut: The universal time in seconds. :type ut: ``number`` :rtype: ``number`` .. method:: trueAnomalyAtRadius(radius) The true anomaly at the given orbital radius. :param radius: The orbital radius in meters. :type radius: ``number`` :rtype: ``number`` .. method:: utAtTrueAnomaly(trueAnomaly) The universal time, in seconds, corresponding to the given true anomaly. :param trueAnomaly: True anomaly. :type trueAnomaly: ``number`` :rtype: ``number`` .. method:: trueAnomalyAtAN(target) The true anomaly of the ascending node with the given target orbit. :param target: Target orbit. :type target: :class:`SpaceCenter.Orbit` :rtype: ``number`` .. method:: trueAnomalyAtDN(target) The true anomaly of the descending node with the given target orbit. :param target: Target orbit. :type target: :class:`SpaceCenter.Orbit` :rtype: ``number`` .. method:: getOrbitalSpeed() .. warning:: Deprecated. Use :meth:`SpaceCenter.Orbit.getSpeed` instead. The current orbital speed in :math:`\mathrm{m/s}`. :Property: Read-only, cannot be set :rtype: ``number`` .. method:: orbitalSpeedAt(ut) .. warning:: Deprecated. Use :meth:`SpaceCenter.Orbit.speedAt` instead. The orbital speed at the given time, in :math:`\mathrm{m/s}`. :param ut: The universal time to measure the speed at. :type ut: ``number`` :rtype: ``number`` .. method:: getOrbitalEnergy() .. warning:: Deprecated. Use :meth:`SpaceCenter.Orbit.getSpecificEnergy` instead. The specific orbital energy of the orbit, in :math:`\mathrm{J/kg}`. :Property: Read-only, cannot be set :rtype: ``number`` .. function:: 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. :param referenceFrame: The reference frame that the returned direction is in. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` :returns: The direction as a unit vector. :rtype: ``[number, number, number]`` .. function:: referencePlaneDirection(referenceFrame) The direction from which the orbits longitude of ascending node is measured, in the given reference frame. :param referenceFrame: The reference frame that the returned direction is in. :type referenceFrame: :class:`SpaceCenter.ReferenceFrame` :returns: The direction as a unit vector. :rtype: ``[number, number, number]`` .. method:: relativeInclination(target) Relative inclination of this orbit and the target orbit, in radians. :param target: Target orbit. :type target: :class:`SpaceCenter.Orbit` :rtype: ``number`` .. method:: 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 :rtype: ``number`` .. method:: 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 :rtype: :class:`SpaceCenter.Orbit` or ``null`` .. method:: nextClosestApproach(target) The next closest approach to a target orbit. :param target: Target orbit. :type target: :class:`SpaceCenter.Orbit` :rtype: :class:`SpaceCenter.ClosestApproach` .. method:: closestApproaches(target, orbits) A list of the closest approaches to a target orbit, one for each of the next *orbits* orbital periods. :param target: Target orbit. :type target: :class:`SpaceCenter.Orbit` :param orbits: The number of future orbits to search. :type orbits: ``number`` :rtype: ``Array`` of :class:`SpaceCenter.ClosestApproach`