determinant method

double determinant (Float32List matrix, int offset)

Compute the determinant of the 4x4 matrix starting at offset.

Implementation

static double determinant(Float32List matrix, int offset) {
  final double m0 = matrix[0 + offset];
  final double m1 = matrix[1 + offset];
  final double m2 = matrix[2 + offset];
  final double m3 = matrix[3 + offset];
  final double m4 = matrix[4 + offset];
  final double m5 = matrix[5 + offset];
  final double m6 = matrix[6 + offset];
  final double m7 = matrix[7 + offset];

  final double det2_01_01 = m0 * m5 - m1 * m4;
  final double det2_01_02 = m0 * m6 - m2 * m4;
  final double det2_01_03 = m0 * m7 - m3 * m4;
  final double det2_01_12 = m1 * m6 - m2 * m5;
  final double det2_01_13 = m1 * m7 - m3 * m5;
  final double det2_01_23 = m2 * m7 - m3 * m6;

  final double m8 = matrix[8 + offset];
  final double m9 = matrix[9 + offset];
  final double m10 = matrix[10 + offset];
  final double m11 = matrix[11 + offset];

  final double det3_201_012 =
      m8 * det2_01_12 - m9 * det2_01_02 + m10 * det2_01_01;
  final double det3_201_013 =
      m8 * det2_01_13 - m9 * det2_01_03 + m11 * det2_01_01;
  final double det3_201_023 =
      m8 * det2_01_23 - m10 * det2_01_03 + m11 * det2_01_02;
  final double det3_201_123 =
      m9 * det2_01_23 - m10 * det2_01_13 + m11 * det2_01_12;

  final double m12 = matrix[12 + offset];
  final double m13 = matrix[13 + offset];
  final double m14 = matrix[14 + offset];
  final double m15 = matrix[15 + offset];

  return -det3_201_123 * m12 +
      det3_201_023 * m13 -
      det3_201_013 * m14 +
      det3_201_012 * m15;
}