Example #1
0
 public static Matrix3 operator *(Matrix3 matrixA, float scale) {
     Matrix3 result = new Matrix3();
     for (int i = 0; i < 3; i++) {
         for (int j = 0; j < 3; j++) {
             result[i, j] = matrixA[i, j] * scale;
         }
     }
     return result;
 }
Example #2
0
 //Matrix multiplication
 public static Matrix3 operator *(Matrix3 matrixA,Matrix3 matrixB) {
     Matrix3 result = new Matrix3();
     result[0, 0] = matrixA[0, 0] * matrixB[0, 0] + matrixA[0, 1] * matrixB[1, 0] + matrixA[0, 2] * matrixB[2, 0];
     result[0, 1] = matrixA[0, 0] * matrixB[0, 1] + matrixA[0, 1] * matrixB[1, 1] + matrixA[0, 2] * matrixB[2, 1];
     result[0, 2] = matrixA[0, 0] * matrixB[0, 2] + matrixA[0, 1] * matrixB[1, 2] + matrixA[0, 2] * matrixB[2, 2];
     result[1, 0] = matrixA[1, 0] * matrixB[0, 0] + matrixA[1, 1] * matrixB[1, 0] + matrixA[1, 2] * matrixB[2, 0];
     result[1, 1] = matrixA[1, 0] * matrixB[0, 1] + matrixA[1, 1] * matrixB[1, 1] + matrixA[1, 2] * matrixB[2, 1];
     result[1, 2] = matrixA[1, 0] * matrixB[0, 2] + matrixA[1, 1] * matrixB[1, 2] + matrixA[1, 2] * matrixB[2, 2];
     result[2, 0] = matrixA[2, 0] * matrixB[0, 0] + matrixA[2, 1] * matrixB[1, 0] + matrixA[2, 2] * matrixB[2, 0];
     result[2, 1] = matrixA[2, 0] * matrixB[0, 1] + matrixA[2, 1] * matrixB[1, 1] + matrixA[2, 2] * matrixB[2, 1];
     result[2, 2] = matrixA[2, 0] * matrixB[0, 2] + matrixA[2, 1] * matrixB[1, 2] + matrixA[2, 2] * matrixB[2, 2];
     return result;
 }
Example #3
0
 public static Matrix3 ZRotation(float theta) {
     theta = theta * (float)(Math.PI / 180);
     Matrix3 result = new Matrix3((float)Math.Cos(theta), -(float)Math.Sin(theta), 0,
                                  (float)Math.Sin(theta), (float)Math.Cos(theta), 0,
                                  0, 0, 1);
     return result;
 }
Example #4
0
 //Inverse
 public static Matrix3 Inverse(Matrix3 matrix) {
     Matrix3 result = Adjugate(matrix);
     float determinant = Determinant(matrix);
     result *= 1.0f/determinant;
     return result;
 }
Example #5
0
 public static Matrix3 XRotation(float theta) {
     theta = theta * (float)(Math.PI / 180); //convert to rads
     Matrix3 result = new Matrix3(1, 0, 0,
                                  0, (float)Math.Cos(theta), -(float)Math.Sin(theta),
                                  0, (float)Math.Sin(theta), (float)Math.Cos(theta));
     return result;
 }
Example #6
0
 //adjugate
 public static Matrix3 Adjugate(Matrix3 matrix) {
     Matrix3 result = new Matrix3();
     result = Matrix3.Transpose(CoFactor(matrix));
     return result;
 }
Example #7
0
 //cofactor
 public static Matrix3 CoFactor(Matrix3 matrix) {
     Matrix3 result = new Matrix3();
     result[0, 0] = (matrix[1, 1] * matrix[2, 2] - matrix[1, 2] * matrix[2, 1]) * 1;
     result[0, 1] = (matrix[1, 0] * matrix[2, 2] - matrix[1, 2] * matrix[2, 0]) * -1;
     result[0, 2] = (matrix[1, 0] * matrix[2, 1] - matrix[1, 1] * matrix[2, 0]) * 1;
     result[1, 0] = (matrix[0, 1] * matrix[2, 2] - matrix[0, 2] * matrix[2, 1]) * -1;
     result[1, 1] = (matrix[0, 0] * matrix[2, 2] - matrix[0, 2] * matrix[2, 0]) * 1;
     result[1, 2] = (matrix[0, 0] * matrix[2, 1] - matrix[0, 1] * matrix[2, 0]) * -1;
     result[2, 0] = (matrix[0, 1] * matrix[1, 2] - matrix[0, 2] * matrix[1, 1]) * 1;
     result[2, 1] = (matrix[0, 0] * matrix[1, 2] - matrix[0, 2] * matrix[1, 0]) * -1;
     result[2, 2] = (matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0]) * 1;
     return result;
 }
Example #8
0
 //Minor
 public static Matrix3 Minor(Matrix3 matrix) {
     Matrix3 result = new Matrix3();
     result[0, 0] = matrix[1, 1] * matrix[2, 2] - matrix[1, 2] * matrix[2, 1];
     result[0, 1] = matrix[1, 0] * matrix[2, 2] - matrix[1, 2] * matrix[2, 0];
     result[0, 2] = matrix[1, 0] * matrix[2, 1] - matrix[1, 1] * matrix[2, 0];
     result[1, 0] = matrix[0, 1] * matrix[2, 2] - matrix[0, 2] * matrix[2, 1];
     result[1, 1] = matrix[0, 0] * matrix[2, 2] - matrix[0, 2] * matrix[2, 0];
     result[1, 2] = matrix[0, 0] * matrix[2, 1] - matrix[0, 1] * matrix[2, 0];
     result[2, 0] = matrix[0, 1] * matrix[1, 2] - matrix[0, 2] * matrix[1, 1];
     result[2, 1] = matrix[0, 0] * matrix[1, 2] - matrix[0, 2] * matrix[1, 0];
     result[2, 2] = matrix[0, 0] * matrix[1, 1] - matrix[0, 1] * matrix[1, 0];
     return result;
 }
Example #9
0
 //Determinant
 public static float Determinant(Matrix3 matrix) {
     return (matrix[0, 0] * (matrix[1, 1] * matrix[2, 2] - matrix[1, 2] * matrix[2, 1]))
          - (matrix[0, 1] * (matrix[1, 0] * matrix[2, 2] - matrix[1, 2] * matrix[2, 0]))
          + (matrix[0, 2] * (matrix[1, 0] * matrix[2, 1] - matrix[1, 1] * matrix[2, 0]));
 }
Example #10
0
 //Transpose, row = col, col = row
 public static Matrix3 Transpose(Matrix3 matrix) {
     Matrix3 result = new Matrix3();
     for (int i = 0; i < 3; i++) {
         for (int j = 0; j < 3; j++) {
             result[i, j] = matrix[j, i];
         }
     }
     return result;
 }