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 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; } }
public static void DrawClosestApproachPlanet(LineRenderer closestApproachLine, List <Orbit> orbits, CelestialBodyData targetPlanet, ref bool drawn) { for (int i = 0; i < orbits.Count; i++) { if (orbits[i].orbitType != Orbit.Type.Encounter) { if (orbits[i].planet == targetPlanet) { ClosestApproach.SetLine(closestApproachLine, Kepler.GetPosition(orbits[i].periapsis, 0.0, orbits[i].argumentOfPeriapsis), Double3.zero, Ref.map.mapRefs[targetPlanet].holder); drawn = true; return; } if (orbits[i].planet == targetPlanet.parentBody) { ClosestApproach.CalculateClosestApproach(closestApproachLine, orbits[i], targetPlanet, ref drawn); if (drawn) { return; } } } } }