88using System . Linq ;
99using System . Text ;
1010
11+ using UnityEngine ;
1112using KSP ;
1213
1314namespace KerbalAlarmClock
@@ -121,7 +122,7 @@ internal static double UTAtMeanAnomaly(this Orbit o, double meanAnomaly, double
121122 //The returned value is always between 0 and 360.
122123 internal static double AscendingNodeTrueAnomaly ( this Orbit a , Orbit b )
123124 {
124- Vector3d vectorToAN = Vector3d . Cross ( a . SwappedOrbitNormal ( ) , b . SwappedOrbitNormal ( ) ) ;
125+ Vector3d vectorToAN = Vector3d . Cross ( b . GetOrbitNormal ( ) , a . GetOrbitNormal ( ) ) ;
125126 return a . TrueAnomalyFromVector ( vectorToAN ) ;
126127 }
127128
@@ -130,7 +131,8 @@ internal static double AscendingNodeTrueAnomaly(this Orbit a, Orbit b)
130131 //The returned value is always between 0 and 360.
131132 internal static double DescendingNodeTrueAnomaly ( this Orbit a , Orbit b )
132133 {
133- return MuUtils . ClampDegrees360 ( a . AscendingNodeTrueAnomaly ( b ) + 180 ) ;
134+ Vector3d vectorToDN = Vector3d . Cross ( a . GetOrbitNormal ( ) , b . GetOrbitNormal ( ) ) ;
135+ return a . TrueAnomalyFromVector ( vectorToDN ) ;
134136 }
135137
136138 //Gives the true anomaly at which o crosses the equator going northwards, if o is east-moving,
@@ -196,23 +198,7 @@ internal static bool DescendingNodeEquatorialExists(this Orbit o)
196198 //The returned value is always between 0 and 360.
197199 internal static double TrueAnomalyFromVector ( this Orbit o , Vector3d vec )
198200 {
199- Vector3d projected = Vector3d . Exclude ( o . SwappedOrbitNormal ( ) , vec ) ;
200- Vector3d vectorToPe = SwapYZ ( o . eccVec ) ;
201- double angleFromPe = Math . Abs ( Vector3d . Angle ( vectorToPe , projected ) ) ;
202-
203- //If the vector points to the infalling part of the orbit then we need to do 360 minus the
204- //angle from Pe to get the true anomaly. Test this by taking the the cross product of the
205- //orbit normal and vector to the periapsis. This gives a vector that points to center of the
206- //outgoing side of the orbit. If vectorToAN is more than 90 degrees from this vector, it occurs
207- //during the infalling part of the orbit.
208- if ( Math . Abs ( Vector3d . Angle ( projected , Vector3d . Cross ( o . SwappedOrbitNormal ( ) , vectorToPe ) ) ) < 90 )
209- {
210- return angleFromPe ;
211- }
212- else
213- {
214- return 360 - angleFromPe ;
215- }
201+ return o . GetTrueAnomalyOfZupVector ( vec ) * Mathf . Rad2Deg ;
216202 }
217203
218204 //Originally by Zool, revised by The_Duck
0 commit comments