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_ZeroVector() { RotationMatrix m = new RotationMatrix(0, 0, 0, 0, 0, 0, 0, 0, 0); Assert.IsTrue(m.IsIdentity()); }