public void SteadyMotionTest() { var t = 5; var s = 35; var v = 7; Assert.AreEqual(t, SteadyMotion.GetDuration(s, v)); Assert.AreEqual(s, SteadyMotion.GetDistance(v, t)); Assert.AreEqual(v, SteadyMotion.GetVelocity(s, t)); }
/// <summary> /// Find t in s = 0.5*a*t² + v0*t /// </summary> /// <param name="s">The distance [m].</param> /// <param name="a">The acceleration [m/s²].</param> /// <param name="v0">The initial velocity [m/s].</param> /// <exception cref="NegativeValueException">Thrown, if the given distance will never be reached.</exception> /// <returns>Returns the duration [s].</returns> public static Durations GetDuration(double s, double a, double v0) { if (a == 0) { var t = SteadyMotion.GetDuration(s, v0); return(new Durations(t, t)); } var sqrt = 2 * a * s + v0 * v0; if (sqrt < 0) { throw new NegativeValueException($"The distance {s}m will never be reached starting with a velocity of {v0}m/s and accelerating with {a}m/s²"); } var t1 = (-Math.Sqrt(sqrt) - v0) / a; var t2 = (Math.Sqrt(sqrt) - v0) / a; var durations = new Durations(t1, t2); return(durations); }