示例#1
0
            public void Test(Random random, int innerIterations)
            {
                Quaternion q;

                q.X = (float)random.NextDouble() * 2 - 1;
                q.Y = (float)random.NextDouble() * 2 - 1;
                q.Z = (float)random.NextDouble() * 2 - 1;
                q.W = (float)random.NextDouble() * 2 - 1;

                Quaternion.NormalizeRef(ref q);

                for (int i = 0; i < innerIterations; ++i)
                {
                    Matrix3x3.CreateFromQuaternion(q, out var r);
                    Quaternion.CreateFromRotationMatrix(r, out var qTest);

#if DEBUG
                    const float epsilon = 1e-6f;
                    var         lengthX = r.X.Length();
                    var         lengthY = r.Y.Length();
                    var         lengthZ = r.Z.Length();
                    Debug.Assert(
                        Math.Abs(1 - lengthX) < epsilon &&
                        Math.Abs(1 - lengthY) < epsilon &&
                        Math.Abs(1 - lengthZ) < epsilon);


                    if (qTest.X * q.X < 0)
                    {
                        Quaternion.Negate(qTest, out qTest);
                    }
                    Debug.Assert(
                        Math.Abs(qTest.X - q.X) < epsilon &&
                        Math.Abs(qTest.Y - q.Y) < epsilon &&
                        Math.Abs(qTest.Z - q.Z) < epsilon &&
                        Math.Abs(qTest.W - q.W) < epsilon);
#endif
                }
            }