Matrices: Inverse vs. Transpose

B137e8bb14e2ea3ace15bf7b52647269
0
roger_hq 101 Sep 12, 2005 at 16:58

Hi,

First time poster, glad to see these forums gaining members.

On to my question:

I am getting back into 3D programming from moderately long hiatus and am dusting off the Direct3D application I was working on. I am implementing new features such as mouse picking and dragging of geometry, and I am successfully implementing these things but I am having trouble remembering why certain matrix operations have to be performed. I google search some of these items and I get a description of what they do to the matrix mathematically, but never the real-world explaination of what it does. So here goes:

When I project a geometric point in 3D space to the screen, I need to “invert” the view matrix in order to correctly get the screen space coordinate. So in my D3D implementation, something like this (forgive me if the parameters are not exactly correct, don’t have docs in front of me):

D3DXMatrixInverse(&invertedViewMatrix, NULL, &viewMatrix);

for this, my question is, what is the inverse operation doing to that point? Why do I have to invert the view matrix? I understand that if you take a transform and you multiply it by its inverse, you get the identity matrix. So is using an inverse of a matrix just to “undo” the effects of a matrix?

Another question is using a transpose matrix. When is it appropriate to use a transpose matrix vs. an inverted matrix?

Thanks in advance!

4 Replies

Please log in or register to post a reply.

45d2a3568ad34f6f0297377c4e9dc1b3
0
nachilau 101 Sep 12, 2005 at 18:11

Hello,

The simple rule of thumb is, when your transofrmation matrix only involves rotation (orthogonal transformation), then you can easily to get the inverse of that matrix by transpose it. However, if your transformation matrix involves some transformation that is not orthogonal (means not only do a rotation), then you need to do a full calculation to compute the inverse matrix, which means you need to do a expensive call and let D3DXMatrixInverse() to do it for you. Eg, the perceptive transformation is not an orthogonal transformation, but the rotation transformation is an orthogonal transformaion. Is it make sense to you?

@roger_hq

Hi,

First time poster, glad to see these forums gaining members.

On to my question:

I am getting back into 3D programming from moderately long hiatus and am dusting off the Direct3D application I was working on. I am implementing new features such as mouse picking and dragging of geometry, and I am successfully implementing these things but I am having trouble remembering why certain matrix operations have to be performed. I google search some of these items and I get a description of what they do to the matrix mathematically, but never the real-world explaination of what it does. So here goes:

When I project a geometric point in 3D space to the screen, I need to “invert” the view matrix in order to correctly get the screen space coordinate. So in my D3D implementation, something like this (forgive me if the parameters are not exactly correct, don’t have docs in front of me):

D3DXMatrixInverse(&invertedViewMatrix, NULL, &viewMatrix);

for this, my question is, what is the inverse operation doing to that point? Why do I have to invert the view matrix? I understand that if you take a transform and you multiply it by its inverse, you get the identity matrix. So is using an inverse of a matrix just to “undo” the effects of a matrix?

Another question is using a transpose matrix. When is it appropriate to use a transpose matrix vs. an inverted matrix?

Thanks in advance!

[snapback]21169[/snapback]

25bbd22b0b17f557748f601922880554
0
bramz 101 Sep 12, 2005 at 18:26

hi,

to understand what the inversion does, it’s best to see that matrix as some kind of function that applies to points and vectors. That function takes the coordinates of that point/vector in one vector space, and returns the coordinates of that same point/vector in another vector space. The camera matrix typically tells how to transform points from screen space to world space. But that doesn’t help you if you want to transform project points on your screen, because you need to transform points from world space to object space. So, you need the transformation in the opposite way that the one that the camera matrix gives you. That’s why you need to invert the camera matrix to project a point.

If you invert a 3x3 matrix that only contains a rotation in 3D, it turns out that the inverted matrix is exactly the same as the transposed matrix. So, in that case you may use the cheaper transposition to get the inverted rotation (inversion is a more expensive operation).

However, we typically use 4x4 matrices for our 3D transformations because they can also represent translations of points. It turns out that if the transformation still only represents a rotation, then the inverted matrix equals to what you get if you only transpose the upper left 3x3 block of the 4x4 matrix (and thus leaving the right column and bottom line alone).

If the 4x4 matrix also represents a translation, it already gets a little trickier … to get the inverted matrix, you can still transpose the upperleft 3x3 block, but the translation part (possible the 3 top elements in the right column, or the 3 left elements in the bottom row, depending what style of matrices you use) must also be taken care of. First see those 3 values as a 3D vector, rotate it by the transposed 3x3 block and negate it. Then put it back where it came from. Now you have you’re inverted matrix.

In any other case (if matrix also represents scaling, skewing, …), you should really invert the matrix instead of relying on transposing it.

I hope this is an answer to your questions.

Bramz

B137e8bb14e2ea3ace15bf7b52647269
0
roger_hq 101 Sep 12, 2005 at 19:28

Thank you both, yes, that does make sense. I seem to recall that now. So the take-home message is that both of these operations perform a “reverse operation” of a starting matrix, but the Transpose matrix is only a valid “reverse operation” if the starting matrix is composed of rotations only. On the other hand, an inverse matrix is a true “reverse operation” for any invertible matrix.

So, technically, its “always” appropriate to use an inverse matrix to reverse a transformation as it will always give you the correct reverse transformation (assuming the matrix is invertible); although it may be more work than you really have to do. A transpose is a faster reverse operation but only is appropriate when you know you don’t have any operations other than rotations.

Do I have it right?

Thanks!

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Sep 12, 2005 at 21:03

Yup, you’ve got it right. In addition to rotations, you can also have reflections and the transpose will still work. But absolutely no scales or shears. A transformation composed of rotations and reflections is called “orthogonal”.

Advanced: Another thing to consider is that transforming points sometimes needs a different matrix than transforming normal vectors. This is because normal vectors are not technically vectors in the usual sense (actually, they are called covariant vectors where the normal kind of vectors are called contravariant).

What this means for you is that if you have an orthogonal transformation, then the same matrix can be used for normal vectors and everything else. However, for a general transformation, the inverse transpose of the regular matrix must be used to transform normal vectors. This is the inverse of the transpose, or the transpose of the inverse (it doesn’t matter, as they are the same). As noted above, if the matrix is orthogonal the inverse and the transpose are the same thing, so the inverse transpose is just the original matrix again.