Not logged in, Join Here! or Log In Below:  
News Articles Search    

 Home / General Programming / Whats the inverse of this matrix? Account Manager
Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

March 15, 2005, 09:15 AM

Hello can anyone help me with this problem.
I am calculating all afternoon, i just dont get it.

| xx yx zx 0|
| xy yy zy 0|
| xz yz zz 0|
| t1 t2 t3 1|

Rui Martins

March 15, 2005, 09:51 AM

Google for " +inverse +matrix "

NOTE: Some matrices can't be inverted ! to be inversible, it has to have some specific properties, but I'll let you google for them, for practice. 8)


March 15, 2005, 10:08 AM

A square matrix can only be inverted if it has a nonzero determinant.

Due to its special structure (fourth column being 0,0,0,1) your matrix has determinant

D = xx*yy*zz + yx*zy*xz + zx*xy*yz - zx*yy*xz - zy*yz*xx - yx*xy*zz.

Note that t1,t2,t3 don't appear. If this term evaluates to zero, it cannot be inverted.

Now it isn't clear from your notation whether xy is a variable or the product x*y.
If I assume xy means x*y, you can quickly verify yourself that D is always zero, no matter what x,y,z are, so this matrix _never_ has an inverse.

Therefore I assume that xy and yx are differently named variables. Then if D is nonzero the inverse is

| yy*zz-yz*zy yx*zz-yz*zx yx*zy-yy*zx |
| xy*zz-xz*zy xx*zz-xz*zx xx*zy-xy*zx | * 1/D
| xy*yz-xz*yy xx*yz-xz*yx xx*yy-xy*yx |

Even if you don't understand your linear algebra -- which you really should -- things like these can be figured out quickly using Maple, MatLab or Mathematica, which your favourite college/university should have ready if it's worth attending its courses.


March 15, 2005, 10:11 AM

Why do you want to have it symbolically? Maybe the context provides for an easier solution.

Erik Faye-Lund

March 15, 2005, 10:14 AM

without the information that created the matrix, i guess you'd have to invert it by either gaussian elimination or cramers rule. if ou DO have the info that created it, it might be easier.


matrix made by
translation(tx, ty, tz) * rotation(rx, ry, rz) * scale(sx, sy, sz)

can be inverted mye creating a matrix something like this
scale(1 / sx, 1 / sy, 1 / sz) * rotation(-rx, -ry, -rz) * translation(-tx, -ty, -tz)

what is more _efficent_ is another question.

there are also some other ways of inverting 3x4 matrices more efficently... like inverting the 3x3 rotation/scale part and transforming the position-part with it or something. don't quite remember.

Rui Martins

March 15, 2005, 11:15 AM

I think is problem is simpler !

He simply doesn't know how to invert an invertible matrix !


March 15, 2005, 11:17 AM

How can the inverse of a 4*4 matrix be a 3*3 matrix?


March 15, 2005, 11:30 AM

That's not really possible. If I compute the inverse in Mathematica, I get a complicated matrix of xx, xy, xz, t, etc - terms. Therefore I asked you about the context, because there is probably a simpler solution. But Erik is right about the determinant part; the inverse it not unconditionally defined, only for D != 0.


March 15, 2005, 11:41 AM

The context is the following.

I got a polygon A. Q is a point on A.
I want to add a new Point p on the polgon that lies on a distance d from Q.
The direction is choosen randomly as an angle.

After building the local system around Q, i get this:


Now i want to transform P back to the global system. So i have to multiply P with the inverse transformation matrix.

Local System around Q:
Z-Axis: normal of A
Y-Axis (for example) ... take one of your polygon edges ( v.e. Point1 - Point2), normalize the resulting vector
X-Axis: Cross product of Z and Y axis (perpendicular vector)

Transforming a point D to local system:

If i want to Transform point D back to Global: I have to multiply D with the inverse transformation matrix.


March 15, 2005, 12:57 PM

Ok. I don't see why you want to do all the transforms, but that's off-topic I guess. You want to invert some matrix M numerically -- I suppose you have filled in values for the transformation matrix T and want its inverse T^(-1); this is not the same as you posted at first. Furthermore let's assume T is non-singular such that an inverse exists.

There are multiple methods, but I found this page rather explicit:

What is done is that the elements of A are shifted around and change sign here and there, which is multiplied by the inverse determinant (which is why the determinant cannot be zero).


March 15, 2005, 02:06 PM



March 15, 2005, 02:10 PM

If you matrix is a "standard" transform (a rotation in the upper 3x3 matrix) then the inversion is really easy:

B = the transpose of the upper 3x3 matrix
t = (t1, t2, t3)' vector
t2 = B*t

Now you store B in the upper 3x3 matrix of the result, t2 in the lower row and set the last column to (0, 0, 0, 1)'.


March 15, 2005, 04:12 PM

Of course it cannot, I fogot the fourth row and column. I'm sorry.

Add a fourth column (here written as a row)
[0, 0, 0, 1]

and a fourth somewhat complicated row (here written as a column)

Again, I'm sorry.


March 15, 2005, 04:14 PM

This is only true if the upper 3x3 matrix contains a true pure rotation, not if it involves shearing, scaling or projection. In maths books it's called orthonormal (also called orthogonal in other definitions, don't argue here).

This thread contains 15 messages.
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.