public void GetRow() { Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor); Assert.AreEqual(new Vector3D(1.0, 2.0, 3.0), m.GetRow(0)); Assert.AreEqual(new Vector3D(4.0, 5.0, 6.0), m.GetRow(1)); Assert.AreEqual(new Vector3D(7.0, 8.0, 9.0), m.GetRow(2)); }
public void MultiplyMatrix() { Matrix33D m = new Matrix33D(12, 23, 45, 67, 89, 90, 43, 65, 87); Assert.AreEqual(Matrix33D.Zero, Matrix33D.Multiply(m, Matrix33D.Zero)); Assert.AreEqual(Matrix33D.Zero, Matrix33D.Multiply(Matrix33D.Zero, m)); Assert.AreEqual(m, Matrix33D.Multiply(m, Matrix33D.Identity)); Assert.AreEqual(m, Matrix33D.Multiply(Matrix33D.Identity, m)); Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, Matrix33D.Multiply(m, m.Inverse))); Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, Matrix33D.Multiply(m.Inverse, m))); Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor); Matrix33D m2 = new Matrix33D(12, 23, 45, 67, 89, 90, 43, 65, 87); Matrix33D result = Matrix33D.Multiply(m1, m2); for (int column = 0; column < 3; column++) { for (int row = 0; row < 3; row++) { Assert.AreEqual(Vector3D.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); } } }
public void SetRow() { Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor); m.SetRow(0, new Vector3D(0.1, 0.2, 0.3)); Assert.AreEqual(new Vector3D(0.1, 0.2, 0.3), m.GetRow(0)); Assert.AreEqual(new Vector3D(4.0, 5.0, 6.0), m.GetRow(1)); Assert.AreEqual(new Vector3D(7.0, 8.0, 9.0), m.GetRow(2)); m.SetRow(1, new Vector3D(0.4, 0.5, 0.6)); Assert.AreEqual(new Vector3D(0.1, 0.2, 0.3), m.GetRow(0)); Assert.AreEqual(new Vector3D(0.4, 0.5, 0.6), m.GetRow(1)); Assert.AreEqual(new Vector3D(7.0, 8.0, 9.0), m.GetRow(2)); m.SetRow(2, new Vector3D(0.7, 0.8, 0.9)); Assert.AreEqual(new Vector3D(0.1, 0.2, 0.3), m.GetRow(0)); Assert.AreEqual(new Vector3D(0.4, 0.5, 0.6), m.GetRow(1)); Assert.AreEqual(new Vector3D(0.7, 0.8, 0.9), m.GetRow(2)); }
public void MultiplyVector() { Vector3D v = new Vector3D(2.34, 3.45, 4.56); Assert.AreEqual(v, Matrix33D.Multiply(Matrix33D.Identity, v)); Assert.AreEqual(Vector3D.Zero, Matrix33D.Multiply(Matrix33D.Zero, v)); Matrix33D m = new Matrix33D(12, 23, 45, 67, 89, 90, 43, 65, 87); Assert.IsTrue(Vector3D.AreNumericallyEqual(v, Matrix33D.Multiply(m * m.Inverse, v))); for (int i = 0; i < 3; i++) Assert.AreEqual(Vector3D.Dot(m.GetRow(i), v), Matrix33D.Multiply(m, v)[i]); }
public void GetRowException2() { Matrix33D m = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor); m.GetRow(3); }
public void MultiplyVectorOperator() { Vector3D v = new Vector3D(2.34, 3.45, 4.56); Assert.AreEqual(v, Matrix33D.Identity * v); Assert.AreEqual(Vector3D.Zero, Matrix33D.Zero * v); Matrix33D m = new Matrix33D(12, 23, 45, 67, 89, 90, 43, 65, 87); Assert.IsTrue(Vector3D.AreNumericallyEqual(v, m * m.Inverse * v)); for (int i = 0; i < 3; i++) Assert.AreEqual(Vector3D.Dot(m.GetRow(i), v), (m * v)[i]); }
public void MultiplyMatrixOperator() { Matrix33D m = new Matrix33D(12, 23, 45, 67, 89, 90, 43, 65, 87); Assert.AreEqual(Matrix33D.Zero, m * Matrix33D.Zero); Assert.AreEqual(Matrix33D.Zero, Matrix33D.Zero * m); Assert.AreEqual(m, m * Matrix33D.Identity); Assert.AreEqual(m, Matrix33D.Identity * m); Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m * m.Inverse)); Assert.IsTrue(Matrix33D.AreNumericallyEqual(Matrix33D.Identity, m.Inverse * m)); Matrix33D m1 = new Matrix33D(columnMajor, MatrixOrder.ColumnMajor); Matrix33D m2 = new Matrix33D(12, 23, 45, 67, 89, 90, 43, 65, 87); Matrix33D result = m1 * m2; for (int column = 0; column < 3; column++) for (int row = 0; row < 3; row++) Assert.AreEqual(Vector3D.Dot(m1.GetRow(row), m2.GetColumn(column)), result[row, column]); }