Example #1
0
        //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 = JUtil.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(JUtil.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 = JUtil.Acosh(coshE);
                if (trueAnomaly > Math.PI)
                {
                    E *= -1;
                }

                return(E);
            }
        }
Example #2
0
 //Gives the true anomaly (in a's orbit) at which a crosses its descending node
 //with b's orbit.
 //The returned value is always between 0 and 360.
 public static double DescendingNodeTrueAnomaly(this Orbit a, Orbit b)
 {
     return(JUtil.ClampDegrees360(a.AscendingNodeTrueAnomaly(b) + 180));
 }