Tools: Removed unused MovingAverage class. Added new getSurfacePitch vessel extension. Refactored getVesselHeading method into two new vessel extensions.
Tools: Removed unused MovingAverage class. Added new getSurfacePitch vessel extension. Refactored getVesselHeading method into two new vessel extensions.

file:a/Tools.cs -> file:b/Tools.cs
--- a/Tools.cs
+++ b/Tools.cs
@@ -149,67 +149,17 @@
 			return string.Format("{0}° {1}", Math.Abs(v_lat).ToString(format), dir_lat);
 		}
 
-		///////////////////////////////////////////////////////////////////////////////
-
-		//For MuMech_get_heading()
-		public class MuMech_MovingAverage
-		{
-			private double[] store;
-			private int storeSize;
-			private int nextIndex = 0;
-
-			public double value
-			{
-				get
-				{
-					double tmp = 0;
-					foreach (double i in store)
-					{
-						tmp += i;
-					}
-					return tmp / storeSize;
-				}
-				set
-				{
-					store[nextIndex] = value;
-					nextIndex = (nextIndex + 1) % storeSize;
-				}
-			}
-
-			public MuMech_MovingAverage(int size = 10, double startingValue = 0)
-			{
-				storeSize = size;
-				store = new double[size];
-				force(startingValue);
-			}
-
-			public void force(double newValue)
-			{
-				for (int i = 0; i < storeSize; i++)
-				{
-					store[i] = newValue;
-				}
-			}
-
-			public static implicit operator double(MuMech_MovingAverage v)
-			{
-				return v.value;
-			}
-
-			public override string ToString()
-			{
-				return value.ToString();
-			}
-
-			public string ToString(string format)
-			{
-				return value.ToString(format);
-			}
-		}
-		//From http://svn.mumech.com/KSP/trunk/MuMechLib/VOID.vesselState.cs
-		public static double MuMech_get_heading(Vessel vessel)
-		{
-			Vector3d CoM;
+		/*
+		* MuMechLib Methods
+		* The methods below are adapted from MuMechLib, © 2013-2014 r4m0n
+		* The following methods are a derivative work of the code from MuMechLib in the MechJeb project.
+		* Used under license.
+		* */
+
+		// Derived from MechJeb2/VesselState.cs
+		public static Quaternion getSurfaceRotation(this Vessel vessel)
+		{
+			Vector3 CoM;
 
 			try
 			{
@@ -217,25 +167,42 @@
 			}
 			catch
 			{
-				return double.NaN;
-			}
-
-			Vector3d up = (CoM - vessel.mainBody.position).normalized;
-			Vector3d north = Vector3d.Exclude(
-				                 up,
-				                 (vessel.mainBody.position +
-				                 vessel.mainBody.transform.up * (float)vessel.mainBody.Radius
-				                 ) - CoM).normalized;
-
-			Quaternion rotationSurface = Quaternion.LookRotation(north, up);
-			Quaternion rotationvesselSurface = Quaternion.Inverse(
-				                                   Quaternion.Euler(90, 0, 0) *
-				                                   Quaternion.Inverse(vessel.transform.rotation) *
-				                                   rotationSurface);
-
-			return rotationvesselSurface.eulerAngles.y;
-		}
-		//From http://svn.mumech.com/KSP/trunk/MuMechLib/MuUtils.cs
+				return new Quaternion();
+			}
+
+			Vector3 bodyPosition = vessel.mainBody.position;
+			Vector3 bodyUp = vessel.mainBody.transform.up;
+
+			Vector3 surfaceUp = (CoM - vessel.mainBody.position).normalized;
+			Vector3 surfaceNorth = Vector3.Exclude(
+				surfaceUp,
+				(bodyPosition + bodyUp * (float)vessel.mainBody.Radius) - CoM
+			).normalized;
+
+			Quaternion surfaceRotation = Quaternion.LookRotation(surfaceNorth, surfaceUp);
+
+			return Quaternion.Inverse(
+				Quaternion.Euler(90, 0, 0) * Quaternion.Inverse(vessel.GetTransform().rotation) * surfaceRotation
+			);
+		}
+
+		// Derived from MechJeb2/VesselState.cs
+		public static double getSurfaceHeading(this Vessel vessel)
+		{
+			return vessel.getSurfaceRotation().eulerAngles.y;
+		}
+
+		// Derived from MechJeb2/VesselState.cs
+		public static double getSurfacePitch(this Vessel vessel)
+		{
+			Quaternion vesselSurfaceRotation = vessel.getSurfaceRotation();
+
+			return (vesselSurfaceRotation.eulerAngles.x > 180f) ?
+				(360f - vesselSurfaceRotation.eulerAngles.x) :
+				-vesselSurfaceRotation.eulerAngles.x;
+		}
+
+		// Derived from MechJeb2/MuUtils.cs
 		public static string MuMech_ToSI(
 			double d, int digits = 3, int MinMagnitude = 0, int MaxMagnitude = int.MaxValue
 		)
@@ -325,6 +292,10 @@
 			}
 		}
 
+		/*
+		 * END MuMecLib METHODS
+		 * */
+
 		public static string ConvertInterval(double seconds)
 		{
 			string format_1 = "{0:D1}y {1:D1}d {2:D2}h {3:D2}m {4:D2}.{5:D1}s";