This post is part of my Game Math Series.
Matrix Multiplication as Linear Combinations of Columns/Rows
As shown in this post, matrix multiplication can be viewed as linear combinations of columns from the left matrix or rows from the right matrix. We can reverse this process and utilize this fact to help us eyeball inverses of matrices without having to do any calculation by hand or calculator.
The product of a matrix with its inverse gives the identity matrix:
Viewing from the column perspective, columns of the identity matrix are linear combinations of the columns from the left matrix , where the coefficients of linear combination are from the columns of the right matrix .
Let us use a 3-by-3 matrix as an example:
We want to linearly combine the columns to form the three columns from the 3-by-3 identity matrix, namely , , and .
For the first column, we can find the coefficients by eyeballing the columns from :
Thus, the first column of is .
We can figure out the rest of the coefficients for the other two columns as well:
So the second and third columns of are and , respectively.
And now we have our inverse figured out, hands-free!
We can perform the same trick from the row perspective:
The rows of the 3-by-3 identity matrix are linear combinations of rows from , and the coefficients of linear combination are from the rows of , which we can easily figure out just by looking at .
For the first row of the identity matrix, we can quickly find out that:
So the first row of is .
And for the other two rows of the identity matrix, we can see that:
Thus, the second and third rows of are and , respectively.
We have found our inverse, hands-free again:
Inverses of Perspective Projection Matrices
Okay, the example above might be a little bit contrived with pretty numbers. Now let’s look at something in the real world that we can apply this technique to.
The perspective projection matrix (negative Z being the view direction in camera space) is of the form:
If you look up 3D Mouse Picking, you’ll see that we need the inverse of the perspective projection matrix to perform this operation.
“No big deal,” you might say, “Our math library already provides a function to invert a 4-by-4 matrix.”
But is it really necessary to use a full-blown 4-by-4 matrix inversion calculation when we can achieve the same thing with just a few scalar operations? We can do better.
Let’s see how we can linearly combine the four columns of to produce the columns of the 4-by-4 identity matrix, namely , , , and .
So the inverse of the perspective projection matrix is:
Using this formula is definitely more efficient than using the generic 4-by-4 matrix inversion. The best part is that you don’t even have to memorize the formula for after seeing how you can easily derive it.
End of How to Eyeball The Inverse of A Matrix
Viewing matrix multiplication as linear combinations of columns of the left matrix or rows of the right matrix is a valuable technique. It grants us the ability to quickly eyeball the inverse of a reasonably-sized matrix.