public void RotationMatrix_OrthogonalOnCreation_RandomVectors()
        {
            RotationMatrix m;
            Vector         vecX, vecY;
            Vector         mVecX, mVecY, mVecZ;
            int            dir;

            for (var i = 0; i < 50; i++)
            {
                vecX = Vector.RandomFromDoubles(-100, 100);
                vecY = Vector.RandomFromDoubles(-100, 100);
                m    = new RotationMatrix(vecX, vecY);

                Trace.WriteLine("");
                Trace.WriteLine(vecX + " " + vecY);
                Trace.WriteLine(m);
                Assert.IsTrue(m.IsOrthogonal(), "RotationMatrix isn't orthogonal");

                mVecX = new Vector(m.m00, m.m10, m.m20);
                Assert.IsTrue(Vector.CompareDirections(vecX, mVecX) == 1, "Original VectorX and orthogonalized one are not parallel");
            }

            for (var i = 0; i < 100; i++)
            {
                vecX = Vector.RandomFromInts(-1, 1);
                vecY = Vector.RandomFromInts(-1, 1);
                dir  = Vector.CompareDirections(vecX, vecY);

                m = new RotationMatrix(vecX, vecY);

                Trace.WriteLine("");
                Trace.WriteLine(vecX + " " + vecY + " dir:" + dir);
                Trace.WriteLine(m);

                if (dir == 1 || dir == 3)
                {
                    Assert.IsTrue(m.IsIdentity(), "Parallel vectors should yield an identity matrix");
                }
                else
                {
                    Assert.IsTrue(m.IsOrthogonal(), "RotationMatrix isn't orthogonal");

                    mVecX = new Vector(m.m00, m.m10, m.m20);
                    Assert.IsTrue(Vector.CompareDirections(vecX, mVecX) == 1, "Original VectorX and orthogonalized X should be parallel");

                    mVecY = new Vector(m.m01, m.m11, m.m21);
                    Assert.IsTrue(Vector.CompareDirections(vecX, mVecY) == 2, "Original VectorX and orthogonalized Y should be perpendicular");

                    mVecZ = new Vector(m.m02, m.m12, m.m22);
                    Assert.IsTrue(Vector.CompareDirections(vecX, mVecZ) == 2, "Original VectorX and orthogonalized Z should be perpendicular");

                    Assert.IsTrue(Vector.CompareDirections(mVecX, mVecY) == 2);
                    Assert.IsTrue(Vector.CompareDirections(mVecX, mVecZ) == 2);
                    Assert.IsTrue(Vector.CompareDirections(mVecY, mVecZ) == 2);
                }
            }
        }
        public void RotationMatrix_OrthogonalOnCreation_RandomValues()
        {
            RotationMatrix m;

            double[] r = new double[9];

            for (var i = 0; i < 50; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    r[j] = Random(-100, 100);
                }

                m = new RotationMatrix(r);

                Trace.WriteLine("");
                for (int j = 0; j < 9; j++)
                {
                    Trace.Write(r[j] + " ");
                }
                Trace.WriteLine("");
                Trace.WriteLine(m);
                Assert.IsTrue(m.IsOrthogonal(), "RotationMatrix isn't orthogonal");
            }

            for (var i = 0; i < 50; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    r[j] = RandomInt(-1, 1);
                }

                m = new RotationMatrix(r);

                Trace.WriteLine("");
                for (int j = 0; j < 9; j++)
                {
                    Trace.Write(r[j] + " ");
                }
                Trace.WriteLine("");
                Trace.WriteLine(m);
                Assert.IsTrue(m.IsOrthogonal(), "RotationMatrix isn't orthogonal");
            }
        }