2x2 Determinant

The determinant of matrix \(M\) is commonly denoted as \(det(M)\), \(det M\) or \(|M|\). In practice, the absolute value of the determinant gives the scale factor by which the matrix will scale a volume. This definition is not really used in games, for games the determinant is a helper function to find the inverse of a matrix.

The determinant of a matrix is the same as the determinant of its transpose, \(|M| = |M^{T}|\). Similarly, the determinant of the inverse of a matrix is the same as the inverse of it's determinant: \(|M^{-1}| = \frac{1}{|M|}\)

Finding the determinant of a matrix is actually a recursive operation. Before learning about the recursive nature of the operation, let's explore the determinant of our smallest square matrix, a 2x2 matrix. Consider this 2x2 matrix:

$$ M = \begin{bmatrix} a & c\\ b & d \end{bmatrix} $$

To find the determinant of the above matrix, you need to multiply diagonal elements and subtract the result. For example, the determinant of the above matrix would be a * d - c * b. A simple way to express this is:

$$ |M| = | \begin{bmatrix} a & c\\ b & d \end{bmatrix} | = ad - cb $$

float Determinant(mat2 m) {
    return m.v[0] * m.v[3] - m.v[2] * m.v[1];
}