Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Bobby-D

Matrix Inversion

This topic is 5330 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

Can anyone tell me where I can find help on the maths behind a function for Inverting a 4x4 Matrix? I need to make a function to invert a matrix, but I don''t know how. Thanks. One by one, the peguins steal my sanity.

Share this post


Link to post
Share on other sites
Advertisement
first transpose the matrix( rows become the columns )
then divide every element by the determinant of the original matrix.

i''m not sure how to go about coding it but that should help get you started.

i got this off the net somewhere, but it was a couple months ago sorry i can''t give you an address.

Share this post


Link to post
Share on other sites
Almost, you need to calculate the cofactor for each position of the transposed matrix, and divide that by the determinant.
The cofactor of position i,j is the determinant of the 3x3 matrix obtained by removing row i and column j from the original 4x4.

Share this post


Link to post
Share on other sites
Most computer implementations would use elemtary row operations, rather than calculating cofactors, for finding the inverse of a matrix. This is much less computationally expensive, especially on big matrices.

Share this post


Link to post
Share on other sites
quote:
Original post by sjelkjd
Almost, you need to calculate the cofactor for each position of the transposed matrix, and divide that by the determinant.
The cofactor of position i,j is the determinant of the 3x3 matrix obtained by removing row i and column j from the original 4x4.



Almost, you multiply the cofactor by (-1) to the power of (i+j).

This is called the adjoint of a matrix.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Share this post


Link to post
Share on other sites
quote:
Original post by Bobby-D
Can anyone tell me where I can find help on the maths behind a function for Inverting a 4x4 Matrix? I need to make a function to invert a matrix, but I don't know how. Thanks.



If your 4x4 matrix is a combination of a 3x3 matrix M and a 3 vector V:

T = | M V |
| 0 1 |

(hope the terminology makes sense...)

then

T_inv = | M_inv (-M_inv * V) |
| 0 1 |

And if the 3x3 matrix is just a rotation matrix, then M_inv = transpose(M), which makes things very simple indeed.





[edited by - MrRowl on January 14, 2004 10:10:32 AM]

Share this post


Link to post
Share on other sites
If you actually want to code a matrix inversion function and understand why it works, I''d recomend checking out the matrix algebra section at SOS Math. It covers gaussian elimination (which can be used to invert a matrix), and personally I found it to be explained in a very clear manner, so when I actually wrote my matrix inverse function I knew what it was actually doing.

Share this post


Link to post
Share on other sites
Knowing Gaussian elimination is helpful for understanding matrix inversion, but I would only recommend it for large matrices. I''d use the

inv (M) = ( 1/det (M) ) adjoint (M)

method for 3x3 or 4x4 matrices.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Share this post


Link to post
Share on other sites
quote:
Original post by Paradigm Shifter
quote:
Original post by sjelkjd
Almost, you need to calculate the cofactor for each position of the transposed matrix, and divide that by the determinant.
The cofactor of position i,j is the determinant of the 3x3 matrix obtained by removing row i and column j from the original 4x4.



Almost, you multiply the cofactor by (-1) to the power of (i+j).

This is called the adjoint of a matrix.


"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley


This method is known as Cramer''s rule. It happens to be EXTREMELY expensive as the matrix gets larger. NOT recommended in practice for large matrices. See the interesting tables in the link below. A computer with teraflops of computing power would require 4 *YEARS* to compute the inverse of a 20x20 matrix using Cramer''s rule!

http://www2.math.uic.edu/~hanson/mcs471/cramers.html

Fortunately, for very small matrices, its not much different from Gaussian Elimination or other methods. As Paradigm Shifter pointed out, the technique is quite fine and good for 3x3 or 4x4 matrices.

Note that for transformation matrices, there are smarter ways.



Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!