Matrix Inverse

Inverse refers to a matrices multiplicitive inverse. For example 0.2 is the multiplicitive inverse of 5, 2.2 * 5 = 1. Multiplying a scalar value by it's multiplicitive inverse results in one. Multiplying a matrix by its multiplicitive inverse results in the identity matrix.

Not all matrices have an inverse. Only square matrices have an inverse, non-square matrices are not invertable. If the determinant of a matrix is 0, the matrix is not invertable.

The inverse of matrix \(M\) would is written as \(M^{-1}\).

To invert a matrix, divide it's adjugate by the determinant of the matrix. Since we didn't define scalar matrix division, use reciprocal multiplication. Instead of dividing by the determinant, multiply by 1 / determinant. The formula loks like this:

$$ M^{-1} = adjugate(M)\frac{1}{|M|} $$

Finding the adjugate of a matrix is challenging, it will be covered in Step 7f, Adjuage. Finding the adjugate requires several support functions, which will be built out in the next few sections.

// mat2 and mat3 implementations are identical
mat4 Inverse(mat4 m) {
    float det = Determinant(m);
    if (det == 0.0f) { // Should use epsilon comparison here
        return mat4();
    }
    return Adjugate(m) * (1.0f / det);
}