private static double GetDistanceSqrtAtHeight(Orbit orbitA, Orbit orbitB, double time, double globalTrueAnomaly) { double nextTrueAnomalyPassageTime = orbitA.GetNextTrueAnomalyPassageTime(time, globalTrueAnomaly - orbitA.argumentOfPeriapsis); Double3 position = Kepler.GetPosition(Kepler.GetRadius(orbitA.semiLatusRectum, orbitA.eccentricity, globalTrueAnomaly - orbitA.argumentOfPeriapsis), globalTrueAnomaly, 0.0); Double3 posOut = orbitB.GetPosOut(nextTrueAnomalyPassageTime); Debug.DrawLine((position / 10000.0).toVector3, (posOut / 10000.0).toVector3, Color.green); return((position - posOut).sqrMagnitude2d); }
public Vector3[] GenerateOrbitLinePoints(double fromTrueAnomaly, double toTrueAnomaly, int resolution) { Vector3[] array = new Vector3[resolution + 1]; double num = (toTrueAnomaly - fromTrueAnomaly) % 6.2831853071795862 / (double)resolution; for (int i = 0; i < resolution + 1; i++) { double v = fromTrueAnomaly + num * (double)i; double radius = Kepler.GetRadius(this.semiLatusRectum, this.eccentricity, v); array[i] = Kepler.GetPosition(radius, v, this.argumentOfPeriapsis).toVector3; } return(array); }
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 void UpdateDynamicVariables(double newTime) { if (this.lastCalculationTime != newTime) { this.lastCalculationTime = newTime; double eccentricAnomaly = Kepler.GetEccentricAnomaly((newTime - this.periapsisPassageTime) * this.meanMotion, this.eccentricity); if (double.IsNaN(eccentricAnomaly)) { return; } this.eccentricAnomnalyOut = eccentricAnomaly; this.trueAnomalyOut = Kepler.GetTrueAnomaly(this.eccentricAnomnalyOut, this.eccentricity); double radius = Kepler.GetRadius(this.semiLatusRectum, this.eccentricity, this.trueAnomalyOut); this.posOut = Kepler.GetPosition(radius, this.trueAnomalyOut, this.argumentOfPeriapsis); this.velOut = Kepler.GetVelocity(this.semiMajorAxis, radius, this.meanMotion, this.eccentricAnomnalyOut, this.trueAnomalyOut, this.eccentricity, this.argumentOfPeriapsis); } }
public static List <Orbit> CalculateOrbits(List <Orbit> orbitsIn) { while (orbitsIn.Count < 3) { Orbit orbit = orbitsIn[orbitsIn.Count - 1]; if (orbit.orbitType == Orbit.Type.Escape) { if (orbitsIn.Count >= 2 && orbitsIn[orbitsIn.Count - 2].orbitType == Orbit.Type.Encounter) { return(orbitsIn); } Double3 position = Kepler.GetPosition(orbit.planet.orbitData.SOI, orbit.endTrueAnomaly, orbit.argumentOfPeriapsis); Double3 velocity = Kepler.GetVelocity(orbit.semiMajorAxis, orbit.planet.orbitData.SOI, orbit.meanMotion, Kepler.GetEccentricAnomalyFromTrueAnomaly(orbit.endTrueAnomaly, orbit.eccentricity), orbit.endTrueAnomaly, orbit.eccentricity, orbit.argumentOfPeriapsis); Double3 posIn = position + orbit.planet.GetPosOut(orbit.orbitEndTime); Double3 velIn = velocity + orbit.planet.GetVelOut(orbit.orbitEndTime); if (double.IsNaN(posIn.x * velIn.y - posIn.y * velIn.x)) { return(orbitsIn); } orbitsIn.Add(new Orbit(posIn, velIn, orbit.orbitEndTime, orbit.nextPlanet, orbit.planet)); } else { if (orbit.orbitType != Orbit.Type.Encounter) { return(orbitsIn); } if (orbitsIn.Count >= 2 && orbitsIn[orbitsIn.Count - 2].planet == orbit.nextPlanet) { return(orbitsIn); } double eccentricAnomalyFromTrueAnomaly = Kepler.GetEccentricAnomalyFromTrueAnomaly(orbit.endTrueAnomaly, orbit.eccentricity); double radius = Kepler.GetRadius(orbit.semiLatusRectum, orbit.eccentricity, orbit.endTrueAnomaly); Double3 position2 = Kepler.GetPosition(radius, orbit.endTrueAnomaly, orbit.argumentOfPeriapsis); Double3 velocity2 = Kepler.GetVelocity(orbit.semiMajorAxis, radius, orbit.meanMotion, eccentricAnomalyFromTrueAnomaly, orbit.endTrueAnomaly, orbit.eccentricity, orbit.argumentOfPeriapsis); Double3 posIn2 = position2 - orbit.nextPlanet.GetPosOut(orbit.orbitEndTime); Double3 velIn2 = velocity2 - orbit.nextPlanet.GetVelOut(orbit.orbitEndTime); if (double.IsNaN(posIn2.x * velIn2.y - posIn2.y * velIn2.x)) { return(orbitsIn); } orbitsIn.Add(new Orbit(posIn2, velIn2, orbit.orbitEndTime, orbit.nextPlanet, null)); } } return(orbitsIn); }
private static void CalculateClosestApproach(LineRenderer closestApproachLine, Orbit orbitA, Orbit orbitB, double time, ref bool drawn) { if (orbitA.orbitType != Orbit.Type.Eternal || orbitB.orbitType != Orbit.Type.Eternal) { return; } List <double> list = new List <double>(); if (orbitA._period > orbitB._period) { list.Add(ClosestApproach.GetIntersectTrueAnomalyGlobal(orbitA, orbitB, time, 15) - orbitA.argumentOfPeriapsis); } else { list.Add(ClosestApproach.GetIntersectTrueAnomalyGlobal(orbitB, orbitA, time, 15) - orbitA.argumentOfPeriapsis); } double num = double.PositiveInfinity; Double3 posA = Double3.zero; Double3 posB = Double3.zero; for (int i = 0; i < list.Count; i++) { double nextTrueAnomalyPassageTime = orbitA.GetNextTrueAnomalyPassageTime(Ref.controller.globalTime, list[i]); if (nextTrueAnomalyPassageTime >= Ref.controller.globalTime) { Double3 position = Kepler.GetPosition(Kepler.GetRadius(orbitA.semiLatusRectum, orbitA.eccentricity, list[i]), list[i], orbitA.argumentOfPeriapsis); Double3 posOut = orbitB.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[orbitA.planet].holder); drawn = true; } }
private static void GenerateMeshOrbitTW(ref MeshFilter meshFilterOrbit, ref bool show, float ejectionAngle, Orbit orbit) { for (int i = 0; i < 2; i++) { double num = Math.Abs(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)(ejectionAngle + (float)i * 0.2f * (float)Math.Sign(orbit.meanMotion)) - orbit.argumentOfPeriapsis)); if (num > orbit.planet.orbitData.SOI || num > orbit.periapsis * 1.35) { return; } } Vector3[] array = new Vector3[42]; for (int j = 0; j < 21; j++) { float num2 = ejectionAngle + (float)j * 0.01f * (float)Math.Sign(orbit.meanMotion); array[j * 2] = new Vector3(Mathf.Cos(num2), Mathf.Sin(num2), 0f) * (float)(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)num2 - orbit.argumentOfPeriapsis) / 10000.0); array[j * 2 + 1] = array[j * 2] * 0.915f; } meshFilterOrbit.mesh.vertices = array; meshFilterOrbit.mesh.RecalculateNormals(); meshFilterOrbit.mesh.RecalculateBounds(); show = true; }
private bool GenerateLocalTransferWindowMarker(float ejectionAngle, Orbit orbit) { for (int i = 0; i < 2; i++) { double num = Math.Abs(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)(ejectionAngle + (float)i * 0.2f * (float)Math.Sign(orbit.meanMotion)) - orbit.argumentOfPeriapsis)); if (num > orbit.planet.orbitData.SOI || num > orbit.periapsis * 1.2) { return(false); } } Vector3[] array = new Vector3[42]; for (int j = 0; j < 21; j++) { float num2 = ejectionAngle + (float)j * 0.01f * (float)Math.Sign(orbit.meanMotion); array[j * 2] = new Vector3(Mathf.Cos(num2), Mathf.Sin(num2), 0f) * (float)(Kepler.GetRadius(Kepler.GetSemiLatusRectum(orbit.periapsis, orbit.eccentricity), orbit.eccentricity, (double)num2 - orbit.argumentOfPeriapsis) / 10000.0); array[j * 2 + 1] = array[j * 2] * 0.915f; } this.transferWindow.localMarkerMesh.mesh.vertices = array; this.transferWindow.localMarkerMesh.mesh.RecalculateNormals(); this.transferWindow.localMarkerMesh.mesh.RecalculateBounds(); return(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); }