View Full Version : Maths Formula for matrix needed!!!

Hi!

This question has nothing to do with OpenGL but since I can't think of a better discussion forum, pls help me!!

do u have a formula to get the inverse of an affine matrix(4x4 matrix)?? I have searched many websites but to no avail.

Thanks a lot!!

Divide Overflow

09-06-2000, 09:16 PM

Isn't that just multiplying with

[-1 0 0 0]

[ 0 -1 0 0]

[ 0 0 -1 0]

[ 0 0 0 -1]

Has been a year or 2 since I last did matrix maths, hope it helps !

--> Divide "I'm a bug, not a feature!"

Hi Divide Overflow,

I'm afraid it is not correct since it only inverts the sign of the matrix. Anyway, thanks for ur help!! Appreciated!!

ngill

09-06-2000, 09:55 PM

dude... it's all over the place!

it needs a couple of division and stuff... too lazy to look it up... just look up matrix inverse on www.google.com (http://www.google.com) or something..

Relic

09-06-2000, 10:56 PM

Hi Nicole, download the graphics gems from the link in my last post of this thread: http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/000959.html

PeterParker

09-07-2000, 06:25 AM

Hi Nicole..

If you do not use scaling or non uniform transformations, and if your matrix is an orthogonal base..you can just use the transposed Matrix to get the inverse.

I do not know for sure, but I use this method in my own engine for Camera-Transformations and there it works best..

Greets, Peter

[This message has been edited by PeterParker (edited 09-07-2000).]

Aster

09-07-2000, 10:43 AM

Hi, I hope this answers your question.

To find an inverse of any square matrix, you can append an identity matrix to the right of your matrix.

Your original matrix:

[5 4 2 4]

[2 3 5 9] = A

[1 0 7 2]

[4 6 2 3]

Changed matrix:

[5 4 2 4 | 1 0 0 0]

[2 3 5 9 | 0 1 0 0] = A | I

[1 0 7 2 | 0 0 1 0]

[4 6 2 3 | 0 0 0 1]

Then, row-reduce the the big matrix to get an identity matrix on the left. After that, the transformed matrix on the right side is the inverse of the original matrix.

Note, matrix has an inverse only if its determinant is non-zero,

|A| not= 0.

This method is based on the obvious fact that if you multiply a matrix by its inverse, you get an identity matrix.

I haven't done that myself, but I think that it's not that hard to find an algorithm for this procedure.

P.S. If you want to know how to find the determinant of a matrix, post a message.

[This message has been edited by Aster (edited 09-07-2000).]

Hi! Thanks all of ya!

PeterParker, do u mean that if my 4x4 matrix contains only translation n rotation, then the transposed Matrix is the inverse Matrix?is an orthogonal base matrix normalised?

Aster, I already have the algorithm to obtain the inverse of a general matrix which works exactly like what u said. However, i still need to find the formulas to get the inverse of an affine matrix, the inverse of an orthogonal matrix and the inverse of an orthonormal matrix.

Relic, there's an algorithm to get the inverse of a 4x4 affine matrix. But I'm confused, that algorithm defined affine matrix as one with the right column [0 0 0 1]. From what I know, affine matrix contains translation which affects the values in the right column, I thought that affine matrix should be one with the last row [0 0 0 1], which is correct then?

regards,

Nicole

If you want to get this involved and you're running on an Intel-based platform, I'm pretty sure that the Intel Math Kernel Library contains functions for matrix inversion (they implement a subset of BLAS and LAPACK, if you're familiar with them). It's kind of a steep learning curve initially, but all of the functions in the MKL are optimized like crazy and run very fast. I regularly use these in my research projects with good results.

More info & download: http://support.intel.com/support/performancetools/libraries/mkl/index.htm

While looking for that link, I also came across the Intel Small Matrix Library (SML), which says it contains optimized routines for 4x4 matrix inversion. I've never used it, but it looks like it might be good.

Link: http://support.intel.com/design/PentiumIII/sml/

Of course, if you're not developing on an Intel platform, I just wasted a bunch of typing http://www.opengl.org/discussion_boards/ubb/smile.gif

Relic

09-08-2000, 04:08 AM

Originally posted by Nicole:

Relic, there's an algorithm to get the inverse of a 4x4 affine matrix. But I'm confused, that algorithm defined affine matrix as one with the right column [0 0 0 1]. From what I know, affine matrix contains translation which affects the values in the right column, I thought that affine matrix should be one with the last row [0 0 0 1], which is correct then?

Haven't looked at the algorithm recently. The position of the translation components in the matrix depends on the layout of the vector (row or column vector).

OpenGL uses column vectors so the matrices are applied from the left side (v'=M*v), means the translation is in the last column of the matrix.

Right multiplied matrices (v'=v^T*M) are transposed, so the translation is in the bottom row.

Hope that helps.

Just one thing. There is not always an inverse to an Affine Matrix (assuming by affine matrix you mean a matrix defining an affine transformation). I know that these 4x4 matrices are in homogeneous coordinates, so transformations don't jsut imply multiplying by the matrices, cause I believe you have to divide by the final v, in the (x, y, z, v) 4tuple created to represent the coordinate, which is nothing but (x/v, y/v, z/v). The reson why there is not always an inverse, is because for degenerate transformations (Affine transformations which when expressed in 3x3 matrices have a determinant of 0), these transformations caanot be reversed, because they map a worl into a lower dimmensional space. By this I mean that, for example, 3D space would collapse into a plane, a line or a point. If this were to happen, then part of the original information contained in the previous transformations would be lost, and a reverse transformation could not be calculated. However, there is a technique to attempt to do so, using what is called singular value decomposition (to calculate the pseudo-inverse of a matrix). This will give the solution which will "reverse" the previous affine transform, but it is more of a pseudo inversive process. I believe with this method, the point closest to the origin that still maintains the other properties (the properties that were not lost with the degenerate transform) will be found.

That was my bunch of math babbling. The bottom line is, not all affine transformations can be inverted, so watch out. However, all affine matrices can be pseudo-inverted. The method for doing so is discussed in GOOD books on Linear Algebra. Most introductory College texts for this topic do not include such information, but I believe there are plenty of web pages with SVD algorithms.

Hi all!

Thanks for all the help u all have given me, especially to Relic who had helped me not once but numerous times!!

n I have already found the algorithms to obtain the inverse of different types of matrices!

Cheers!!

Relic

09-11-2000, 11:23 PM

I'm flattered. http://www.opengl.org/discussion_boards/ubb/smile.gif

Powered by vBulletin® Version 4.2.5 Copyright © 2019 vBulletin Solutions Inc. All rights reserved.