Browse Source

Merge pull request #1475 from LumaDigital/MB-MathHelper-Acceleration

Added a function to calculate acceleration to the MathHelper class
JoshEngebretson 8 years ago
parent
commit
40ad572856
1 changed files with 12 additions and 0 deletions
  1. 12 0
      Script/AtomicNET/AtomicNET/Math/MathHelper.cs

+ 12 - 0
Script/AtomicNET/AtomicNET/Math/MathHelper.cs

@@ -337,6 +337,18 @@ namespace AtomicEngine
                 (3.0 * value2 - value1 - 3.0 * value3 + value4) * amountCubed));
         }
 
+        /// <summary>
+        /// Calculates the acceleration
+        /// </summary>
+        /// <param name="vO">Initial Velocity.</param>
+        /// <param name="t">Total time.</param>
+        /// <param name="xO">Initial Position.</param>
+        /// <param name="xF">Final Position.</param>
+        /// <returns>Acceleration based on equation of motion: Xf = Xo + Vot + 0.5at^2</returns>
+        public static float Acceleration(float vO, float t, Vector3 xO, Vector3 xF)
+        {
+            return ((2 / (t * t)) * ((xF - xO).Length - (vO * t)));
+        }
 
     }
 }