public void SlerpNegatedDoublePrecision()
        {
            QuaternionD q1    = new QuaternionD(-1.0, 0.0, 0.0, 0.0);
            QuaternionD q2    = QuaternionD.CreateRotation(-Vector3.UnitZ, -Math.PI / 2);
            QuaternionD slerp = InterpolationHelper.Slerp(q1, q2, 0.5);

            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Vector3D v      = slerp.Rotate(Vector3D.UnitX);
            Vector3D result = new Vector3D(1.0, 1.0, 0.0).Normalized;

            Assert.IsTrue(Vector3D.AreNumericallyEqual(result, v));
        }
        public void SlerpNegatedSinglePrecision()
        {
            Quaternion q1    = new Quaternion(-1.0f, 0.0f, 0.0f, 0.0f);
            Quaternion q2    = Quaternion.CreateFromRotationMatrix(-Vector3.UnitZ, (float)-Math.PI / 2);
            Quaternion slerp = InterpolationHelper.Slerp(q1, q2, 0.5f);

            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Vector3 v      = slerp.Rotate(Vector3.UnitX);
            Vector3 result = new Vector3(1.0f, 1.0f, 0.0f).Normalized;

            Assert.IsTrue(Vector3.AreNumericallyEqual(result, v));
        }
        public void SlerpXDoublePrecision()
        {
            QuaternionD q1    = QuaternionD.Identity;
            QuaternionD q2    = QuaternionD.CreateRotation(Vector3.UnitX, Math.PI / 2);
            QuaternionD slerp = InterpolationHelper.Slerp(q1, q2, 0.5);

            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Vector3D v      = slerp.Rotate(Vector3.UnitY);
            Vector3D result = new Vector3D(0.0, 1.0, 1.0).Normalized;

            Assert.IsTrue(Vector3D.AreNumericallyEqual(result, v));
        }
        public void SlerpXSinglePrecision()
        {
            QuaternionF q1    = QuaternionF.Identity;
            QuaternionF q2    = QuaternionF.CreateRotation(Vector3F.UnitX, (float)Math.PI / 2);
            QuaternionF slerp = InterpolationHelper.Slerp(q1, q2, 0.5f);

            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Vector3F v      = slerp.Rotate(Vector3F.UnitY);
            Vector3F result = new Vector3F(0.0f, 1.0f, 1.0f).Normalized;

            Assert.IsTrue(Vector3F.AreNumericallyEqual(result, v));
        }
        public void SlerpDoublePrecision()
        {
            // Warning: The not all results are not verified
            QuaternionD q1    = new QuaternionD(1.0, 2.0, 3.0, 4.0).Normalized;
            QuaternionD q2    = new QuaternionD(2.0, 4.0, 6.0, 8.0).Normalized;
            QuaternionD slerp = InterpolationHelper.Slerp(q1, q2, 0.75);

            Assert.IsTrue(slerp.IsNumericallyNormalized);

            slerp = InterpolationHelper.Slerp(q1, q2, 0);
            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Assert.IsTrue(QuaternionD.AreNumericallyEqual(q1, slerp));

            slerp = InterpolationHelper.Slerp(q1, q2, 1);
            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Assert.IsTrue(QuaternionD.AreNumericallyEqual(q2, slerp));
        }
        public void SlerpSinglePrecision()
        {
            // Warning: The not all results are not verified
            Quaternion q1    = new Quaternion(1.0f, 2.0f, 3.0f, 4.0f).Normalized;
            Quaternion q2    = new Quaternion(2.0f, 4.0f, 6.0f, 8.0f).Normalized;
            Quaternion slerp = InterpolationHelper.Slerp(q1, q2, 0.75f);

            Assert.IsTrue(slerp.IsNumericallyNormalized);

            slerp = InterpolationHelper.Slerp(q1, q2, 0);
            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Assert.IsTrue(Quaternion.AreNumericallyEqual(q1, slerp));

            slerp = InterpolationHelper.Slerp(q1, q2, 1);
            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Assert.IsTrue(Quaternion.AreNumericallyEqual(q2, slerp));
        }
        public void SlerpGeneralDoublePrecision()
        {
            QuaternionD q1    = QuaternionD.CreateRotation(-Vector3D.UnitY, Math.PI / 2);
            QuaternionD q2    = QuaternionD.CreateRotation(Vector3D.UnitZ, Math.PI / 2);
            QuaternionD slerp = InterpolationHelper.Slerp(q1, q2, 0.5);

            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Vector3D v      = slerp.Rotate(Vector3D.UnitX);
            Vector3D result = new Vector3D(1.0 / 3.0, 2.0 / 3.0, 2.0 / 3.0); // I hope this is correct.

            Assert.IsTrue(Vector3D.AreNumericallyEqual(result, v));

            q1    = QuaternionD.CreateRotation(-Vector3D.UnitY, Math.PI / 2);
            q2    = QuaternionD.CreateRotation(-Vector3D.UnitZ, -Math.PI / 2);
            slerp = InterpolationHelper.Slerp(q1, q2, 0.5);
            Assert.IsTrue(slerp.IsNumericallyNormalized);
            v      = slerp.Rotate(Vector3D.UnitX);
            result = new Vector3D(1.0 / 3.0, 2.0 / 3.0, 2.0 / 3.0); // I hope this is correct.
            Assert.IsTrue(Vector3D.AreNumericallyEqual(result, v));
        }
        public void SlerpGeneralSinglePrecision()
        {
            Quaternion q1    = Quaternion.CreateFromRotationMatrix(-Vector3.UnitY, (float)Math.PI / 2);
            Quaternion q2    = Quaternion.CreateFromRotationMatrix(Vector3.UnitZ, (float)Math.PI / 2);
            Quaternion slerp = InterpolationHelper.Slerp(q1, q2, 0.5f);

            Assert.IsTrue(slerp.IsNumericallyNormalized);
            Vector3 v      = slerp.Rotate(Vector3.UnitX);
            Vector3 result = new Vector3(1.0f / 3.0f, 2.0f / 3.0f, 2.0f / 3.0f); // I hope this is correct.

            Assert.IsTrue(Vector3.AreNumericallyEqual(result, v));

            q1    = Quaternion.CreateFromRotationMatrix(-Vector3.UnitY, (float)Math.PI / 2);
            q2    = Quaternion.CreateFromRotationMatrix(-Vector3.UnitZ, (float)-Math.PI / 2);
            slerp = InterpolationHelper.Slerp(q1, q2, 0.5f);
            Assert.IsTrue(slerp.IsNumericallyNormalized);
            v      = slerp.Rotate(Vector3.UnitX);
            result = new Vector3(1.0f / 3.0f, 2.0f / 3.0f, 2.0f / 3.0f); // I hope this is correct.
            Assert.IsTrue(Vector3.AreNumericallyEqual(result, v));
        }
        public void SquadDoublePrecision()
        {
            QuaternionD q0 = QuaternionD.CreateRotation(new Vector3D(1, 1, 1), 0.3);
            QuaternionD q1 = QuaternionD.CreateRotation(new Vector3D(1, 0, 1), 0.4);
            QuaternionD q2 = QuaternionD.CreateRotation(new Vector3D(1, 0, -1), -0.6);
            QuaternionD q3 = QuaternionD.CreateRotation(new Vector3D(0, 1, 1), 0.2);

            QuaternionD q, a, b, p;
            QuaternionD expected;

            InterpolationHelper.SquadSetup(q0, q1, q2, q3, out q, out a, out b, out p);

            // t = 0
            QuaternionD result = InterpolationHelper.Squad(q, a, b, p, 0.0);

            Assert.IsTrue(QuaternionD.AreNumericallyEqual(q1, result));

            // t = 1.0f
            result = InterpolationHelper.Squad(q, a, b, p, 1.0);
            Assert.IsTrue(QuaternionD.AreNumericallyEqual(q2, result));

            // Check series (just for debugging)
            QuaternionD r1, r2, r3, r4, r5, r6, r7, r8, r9;

            r1 = InterpolationHelper.Squad(q, a, b, p, 0.1);
            r2 = InterpolationHelper.Squad(q, a, b, p, 0.2);
            r3 = InterpolationHelper.Squad(q, a, b, p, 0.3);
            r4 = InterpolationHelper.Squad(q, a, b, p, 0.4);
            r5 = InterpolationHelper.Squad(q, a, b, p, 0.5);
            r6 = InterpolationHelper.Squad(q, a, b, p, 0.6);
            r7 = InterpolationHelper.Squad(q, a, b, p, 0.7);
            r8 = InterpolationHelper.Squad(q, a, b, p, 0.8);
            r9 = InterpolationHelper.Squad(q, a, b, p, 0.9);

            // q0 = q1, q2 = q3
            InterpolationHelper.SquadSetup(q1, q1, q2, q2, out q, out a, out b, out p);
            result   = InterpolationHelper.Squad(q, a, b, p, 0.5);
            expected = InterpolationHelper.Slerp(q1, q2, 0.5);
            Assert.IsTrue(QuaternionD.AreNumericallyEqual(expected, result));
        }
        public void SquadSinglePrecision()
        {
            Quaternion q0 = Quaternion.CreateFromRotationMatrix(new Vector3(1, 1, 1), 0.3f);
            Quaternion q1 = Quaternion.CreateFromRotationMatrix(new Vector3(1, 0, 1), 0.4f);
            Quaternion q2 = Quaternion.CreateFromRotationMatrix(new Vector3(1, 0, -1), -0.6f);
            Quaternion q3 = Quaternion.CreateFromRotationMatrix(new Vector3(0, 1, 1), 0.2f);

            Quaternion q, a, b, p;
            Quaternion expected;

            InterpolationHelper.SquadSetup(q0, q1, q2, q3, out q, out a, out b, out p);

            // t = 0
            Quaternion result = InterpolationHelper.Squad(q, a, b, p, 0.0f);

            Assert.IsTrue(Quaternion.AreNumericallyEqual(q1, result));

            // t = 1.0f
            result = InterpolationHelper.Squad(q, a, b, p, 1.0f);
            Assert.IsTrue(Quaternion.AreNumericallyEqual(q2, result));

            // Check series (just for debugging)
            Quaternion r1, r2, r3, r4, r5, r6, r7, r8, r9;

            r1 = InterpolationHelper.Squad(q, a, b, p, 0.1f);
            r2 = InterpolationHelper.Squad(q, a, b, p, 0.2f);
            r3 = InterpolationHelper.Squad(q, a, b, p, 0.3f);
            r4 = InterpolationHelper.Squad(q, a, b, p, 0.4f);
            r5 = InterpolationHelper.Squad(q, a, b, p, 0.5f);
            r6 = InterpolationHelper.Squad(q, a, b, p, 0.6f);
            r7 = InterpolationHelper.Squad(q, a, b, p, 0.7f);
            r8 = InterpolationHelper.Squad(q, a, b, p, 0.8f);
            r9 = InterpolationHelper.Squad(q, a, b, p, 0.9f);

            // q0 = q1, q2 = q3
            InterpolationHelper.SquadSetup(q1, q1, q2, q2, out q, out a, out b, out p);
            result   = InterpolationHelper.Squad(q, a, b, p, 0.5f);
            expected = InterpolationHelper.Slerp(q1, q2, 0.5f);
            Assert.IsTrue(Quaternion.AreNumericallyEqual(expected, result));
        }