Fixed issue with angle to prograde/retrograde calculations on highly inclined orbits. (resolves #63)
Fixed issue with angle to prograde/retrograde calculations on highly inclined orbits. (resolves #63)

--- a/Documents/CHANGES.txt
+++ b/Documents/CHANGES.txt
@@ -7,6 +7,7 @@
     Fixed: Optimised time formatting. (itwtx)
     Fixed: TimeToAtmosphere checks that the Apoapsis is outside atmosphere. (Kerbas-ad-astra)
     Fixed: Issue with stage priority flow. Caused Rapier calculations to fail if LF and O are drawn from different tanks. (Padishar)
+    Fixed: Issue with angle to prograde/retrograde calculations on highly inclined orbits.
     Removed: Time Formatter readout as it's not required anymore.
 
 1.0.18.0

--- a/KerbalEngineer/Extensions/OrbitExtensions.cs
+++ b/KerbalEngineer/Extensions/OrbitExtensions.cs
@@ -61,12 +61,15 @@
                 return 0.0;
             }
 
-            var angle = AngleHelper.GetAngleBetweenVectors(orbit.getRelativePositionAtUT(universalTime),
-                                                           Vector3d.Exclude(orbit.GetOrbitNormal(), orbit.referenceBody.orbit.getRelativePositionAtUT(universalTime)));
+            Vector3d orbitVector = orbit.getRelativePositionAtUT(universalTime);
+            orbitVector.z = 0.0;
 
-            angle = AngleHelper.Clamp360(angle - 90.0);
+            Vector3d bodyVector = orbit.referenceBody.orbit.getOrbitalVelocityAtUT(universalTime);
+            bodyVector.z = 0.0;
 
-            return orbit.inclination > 90.0 ? angle : 360.0 - angle;
+            double angle = AngleHelper.GetAngleBetweenVectors(bodyVector, orbitVector);
+
+            return AngleHelper.Clamp360(orbit.inclination < 90.0 ? angle : 360.0 - angle);
         }
 
         public static double GetAngleToRetrograde(this Orbit orbit)
@@ -81,12 +84,15 @@
                 return 0.0;
             }
 
-            var angle = AngleHelper.GetAngleBetweenVectors(orbit.getRelativePositionAtUT(universalTime),
-                                                           Vector3d.Exclude(orbit.GetOrbitNormal(), orbit.referenceBody.orbit.getRelativePositionAtUT(universalTime)));
+            Vector3d orbitVector = orbit.getRelativePositionAtUT(universalTime);
+            orbitVector.z = 0.0;
 
-            angle = AngleHelper.Clamp360(angle + 90.0);
+            Vector3d bodyVector = orbit.referenceBody.orbit.getOrbitalVelocityAtUT(universalTime);
+            bodyVector.z = 0.0;
 
-            return orbit.inclination > 90.0 ? angle : 360.0 - angle;
+            double angle = AngleHelper.GetAngleBetweenVectors(-bodyVector, orbitVector);
+
+            return AngleHelper.Clamp360(orbit.inclination < 90.0 ? angle : 360.0 - angle);
         }
 
         public static double GetAngleToTrueAnomaly(this Orbit orbit, double trueAnomaly)

 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ