Determinant of a 4x4 matrix help needed

Started by
6 comments, last by alvaro 12 years, 7 months ago
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
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.
Thank you for your advice, much appreciated, will continue my research with your advice to hand. thank you again.
Dave
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.
determinant of 4x4
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.

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.
Lauris Kaplinski

First technology demo of my game Shinya is out: http://lauris.kaplinski.com/shinya
Khayyam 3D - a freeware poser and scene builder application: http://khayyam.kaplinski.com/

[...] 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.

This topic is closed to new replies.

Advertisement