• Advertisement
Sign in to follow this  

Determinant of a 4x4 matrix help needed

This topic is 2344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there,

I'm working on a design document of a maths library for my future projects as part of hopefully a whole game engine. I'm having problems finding a decent documentation of working out the determinant of a 4x4 matrix before calculating the inverse of the matrix, I've found a few videos on YouTube that in some way helps but not from the perspective of calculating in code but rather on paper (I know that if we can calculate it on paper the coding is made a lot easier from our understanding of the calculation) but from one video that I found 'finding the determinant of a 4x4 matrix' I'm slightly confused by if this is the best method in perspective of coding (have it function search the column and row for any which have a larger zero count of elements before calculation the rest) as the video shows or if there is a better and simpler way to do this?

Thank you in advance
Dave

Share this post


Link to post
Share on other sites
Advertisement
If you have generic 4x4 matrix (not 3d transformations only, for example), then don't worry about zeroes when implementing determinant calculation on computer. Just take first row and use that to to construct four 3x3 submatrices. Searching for most zeroes in column or row is when you want calculate determinant on paper - it is easier because then you need to do less calculations.

Share this post


Link to post
Share on other sites
Thank you for your advice, much appreciated, will continue my research with your advice to hand. thank you again.
Dave

Share this post


Link to post
Share on other sites
Computing an NxN determinant by expanding a row or column and computing N determinants of size (N-1)x(N-1) will require O(N!) operations. You can obtain the determinant as a side-product of Gaussian elimination, which runs asymptotically much faster. However, N=4 might be small enough that the O(N!) algorithm is still faster.

Share this post


Link to post
Share on other sites
You almost certainly do not need a generic matrix inversion routine for game applications.

If you're inverting a well behaved 4x4 transformation matrix, decompose it into two matricies -- one containing the 3x3 rotation part padded out to 4x4. This is invertible by transposing it. The other matrix contains the translation component. This is also then easily inverted by transposing it.

Then multiply them back together in the reverse order.

This is much faster than the application of generic inversion.

Share this post


Link to post
Share on other sites

You almost certainly do not need a generic matrix inversion routine for game applications.

If you're inverting a well behaved 4x4 transformation matrix, decompose it into two matricies -- one containing the 3x3 rotation part padded out to 4x4. This is invertible by transposing it. The other matrix contains the translation component. This is also then easily inverted by transposing it.

Then multiply them back together in the reverse order.

This is much faster than the application of generic inversion.

This is what I am doing at now - but a word of warning:

Better enforce the invariant, that 3x3 rotation part of your matrix is orthonormal every time you store matrix for the usage in later frames/timesteps. You will be surprised, how fast calculating errors can accumulate and completely mess up your matrix if you are using multiplication + inversion by transposition.

Share this post


Link to post
Share on other sites

[...] but a word of warning:

Better enforce the invariant, that 3x3 rotation part of your matrix is orthonormal every time you store matrix for the usage in later frames/timesteps. You will be surprised, how fast calculating errors can accumulate and completely mess up your matrix if you are using multiplication + inversion by transposition.


I just wanted to mention that one of the advantages of using quaternions is that they are much simpler to normalize. Instead of transposition, you would use conjugation.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement