public Orbit(Double3 posIn, Double3 velIn, double timeIn, CelestialBodyData planet, CelestialBodyData lastPlanet) { this.planet = planet; this.timeIn = timeIn; double mass = planet.mass; Double3 b = Double3.Cross2d(posIn, velIn); Double3 @double = Double3.Cross(velIn, b) / mass - posIn.normalized2d; this.eccentricity = @double.magnitude2d; this.argumentOfPeriapsis = Math.Atan2(@double.y, @double.x); this.semiMajorAxis = -mass / (2.0 * (Math.Pow(velIn.magnitude2d, 2.0) / 2.0 - mass / posIn.magnitude2d)); this.periapsis = this.semiMajorAxis * (1.0 - this.eccentricity); this.apoapsis = ((this.eccentricity >= 1.0) ? double.PositiveInfinity : (this.semiMajorAxis * (1.0 + this.eccentricity))); this.semiLatusRectum = Kepler.GetSemiLatusRectum(this.periapsis, this.eccentricity); this._period = Kepler.GetPeriod(this.eccentricity, this.semiMajorAxis, mass); this.meanMotion = Kepler.GetMeanMotion(this._period, this.eccentricity, mass, this.semiMajorAxis) * (double)Math.Sign(b.z); double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(posIn.magnitude2d, this.semiLatusRectum, this.eccentricity); double num = Kepler.GetMeanAnomaly(this.eccentricity, trueAnomalyAtRadius, posIn, this.argumentOfPeriapsis) / this.meanMotion; if (this.apoapsis > planet.orbitData.SOI || this.eccentricity >= 1.0) { this._period = 0.0; } this.periapsisPassageTime = timeIn + num - this._period * 10.0; this.GetOrbitType(timeIn, lastPlanet); this.stopTimeWarpTime = this.GetStopTimeWarpTime(); }
public double GetStopTimeWarpTime() { double num = this.planet.radius + this.planet.minTimewarpHeightKm * 1000.0; if (this.periapsis + 10.0 < num) { double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(num, this.semiLatusRectum, this.eccentricity); double num2 = this.GetNextTrueAnomalyPassageTime(this.timeIn, trueAnomalyAtRadius); double num3 = this.GetNextTrueAnomalyPassageTime(this.timeIn, -trueAnomalyAtRadius); if (num2 < this.timeIn) { num2 += this._period; } if (num3 < this.timeIn) { num3 += this._period; } if (num2 < this.timeIn) { num2 = double.PositiveInfinity; } if (num3 < this.timeIn) { num3 = double.PositiveInfinity; } return(Math.Min(num2, num3)); } return(double.PositiveInfinity); }
public double GetPassAnomaly(double height) { double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(height, this.semiLatusRectum, this.eccentricity); double meanAnomaly = Kepler.GetMeanAnomaly(this.eccentricity, trueAnomalyAtRadius); return(Math.Abs(meanAnomaly / this.meanMotion)); }
public void GetOrbitType(double timeIn, CelestialBodyData lastPlanet) { this.orbitType = Orbit.Type.Eternal; this.orbitEndTime = double.PositiveInfinity; this.calculatePassesTime = double.PositiveInfinity; if (this.apoapsis > this.planet.orbitData.SOI || this.eccentricity > 1.0) { this.orbitEndTime = this.periapsisPassageTime + this.GetPassAnomaly(this.planet.orbitData.SOI); if (!double.IsNaN(this.meanMotion)) { this.endTrueAnomaly = Kepler.GetTrueAnomalyAtRadius(this.planet.orbitData.SOI, this.semiLatusRectum, this.eccentricity) * (double)Math.Sign(this.meanMotion); } this.orbitType = Orbit.Type.Escape; this.nextPlanet = this.planet.parentBody; } double cutEndTime = (this.orbitType != Orbit.Type.Escape) ? (timeIn + this._period * 0.995) : double.PositiveInfinity; List <Orbit.Pass> list = new List <Orbit.Pass>(); CelestialBodyData[] satellites = this.planet.satellites; for (int i = 0; i < satellites.Length; i++) { CelestialBodyData celestialBodyData = satellites[i]; if (this.CanPasSOI(celestialBodyData.orbitData.orbitHeightM, celestialBodyData.orbitData.SOI)) { double cutStartTime = timeIn + ((!(celestialBodyData != lastPlanet)) ? ((this.orbitType != Orbit.Type.Escape) ? (this._period * 0.05) : double.PositiveInfinity) : 0.0); list.AddRange(this.CreatePasses(this.orbitType == Orbit.Type.Escape, cutStartTime, cutEndTime, celestialBodyData)); if (this.orbitType == Orbit.Type.Eternal) { this.calculatePassesTime = cutEndTime; } } } this.ProcessPasses(this.SortPasses(list)); }
private static void CalculateClosestApproach(LineRenderer closestApproachLine, Orbit orbit, CelestialBodyData targetPlanet, ref bool drawn) { List <double> list = new List <double>(); if (orbit.periapsis < targetPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetPlanet.orbitData.orbitHeightM) { double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity); list.Add(trueAnomalyAtRadius); list.Add(-trueAnomalyAtRadius); } else { if (!orbit.CanPasSOI(targetPlanet.orbitData.orbitHeightM, targetPlanet.mapData.showClosestApproachDistance)) { return; } if (orbit.apoapsis < targetPlanet.orbitData.orbitHeightM) { list.Add(3.1415927410125732); } else { list.Add(0.0); } } double num = double.PositiveInfinity; Double3 posA = Double3.zero; Double3 posB = Double3.zero; for (int i = 0; i < list.Count; i++) { double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]); if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime) { Double3 position = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis); Double3 posOut = targetPlanet.GetPosOut(nextTrueAnomalyPassageTime); double sqrMagnitude2d = (position - posOut).sqrMagnitude2d; if (sqrMagnitude2d <= num) { num = sqrMagnitude2d; posA = position; posB = posOut; } } } if (list.Count > 0) { ClosestApproach.SetLine(closestApproachLine, posA, posB, Ref.map.mapRefs[targetPlanet.parentBody].holder); drawn = true; } }
private bool CalculateClosestApproach(Orbit orbit, CelestialBodyData targetingPlanet) { double num = double.PositiveInfinity; Double3 @double = Double3.zero; Double3 a = Double3.zero; bool flag = false; if (orbit.planet != targetingPlanet) { List <double> list = new List <double>(); if (orbit.periapsis < targetingPlanet.orbitData.orbitHeightM && orbit.apoapsis > targetingPlanet.orbitData.orbitHeightM) { double trueAnomalyAtRadius = Kepler.GetTrueAnomalyAtRadius(targetingPlanet.orbitData.orbitHeightM, orbit.semiLatusRectum, orbit.eccentricity); list.Add(trueAnomalyAtRadius); list.Add(-trueAnomalyAtRadius); } else { if (!orbit.CanPasSOI(targetingPlanet.orbitData.orbitHeightM, targetingPlanet.mapData.showClosestApproachDistance)) { return(false); } if (orbit.apoapsis < targetingPlanet.orbitData.orbitHeightM) { list.Add(3.1415927410125732); } else { list.Add(0.0); } } for (int i = 0; i < list.Count; i++) { double nextTrueAnomalyPassageTime = orbit.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]); if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime) { Double3 position = Kepler.GetPosition(Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, list[i]), list[i], orbit.argumentOfPeriapsis); Double3 double2 = (!(orbit.planet != targetingPlanet)) ? Double3.zero : targetingPlanet.GetPosOut(nextTrueAnomalyPassageTime); double sqrMagnitude2d = (position - double2).sqrMagnitude2d; if (sqrMagnitude2d < num) { num = sqrMagnitude2d; @double = position; a = double2; flag = true; } } } } else { @double = Kepler.GetPosition(orbit.periapsis, 0.0, orbit.argumentOfPeriapsis); flag = true; } if (!flag) { return(false); } Transform transform = (!(orbit.planet != targetingPlanet)) ? targetingPlanet.mapRefs.holder : targetingPlanet.parentBody.mapRefs.holder; if (this.transferWindow.closestApproachMarker.transform.parent != transform) { this.transferWindow.closestApproachMarker.transform.parent = transform; } this.transferWindow.closestApproachMarker.transform.localPosition = (@double / 10000.0).toVector3; Double3 double3 = (a - @double) / 10000.0; this.transferWindow.closestApproachMarker.SetPosition(1, double3.toVector3); this.transferWindow.closestApproachMarker.sharedMaterial.mainTextureScale = new Vector2(Mathf.Max(1.6f, (float)(double3.magnitude2d / -(float)this.mapPosition.z * 80.0) + 0.6f), 1f); return(true); }