public void QuaternionLerpTest1() { Vector3 axis = Vector3.Normalize(new Vector3(1.0f, 2.0f, 3.0f)); Quaternion a = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(10.0f)); Quaternion b = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(30.0f)); Single t = 0.0f; Quaternion expected = new Quaternion(a.X, a.Y, a.Z, a.W); Quaternion actual = Quaternion.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), $"Quaternion.Lerp did not return the expected value: expected {expected} actual {actual}"); }
public void QuaternionLerpTest3() { Vector3 axis = Vector3.Normalize(new Vector3(1.0f, 2.0f, 3.0f)); Quaternion a = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(10.0f)); Quaternion b = Quaternion.Negate(a); Single t = 1.0f; Quaternion actual = Quaternion.Lerp(a, b, t); // Note that in quaternion world, Q == -Q. In the case of quaternions dot product is zero, // one of the quaternion will be flipped to compute the shortest distance. When t = 1, we // expect the result to be the same as quaternion b but flipped. Assert.True(actual == a, $"Quaternion.Lerp did not return the expected value: expected {a} actual {actual}"); }
public void QuaternionLerpTest() { Vector3 axis = Vector3.Normalize(new Vector3(1.0f, 2.0f, 3.0f)); Quaternion a = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(10.0f)); Quaternion b = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(30.0f)); Single t = 0.5f; Quaternion expected = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(20.0f)); Quaternion actual; actual = Quaternion.Lerp(a, b, t); Assert.True(MathHelper.Equal(expected, actual), $"Quaternion.Lerp did not return the expected value: expected {expected} actual {actual}"); // Case a and b are same. expected = a; actual = Quaternion.Lerp(a, a, t); Assert.True(MathHelper.Equal(expected, actual), $"Quaternion.Lerp did not return the expected value: expected {expected} actual {actual}"); }