Esempio n. 1
0
        public void QuaternionDFromRotationMatrixTest5()
        {
            for (double angle = 0.0f; angle < 720.0f; angle += 10.0f)
            {
                Matrix4x4D matrix = Matrix4x4D.CreateRotationX(angle) * Matrix4x4D.CreateRotationY(angle) * Matrix4x4D.CreateRotationZ(angle);

                QuaternionD expected =
                    QuaternionD.CreateFromAxisAngle(Vector3D.UnitZ, angle) *
                    QuaternionD.CreateFromAxisAngle(Vector3D.UnitY, angle) *
                    QuaternionD.CreateFromAxisAngle(Vector3D.UnitX, angle);

                QuaternionD actual = QuaternionD.CreateFromRotationMatrix(matrix);
                Assert.True(MathHelper.EqualRotation(expected, actual),
                            $"QuaternionD.CreateFromRotationMatrix angle:{angle} did not return the expected value: expected {expected} actual {actual}");

                // make sure convert back to matrix is same as we passed matrix.
                Matrix4x4D m2 = Matrix4x4D.CreateFromQuaternion(actual);
                Assert.True(MathHelper.Equal(matrix, m2),
                            $"QuaternionD.CreateFromQuaternionD angle:{angle} did not return the expected value: matrix {matrix} m2 {m2}");
            }
        }