public Vector2 Mult(Matrix2 matrix) { return new Vector2( tuple[0] * matrix.entry[0] + tuple[1] * matrix.entry[2], tuple[0] * matrix.entry[1] + tuple[1] * matrix.entry[3]); }
public Matrix2 Transpose() { Matrix2 result = new Matrix2(); for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) result.entry[I(i, j)] = entry[I(j, i)]; return result; }
public Matrix2 TransposeTimes(Matrix2 matrix) { // P = A^T*B, P[r][c] = sum_m A[m][r]*B[m][c] Matrix2 result = new Matrix2(); for (int row = 0; row < 2; row++) { for (int col = 0; col < 2; col++) { int i = I(row, col); result.entry[i] = 0; for (int mid = 0; mid < 2; mid++) result.entry[i] += entry[I(mid, row)] * matrix.entry[I(mid, col)]; } } return result; }
public Matrix2 Sub(Matrix2 matrix) { Matrix2 result = new Matrix2(); for (int i = 0; i < 4; i++) result.entry[i] = entry[i] - matrix.entry[i]; return result; }
public Matrix2 TimesTranspose(Matrix2 matrix) { // P = A*B^T, P[r][c] = sum_m A[r][m]*B[c][m] Matrix2 result = new Matrix2(); for (int row = 0; row < 2; row++) { for (int col = 0; col < 2; col++) { int i = I(row, col); result.entry[i] = 0; for (int mid = 0; mid < 2; mid++) result.entry[i] += entry[I(row, mid)] * matrix.entry[I(col, mid)]; } } return result; }
public Matrix2 Negative() { Matrix2 result = new Matrix2(); for (int i = 0; i < 4; i++) result.entry[i] = -entry[i]; return result; }
public Matrix2 Mult(double scalar) { Matrix2 result = new Matrix2(); for (int i = 0; i < 4; i++) result.entry[i] = entry[i] * scalar; return result; }
public Matrix2 Mult(Matrix2 matrix) { Matrix2 result = new Matrix2(); for (int row = 0; row < 2; row++) { for (int col = 0; col < 2; col++) { int i = I(row, col); result.entry[i] = 0; for (int mid = 0; mid < 2; mid++) result.entry[i] += entry[I(row, mid)] * matrix.entry[I(mid, col)]; } } return result; }
public Matrix2 Inverse() { double det = Determinant(); if (System.Math.Abs(det) > 0) { Matrix2 result = new Matrix2(); double invDet = 1 / det; result.entry[I(0, 0)] = entry[3] * invDet; result.entry[I(0, 1)] = -entry[1] * invDet; result.entry[I(1, 0)] = -entry[2] * invDet; result.entry[I(1, 1)] = entry[0] * invDet; return result; } else return Matrix2.Zero; }
public Matrix2 Div(double scalar) { Matrix2 result = new Matrix2(); if (scalar != 0.0) { double invScalar = 1 / scalar; for (int i = 0; i < 4; i++) result.entry[i] = invScalar * entry[i]; } else for (int i = 0; i < 4; i++) result.entry[i] = double.MaxValue; return result; }