/// <summary> /// Updates the value of orbital anomalies by defined deltatime. /// </summary> /// <param name="deltaTime">The delta time.</param> /// <remarks> /// Only anomalies values will be changed. /// Position and velocity states needs to be updated too after this method call. /// </remarks> public void UpdateOrbitAnomaliesByTime(double deltaTime) { if (Eccentricity < 1) { if (Period > 1e-5) { MeanAnomaly += Mathd.PI_2 * deltaTime / Period; } MeanAnomaly %= Mathd.PI_2; if (MeanAnomaly < 0) { MeanAnomaly = Mathd.PI_2 - MeanAnomaly; } EccentricAnomaly = CelestialBodyUtils.KeplerSolver(MeanAnomaly, Eccentricity); var cosE = Math.Cos(EccentricAnomaly); TrueAnomaly = Math.Acos((cosE - Eccentricity) / (1 - Eccentricity * cosE)); if (MeanAnomaly > Mathd.PI) { TrueAnomaly = Mathd.PI_2 - TrueAnomaly; } if (double.IsNaN(MeanAnomaly) || double.IsInfinity(MeanAnomaly)) { Debug.Log("SpaceGravity2D: NaN(INF) MEAN ANOMALY"); //litle paranoya Debug.Break(); } if (double.IsNaN(EccentricAnomaly) || double.IsInfinity(EccentricAnomaly)) { Debug.Log("SpaceGravity2D: NaN(INF) ECC ANOMALY"); Debug.Break(); } if (double.IsNaN(TrueAnomaly) || double.IsInfinity(TrueAnomaly)) { Debug.Log("SpaceGravity2D: NaN(INF) TRUE ANOMALY"); Debug.Break(); } } else { double n = Math.Sqrt(AttractorMass * GravitationalConstant / Math.Pow(SemiMajorAxis, 3)); MeanAnomaly = MeanAnomaly + n * deltaTime; EccentricAnomaly = CelestialBodyUtils.KeplerSolverHyperbolicCase(MeanAnomaly, Eccentricity); TrueAnomaly = Math.Atan2(Math.Sqrt(Eccentricity * Eccentricity - 1.0) * Math.Sinh(EccentricAnomaly), Eccentricity - Math.Cosh(EccentricAnomaly)); } }
public void UpdateOrbitAnomaliesByTime(double deltaTime) { if (eccentricity < 1) { if (period > 1e-5) { meanAnomaly += Mathd.PI_2 * deltaTime / period; } meanAnomaly %= Mathd.PI_2; if (meanAnomaly < 0) { meanAnomaly = Mathd.PI_2 - meanAnomaly; } eccentricAnomaly = CelestialBodyUtils.KeplerSolver(meanAnomaly, eccentricity); var cosE = System.Math.Cos(eccentricAnomaly); trueAnomaly = System.Math.Acos((cosE - eccentricity) / (1 - eccentricity * cosE)); if (meanAnomaly > Mathd.PI) { trueAnomaly = Mathd.PI_2 - trueAnomaly; } if (double.IsNaN(meanAnomaly) || double.IsInfinity(meanAnomaly)) { Debug.Log("SpaceGravity2D: NaN(INF) MEAN ANOMALY"); //litle paranoya Debug.Break(); } if (double.IsNaN(eccentricAnomaly) || double.IsInfinity(eccentricAnomaly)) { Debug.Log("SpaceGravity2D: NaN(INF) ECC ANOMALY"); Debug.Break(); } if (double.IsNaN(trueAnomaly) || double.IsInfinity(trueAnomaly)) { Debug.Log("SpaceGravity2D: NaN(INF) TRUE ANOMALY"); Debug.Break(); } } else { double n = System.Math.Sqrt(attractorMass * gravConst / System.Math.Pow(semiMajorAxis, 3)) * Mathd.Sign(orbitNormalDotEclipticNormal); meanAnomaly = meanAnomaly - n * deltaTime; eccentricAnomaly = CelestialBodyUtils.KeplerSolverHyperbolicCase(meanAnomaly, eccentricity); trueAnomaly = System.Math.Atan2(System.Math.Sqrt(eccentricity * eccentricity - 1.0) * System.Math.Sinh(eccentricAnomaly), eccentricity - System.Math.Cosh(eccentricAnomaly)); } }
/// <summary> /// Sets the mean anomaly and updates all other anomalies. /// </summary> /// <param name="m">The m.</param> public void SetMeanAnomaly(double m) { if (!IsValidOrbit) { return; } MeanAnomaly = m % Mathd.PI_2; if (Eccentricity < 1) { if (MeanAnomaly < 0) { MeanAnomaly += Mathd.PI_2; } EccentricAnomaly = CelestialBodyUtils.KeplerSolver(MeanAnomaly, Eccentricity); TrueAnomaly = CelestialBodyUtils.ConvertEccentricToTrueAnomaly(EccentricAnomaly, Eccentricity); } else { EccentricAnomaly = CelestialBodyUtils.KeplerSolverHyperbolicCase(MeanAnomaly, Eccentricity); TrueAnomaly = CelestialBodyUtils.ConvertEccentricToTrueAnomaly(EccentricAnomaly, Eccentricity); } SetPositionByCurrentAnomaly(); SetVelocityByCurrentAnomaly(); }
/// <summary> /// Sets the eccentricity and updates all corresponding orbit state values. /// </summary> /// <param name="e">The new eccentricity value.</param> /// <remarks> /// Mean anomaly will try to preserve. /// </remarks> public void SetEccentricity(double e) { if (!IsValidOrbit) { return; } e = Mathd.Abs(e); var _periapsis = PeriapsisDistance; // Periapsis remains constant Eccentricity = e; var compresion = Eccentricity < 1 ? (1 - Eccentricity * Eccentricity) : (Eccentricity * Eccentricity - 1); SemiMajorAxis = Math.Abs(_periapsis / (1 - Eccentricity)); FocalParameter = SemiMajorAxis * compresion; SemiMinorAxis = SemiMajorAxis * Mathd.Sqrt(compresion); CenterPoint = SemiMajorAxis * Math.Abs(Eccentricity) * SemiMajorAxisBasis; if (Eccentricity < 1) { EccentricAnomaly = CelestialBodyUtils.KeplerSolver(MeanAnomaly, Eccentricity); var cosE = Math.Cos(EccentricAnomaly); TrueAnomaly = Math.Acos((cosE - Eccentricity) / (1 - Eccentricity * cosE)); if (MeanAnomaly > Mathd.PI) { TrueAnomaly = Mathd.PI_2 - TrueAnomaly; } } else { EccentricAnomaly = CelestialBodyUtils.KeplerSolverHyperbolicCase(MeanAnomaly, Eccentricity); TrueAnomaly = Math.Atan2(Math.Sqrt(Eccentricity * Eccentricity - 1) * Math.Sinh(EccentricAnomaly), Eccentricity - Math.Cosh(EccentricAnomaly)); } SetVelocityByCurrentAnomaly(); SetPositionByCurrentAnomaly(); CalculateNewOrbitData(); }
public void SetEccentricity(double e) { if (!isValidOrbit) { return; } e = Mathd.Abs(e); var _periapsis = periapsisDistance; // Periapsis remains constant eccentricity = e; var compresion = eccentricity < 1 ? (1 - eccentricity * eccentricity) : (eccentricity * eccentricity - 1); semiMajorAxis = System.Math.Abs(_periapsis / (1 - eccentricity)); focalParameter = semiMajorAxis * compresion; semiMinorAxis = semiMajorAxis * Mathd.Sqrt(compresion); centerPoint = semiMajorAxis * System.Math.Abs(eccentricity) * semiMajorAxisBasis; if (eccentricity < 1) { eccentricAnomaly = CelestialBodyUtils.KeplerSolver(meanAnomaly, eccentricity); var cosE = System.Math.Cos(eccentricAnomaly); trueAnomaly = System.Math.Acos((cosE - eccentricity) / (1 - eccentricity * cosE)); if (meanAnomaly > Mathd.PI) { trueAnomaly = Mathd.PI_2 - trueAnomaly; } } else { eccentricAnomaly = CelestialBodyUtils.KeplerSolverHyperbolicCase(meanAnomaly, eccentricity); trueAnomaly = System.Math.Atan2(System.Math.Sqrt(eccentricity * eccentricity - 1) * System.Math.Sinh(eccentricAnomaly), eccentricity - System.Math.Cosh(eccentricAnomaly)); } SetVelocityByCurrentAnomaly(); SetPositionByCurrentAnomaly(); CalculateNewOrbitData(); }