The adjugate of any order matrix is the transpose of its cofactor matrix. The adjugate is sometimes referred to as adjoint:
We already know how to take the cofactor of a matrix and how to transpose the matrix. Implementing the adjugate function is as easy as calling our existing cofactor and transpose functions.
Follow these steps to implement functions which return the adjugate matrix of two, three and four dimensional square matrices:
Add the declaration for adjugate for all three matrices to
matrices.h
:mat2 Adjugate(const mat2& mat); mat3 Adjugate(const mat3& mat); mat4 Adjugate(const mat4& mat);
Implement all three of the adjugate functions in
matrices.cpp
:mat2 Adjugate(const mat2& mat) { return Transpose(Cofactor(mat)); } mat3 Adjugate(const mat3& mat) { return Transpose(Cofactor(mat)); } mat4 Adjugate(const mat4& mat) { return Transpose(Cofactor(mat)); }