/// <summary> /// Gets the descending node of orbit. /// </summary> /// <param name="desc">The desc.</param> /// <returns><c>true</c> if descending node exists, otherwise <c>false</c></returns> public bool GetDescendingNode(out Vector3d desc) { var norm = CelestialBodyUtils.CrossProduct(OrbitNormal, EclipticNormal); var s = CelestialBodyUtils.DotProduct(CelestialBodyUtils.CrossProduct(norm, SemiMajorAxisBasis), OrbitNormal) < 0; var ecc = 0d; var trueAnom = Vector3d.Angle(norm, -CenterPoint) * Mathd.Deg2Rad; if (Eccentricity < 1) { var cosT = Math.Cos(trueAnom); ecc = Math.Acos((Eccentricity + cosT) / (1d + Eccentricity * cosT)); if (s) { ecc = Mathd.PI_2 - ecc; } } else { trueAnom = Vector3d.Angle(norm, CenterPoint) * Mathd.Deg2Rad; if (trueAnom >= Mathd.Acos(-1d / Eccentricity)) { desc = new Vector3d(); return(false); } var cosT = Math.Cos(trueAnom); ecc = CelestialBodyUtils.Acosh((Eccentricity + cosT) / (1 + Eccentricity * cosT)) * (s ? -1 : 1); } desc = GetFocalPositionAtEccentricAnomaly(ecc); return(true); }
public bool GetAscendingNode(out Vector3d asc) { var norm = CelestialBodyUtils.CrossProduct(orbitNormal, eclipticNormal); var s = CelestialBodyUtils.DotProduct(CelestialBodyUtils.CrossProduct(norm, semiMajorAxisBasis), orbitNormal) < 0; var ecc = 0d; var trueAnom = Vector3d.Angle(norm, centerPoint) * Mathd.Deg2Rad; if (eccentricity < 1) { var cosT = System.Math.Cos(trueAnom); ecc = System.Math.Acos((eccentricity + cosT) / (1d + eccentricity * cosT)); if (!s) { ecc = Mathd.PI_2 - ecc; } } else { trueAnom = Vector3d.Angle(-norm, centerPoint) * Mathd.Deg2Rad; if (trueAnom >= Mathd.Acos(-1d / eccentricity)) { asc = new Vector3d(); return(false); } var cosT = System.Math.Cos(trueAnom); ecc = CelestialBodyUtils.Acosh((eccentricity + cosT) / (1 + eccentricity * cosT)) * (!s ? -1 : 1); } asc = GetFocalPositionAtEccentricAnomaly(ecc); return(true); }
public static double ConvertTrueToEccentricAnomaly(double trueAnomaly, double eccentricity) { trueAnomaly = trueAnomaly % Mathd.PI_2; if (eccentricity < 1d) { if (trueAnomaly < 0) { trueAnomaly = trueAnomaly + Mathd.PI_2; } var cosT2 = System.Math.Cos(trueAnomaly); var eccAnom = System.Math.Acos((eccentricity + cosT2) / (1d + eccentricity * cosT2)); if (trueAnomaly > Mathd.PI) { eccAnom = Mathd.PI_2 - eccAnom; } return(eccAnom); } else { var cosT = System.Math.Cos(trueAnomaly); var eccAnom = CelestialBodyUtils.Acosh((eccentricity + cosT) / (1d + eccentricity * cosT)) * System.Math.Sign(trueAnomaly); return(eccAnom); } }