#region Assembly Assembly-CSharp.dll, v2.0.50727 // C:\greg\games\KSP 0.18.2\KSP_Data\Managed\Assembly-CSharp.dll #endregion using System; using UnityEngine; /// /// An Orbit class represents a Keplerian orbit. Each Vessel and each CelestialBody has an Orbit. CelestialBodies and /// on-rails Vessels follow their Orbits exactly. Off-rails vessels (the active vessel and any nearby vessels) /// do not follow their orbits exactly; instead their motion is computed frame-by-frame from the forces acting on them. /// A patched consics trajectory consists of a series of Orbits, called patches. /// [Serializable] public class Orbit { /// /// Whether this patch actually represents a real orbit patch in the projected flight path. Often /// Orbit.nextPatch for the last real will not be null, but will be some sort of bogus Orbit object. /// You can recognize these because activePatch will be false. /// public bool activePatch; public double altitude; public Vector3d an; /// /// The angle between the ascending node and the periapsis, in degrees. /// public double argumentOfPeriapsis; public double ClAppr; public double ClEctr1; public double ClEctr2; public CelestialBody closestEncounterBody; public Orbit.EncounterSolutionLevel closestEncounterLevel; public Orbit closestEncounterPatch; public double closestTgtApprUT; public double CrAppr; public bool debug_returnFullEllipseTrajectory; public Vector3 debugAN; public Vector3 debugEccVec; public Vector3 debugH; public Vector3 debugPos; public Vector3 debugVel; public double E; /// /// A quantity used in the math describing Keplerian orbits; Google it. /// public double eccentricAnomaly; /// /// The eccentricity of the orbit. /// public double eccentricity; /// /// A vector that points toward periapsis, with mangitude equal to the eccentricity. /// NOTE: All Vector3d's returned by Orbit class functions have their y and z axes flipped. You have /// to flip these back to get the vectors in world coordinates. /// public Vector3d eccVec; /// /// The universal time at which this patch ends. /// public double EndUT; /// /// A special UT at which the parameters of the Orbit are defined. See meanAnomalyAtEpoch. /// public double epoch; public double FEVp; public double FEVs; public double fromE; public double fromV; /// /// The specific orbital angular momentum, maybe? /// public Vector3d h; /// /// The inclination of this orbit with respect to the equator of the central body (in radians or degrees?) /// public double inclination; /// /// The longitude of the ascending node of the orbit, in degrees. The LAN /// is the angle between the ascending node and Planetarium.right, as viewed along /// Planetarium.up. /// public double LAN; public double mag; /// /// Mean anomaly is the fraction of the orbit that has been completed, measured starting /// from the periapsis, multiplied by 2π. Look it up. /// public double meanAnomaly; /// /// The mean anomaly of the orbit at the special UT given by Orbit.epoch. /// public double meanAnomalyAtEpoch; public double nearestTT; public Orbit nextPatch; public double nextTT; [Obsolete("Use VesselType or CelestialBodyType instead")] public Orbit.ObjectType objectType; /// /// Time since periapsis, in seconds. /// public double ObT; /// /// The value of ObT at the universal time given by epoch. /// public double ObTAtEpoch; public double orbitalEnergy; public double orbitalSpeed; /// /// Equal to >ObT / period? /// public double orbitPercent; /// /// How the next patch follows onto this one, or FINAL if there is no patch after this one. /// public Orbit.PatchTransitionType patchEndTransition; public Orbit.PatchTransitionType patchStartTransition; /// /// The period of the orbit, in seconds. /// public double period; public Vector3d pos; public Orbit previousPatch; public double radius; /// /// The body orbited. /// public CelestialBody referenceBody; public double sampleInterval; public Vector3d secondaryPosAtTransition1; public Vector3d secondaryPosAtTransition2; /// /// The semi-major axis of the orbit, in meters. Equal to (PeR + ApR)/2 /// public double semiMajorAxis; public double SEVp; public double SEVs; public double StartUT; /// /// The time until the object will reach apoapsis, in seconds. /// public double timeToAp; /// /// The time unti lthe object will reach periapsis, in seconds. /// public double timeToPe; public double timeToTransition1; public double timeToTransition2; public double toE; public double toV; public double trueAnomaly; public double UTappr; public double UTsoi; public double V; public Vector3d vel; public extern Orbit(); public extern Orbit(double inc, double e, double sma, double lan, double w, double mEp, double t, CelestialBody body); /// /// The apoapsis of the orbit in meters, measured from sea level. /// public extern double ApA { get; } /// /// The apoapsis of the orbit in meters, measured from the center of the main body. /// public extern double ApR { get; } /// /// The periapsis of the orbit in meters, measured from sea level. /// public extern double PeA { get; } /// /// The periapsis of the orbit in meters, measured from the center of the main body. /// public extern double PeR { get; } /// /// A property of ellipses, parabolas and hyperbolas; Google it. /// public extern double semiLatusRectum { get; } /// /// A property of ellipses; Google it. /// public extern double semiMinorAxis { get; } public extern void DrawOrbit(); public extern static void FindClosestPoints(Orbit p, Orbit s, ref double CD, ref double CCD, ref double FFp, ref double FFs, ref double SFp, ref double SFs, double epsilon, int maxIterations, ref int iterationCount); public extern Vector3d GetANVector(); public extern double GetDTforTrueAnomaly(double tA, double wrapAfterSeconds); public extern double GetEccentricAnomaly(double tA); public extern Vector3d GetEccVector(); public extern Vector3d GetFrameVel(); public extern Vector3d GetFrameVelAtUT(double UT); public extern double GetMeanAnomaly(double E, double tA); public extern double getObTAtMeanAnomaly(double M); public extern double getObtAtUT(double UT); public extern double getOrbitalSpeedAt(double time); public extern double getOrbitalSpeedAtDistance(double d); public extern double getOrbitalSpeedAtPos(Vector3d pos); public extern double getOrbitalSpeedAtRelativePos(Vector3d relPos); public extern Vector3d getOrbitalVelocityAtObT(double ObT); public extern Vector3d getOrbitalVelocityAtUT(double UT); /// /// A unit vector normal to the plane of the orbit. NOTE: All Vector3d's returned by Orbit class functions have their y and z axes flipped. You have /// to flip these back to get the vectors in world coordinates. /// /// A unit normal vector. public extern Vector3d GetOrbitNormal(); public extern Trajectory GetPatchTrajectory(int sampleCount); public extern Vector3d getPositionAtT(double T); public extern Vector3d getPositionAtUT(double UT); public extern Vector3d getPositionFromEccAnomaly(double E); public extern Vector3d getPositionFromMeanAnomaly(double M); public extern Vector3d getPositionFromTrueAnomaly(double tA); public extern Vector3d getRelativePositionAtT(double T); /// /// Gets the predicted displacement of the orbiting object from the center of the main /// body at a given universal time. NOTE: All Vector3d's returned by Orbit class functions have their y and z axes flipped. You have /// to flip these back to get the vectors in world coordinates. /// /// A univeral time. /// Position relative to the main body (YZ flipped) public extern Vector3d getRelativePositionAtUT(double UT); public extern Vector3d getRelativePositionFromEccAnomaly(double E); public extern Vector3d getRelativePositionFromMeanAnomaly(double M); public extern Vector3d getRelativePositionFromTrueAnomaly(double tA); public extern Vector3d GetRelativeVel(); public extern Vector3d GetRotFrameVel(CelestialBody refBody); public extern double getTrueAnomaly(double E); public extern double GetTrueAnomalyOfZupVector(Vector3d vector); public extern Vector3d getTruePositionAtUT(double UT); public extern double GetUTforTrueAnomaly(double tA, double wrapAfterSeconds); /// /// The current orbital velocity of the orbiting body. Unlike most other methods of the orbit /// class, the returned vector seems to already be in world coordinates and doesn't need to have /// its Y and Z axes flipped. /// /// Orbital velocity vector at current time. public extern Vector3d GetVel(); public extern Vector3d GetWorldSpaceVel(); public extern void Init(); public extern static bool PeApIntersects(Orbit primary, Orbit secondary, double threshold); /// /// The distance the orbiting object will be from the center of the main body when it reaches the given true anomaly. /// /// True anomaly (in degrees or radians?) /// Distance from the main body's center, in meters public extern double RadiusAtTrueAnomaly(double tA); public extern static double SolveClosestApproach(Orbit p, Orbit s, ref double UT, double dT, double threshold, double MinUT, double MaxUT, double epsilon, int maxIterations, ref int iterationCount); public extern double solveEccentricAnomaly(double M, double ecc, double maxError, int maxIterations); public extern static bool SolveSOI_BSP(Orbit p, Orbit s, ref double UT, double dT, double Rsoi, double MinUT, double MaxUT, double epsilon, int maxIterations, ref int iterationCount); /// /// The true anomaly at which the orbiting object will achieve the given distance from the center of the main body. /// /// Distance from the center of the main body, in meters. /// True anomaly, in radians. public extern double TrueAnomalyAtRadius(double R); public extern double TrueAnomalyAtT(double T); public extern double TrueAnomalyAtUT(double UT); public extern void UpdateFromOrbitAtUT(Orbit orbit, double UT, CelestialBody toBody); /// /// Updates this orbit to reflect the orbit that will be taken around the given body by an object with the /// given position and velocity at the given universal time. /// /// The initial position of the object RELATIVE TO refBody at UT (YZ flipped) /// The initial velocity of the object (YZ flipped) /// The main body /// The universal time at which to start the orbit. public extern void UpdateFromStateVectors(Vector3d pos, Vector3d vel, CelestialBody refBody, double UT); public extern void UpdateFromUT(double UT); public enum EncounterSolutionLevel { NONE = 0, ESCAPE = 1, ORBIT_INTERSECT = 2, SOI_INTERSECT_2 = 3, SOI_INTERSECT_1 = 4, } public enum ObjectType { VESSEL = 0, SPACE_DEBRIS = 1, CELESTIAL_BODIES = 2, UNKNOWN_MISC = 3, KERBAL = 4, } public enum PatchTransitionType { INITIAL = 0, FINAL = 1, ENCOUNTER = 2, ESCAPE = 3, MANEUVER = 4, } }