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 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); } }
private static void UpdateLocalTransferWindowMarker(ref bool show, ref MeshFilter meshFilterOrbit, double ejectionOrbitHeight, Orbit orbit, TransferWindow.Data transferWindow) { if (transferWindow.departure.type == CelestialBodyData.Type.Star || (transferWindow.transferType == TransferWindow.TransferType.ToNeighbour && transferWindow.departure != transferWindow.firstNeighbour)) { return; } if (transferWindow.transferType == TransferWindow.TransferType.ToNeighbour || transferWindow.transferType == TransferWindow.TransferType.ToParent) { CelestialBodyData celestialBodyData = (transferWindow.transferType != TransferWindow.TransferType.ToNeighbour) ? transferWindow.departure : transferWindow.firstNeighbour; double orbitHeightM = celestialBodyData.orbitData.orbitHeightM; double num = (transferWindow.transferType != TransferWindow.TransferType.ToNeighbour) ? (transferWindow.target.radius + transferWindow.target.atmosphereData.atmosphereHeightM) : transferWindow.secondNeighbour.orbitData.orbitHeightM; double num2 = Math.Min(num, orbitHeightM); double num3 = (orbitHeightM + num) * 0.5; double e = 1.0 - num2 / num3; double mass = celestialBodyData.parentBody.mass; double meanMotion = Kepler.GetMeanMotion(Kepler.GetPeriod(e, num3, mass), e, mass, num3); bool flag = num > orbitHeightM; double magnitude2d = Kepler.GetVelocity(num3, orbitHeightM, meanMotion, (!flag) ? 3.1415926535897931 : 0.0, (!flag) ? 3.1415926535897931 : 0.0, e, 0.0).magnitude2d; double escapeVelocity = magnitude2d - -celestialBodyData.orbitData.orbitalVelocity; float num4 = (float)(Kepler.GetEjectionAngle(escapeVelocity, ejectionOrbitHeight, celestialBodyData.mass, celestialBodyData.orbitData.SOI) * (double)Math.Sign(-orbit.meanMotion) + ((!flag) ? 3.1415926535897931 : 0.0)); float ejectionAngle = num4 + (float)(Ref.controller.globalTime * celestialBodyData.orbitData._meanMotion) - 1.57079637f; TransferWindow.GenerateMeshOrbitTW(ref meshFilterOrbit, ref show, ejectionAngle, orbit); return; } if (transferWindow.transferType != TransferWindow.TransferType.ToSatellite) { return; } if (ejectionOrbitHeight > transferWindow.target.orbitData.orbitHeightM * 0.75) { return; } float num5 = (float)Kepler.GetPhaseAngle(ejectionOrbitHeight, transferWindow.target.orbitData.orbitHeightM); float ejectionAngle2 = num5 + (float)(Ref.controller.globalTime * transferWindow.target.orbitData._meanMotion); TransferWindow.GenerateMeshOrbitTW(ref meshFilterOrbit, ref show, ejectionAngle2, orbit); }