This post explains an easy and efficient way to implement the inverse of a 3x3 matrix. It’s based on vector operations like previous posts.

Given a 3x3 matrix:

We construct the following three vectors, one for each row of the matrix:

The inverse of the matrix is:

The expression is the determinant of like explained in a previous post. If the determinant is zero, then the matrix has no inverse. Note that the expression appears two times, so it only needs to be calculated once.


float inverse(Matrix3x3 m)
	vec3 v1 = m.row(0);
	vec3 v2 = m.row(1);
	vec3 v3 = m.row(2);

	vec3 col1 = cross(v2, v3);

	float det = dot(v1, col1);
	if(det == 0) error();

	vec3 col2 = cross(v3, v1);
	vec3 col3 = cross(v1, v2);

	return Matrix3x3(col1, col2, col3)/det;