//TODO 1.1 changed trueAnomaly to rad but MJ ext stil uses deg. Should change for consistency //Originally by Zool, revised by The_Duck //Converts a true anomaly into an eccentric anomaly. //For elliptical orbits this returns a value between 0 and 2pi //For hyperbolic orbits the returned value can be any number. //NOTE: For a hyperbolic orbit, if a true anomaly is requested that does not exist (a true anomaly //past the true anomaly of the asymptote) then an ArgumentException is thrown public static double GetEccentricAnomalyAtTrueAnomaly(this Orbit o, double trueAnomaly) { double e = o.eccentricity; trueAnomaly = MuUtils.ClampDegrees360(trueAnomaly); trueAnomaly = trueAnomaly * (Math.PI / 180); if (e < 1) //elliptical orbits { double cosE = (e + Math.Cos(trueAnomaly)) / (1 + e * Math.Cos(trueAnomaly)); double sinE = Math.Sqrt(1 - (cosE * cosE)); if (trueAnomaly > Math.PI) { sinE *= -1; } return(MuUtils.ClampRadiansTwoPi(Math.Atan2(sinE, cosE))); } else //hyperbolic orbits { double coshE = (e + Math.Cos(trueAnomaly)) / (1 + e * Math.Cos(trueAnomaly)); if (coshE < 1) { throw new ArgumentException("OrbitExtensions.GetEccentricAnomalyAtTrueAnomaly: True anomaly of " + trueAnomaly + " radians is not attained by orbit with eccentricity " + o.eccentricity); } double E = MuUtils.Acosh(coshE); if (trueAnomaly > Math.PI) { E *= -1; } return(E); } }