public void InverseWithNearSingularMatrix() { Matrix22F m = new Matrix22F(0.0001f, 0, 0, 0.0001f); Vector2F v = Vector2F.One; Vector2F w = m * v; Assert.IsTrue(Vector2F.AreNumericallyEqual(v, m.Inverse * w)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m * m.Inverse)); }
public void Inverse() { Assert.AreEqual(Matrix22F.Identity, Matrix22F.Identity.Inverse); Matrix22F m = new Matrix22F(1, 2, 3, 4); Vector2F v = Vector2F.One; Vector2F w = m * v; Assert.IsTrue(Vector2F.AreNumericallyEqual(v, m.Inverse * w)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, m * m.Inverse)); }
public void AreEqualWithEpsilon() { float epsilon = 0.001f; Matrix22F m0 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m1 += new Matrix22F(0.002f); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m2 += new Matrix22F(0.0001f); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m0, epsilon)); Assert.IsFalse(Matrix22F.AreNumericallyEqual(m0, m1, epsilon)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m2, epsilon)); }
public void AreEqual() { float originalEpsilon = Numeric.EpsilonF; Numeric.EpsilonF = 1e-8f; Matrix22F m0 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m1 += new Matrix22F(0.000001f); Matrix22F m2 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); m2 += new Matrix22F(0.00000001f); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m0)); Assert.IsFalse(Matrix22F.AreNumericallyEqual(m0, m1)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(m0, m2)); Numeric.EpsilonF = originalEpsilon; }
public void MultiplyMatrix() { Matrix22F m = new Matrix22F(12, 23, 45, 67); Assert.AreEqual(Matrix22F.Zero, Matrix22F.Multiply(m, Matrix22F.Zero)); Assert.AreEqual(Matrix22F.Zero, Matrix22F.Multiply(Matrix22F.Zero, m)); Assert.AreEqual(m, Matrix22F.Multiply(m, Matrix22F.Identity)); Assert.AreEqual(m, Matrix22F.Multiply(Matrix22F.Identity, m)); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, Matrix22F.Multiply(m, m.Inverse))); Assert.IsTrue(Matrix22F.AreNumericallyEqual(Matrix22F.Identity, Matrix22F.Multiply(m.Inverse, m))); Matrix22F m1 = new Matrix22F(columnMajor, MatrixOrder.ColumnMajor); Matrix22F m2 = new Matrix22F(12, 23, 45, 67); Matrix22F result = Matrix22F.Multiply(m1, m2); for (int column = 0; column < 2; column++) { for (int row = 0; row < 2; row++) { Assert.AreEqual(Vector2F.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); } } }