PDA

View Full Version : Matrix questions



chronozphere
13-01-2007, 03:03 PM
Hi all 8)

I've two matrix questions (I'm using Direct3d so i need appropriate answers):

1. Are the rows of the upper-left part (3x3) of a matrix the base-vectors for the coordinate system, the matrix defines. To be more specific:
Is e.g the following vector [_11,_12,_13] the X axis for the new coordinate system?? :?

2.I dont understand why Direct3d uses 4x4 matrices instead of 3x3. The coordinates all have 3 components so you would expect a 3x3 matrix,
i know one row (_41,_42,_43) is ment for translation values.. Example:

http://msdn.microsoft.com/archive/en-us/directx9_c_Summer_04/directx/Art/matexpnd.gif

This shows how a vector is multiplied/transformed using a matrix, but i miss one column (_14,_24,_34,_44).
It seems that sometimes vectors with 4 components are used.

I was trying to understand the matrix on this page:

D3DXMatrixPerspectivefovLH (http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_Dec_2005/D3DXMATRIXIdentity.asp)

But i don't know what the function of the 1.0 is (4th column, third row). :?

Can anyone explain the function of the 4th component and the last matrix-column???

Thank you ;)

grudzio
15-01-2007, 02:59 PM
1. Yes, but when matrix contains only rotations and translations (no scaling).
2. To fully describe transformations in 3D (rotations, translation and scaling) you need 4x4 matrix. Translation must be in 4th row. You will see it if you rewrite the translation eqation


x' = x + tx
y' = y + ty
z' = z + tz

into the matrix form.

The remaining fourth column contains zeros except the _44 element which is one. Since the matrix is square, it can be inverted.
In order to multiply vector by a 4x4 matrix, the vector must have four components. Usually the fourth one called w is set to one.

The calculations on the picture implicitly assume that w equals one and missing column contains zeros.

As for the projection matrix, the only thing I can say that it contains the view frustum and it transforms coordinates from world space to screen space. It is all I know.

chronozphere
15-01-2007, 08:01 PM
1. Yes, but when matrix contains only rotations and translations (no scaling).

Uhh...:shock: why no scaling?? if you scale, you simply stretch the base vectors. So if you create a scale matrix with factors (2,2,2), the base vectors of the matrixes coordinate system will have a length of 2.
So everything transformed with this matrix will become 2 times bigger. :)

If you need base vectors with length=1.0 then you simply have to normalize them. isn't it?? :?

Sorry but i dont see the problem with scaling. Could you explain that??



Since the matrix is square, it can be inverted.


right... so that's the main reason why we use 4x4 matices. It can be inverted.
BTW: what's inverted?? calculating the inverse matrix?? :? didn't know a square matrix was required to do that.

So whe do not use the 4th column, except if we want to do something with W.
So if we set W to 2, would that multiply all translation valeus by 2?? can that be usefull?? :?

I like to know how the projection matrix in my first post works.. if anyone knows, please let me know. ;)

grudzio
15-01-2007, 10:09 PM
1. Yes, but when matrix contains only rotations and translations (no scaling).

Uhh...:shock: why no scaling?? if you scale, you simply stretch the base vectors. So if you create a scale matrix with factors (2,2,2), the base vectors of the matrixes coordinate system will have a length of 2.
So everything transformed with this matrix will become 2 times bigger. :)

If you need base vectors with length=1.0 then you simply have to normalize them. isn't it?? :?

Sorry but i dont see the problem with scaling. Could you explain that??


I may be wrong, but I think when the scaling is non uniform e. g. (1,2,3)
then the scaled base vectors will not be orthogonal anymore.






Since the matrix is square, it can be inverted.


right... so that's the main reason why we use 4x4 matices. It can be inverted.
BTW: what's inverted?? calculating the inverse matrix?? :? didn't know a square matrix was required to do that.


A matrix is invertible (has an inverse matrix) if its determinant (http://en.wikipedia.org/wiki/Determinant) is non zero.
And determinant is defined only for square matrices.




So whe do not use the 4th column, except if we want to do something with W.
So if we set W to 2, would that multiply all translation valeus by 2?? can that be usefull?? :?


In 3D graphics, after the vector is transformed by a projection matrix, its x, y and z coordinates are divided by w. So by changing the w value you can shrink or grow 3D objects. w coordinate is also used in shadow volume technique, where an infinite volume is needed. The points definig this volume are moved to infinity by setting w to zero.



I like to know how the projection matrix in my first post works.. if anyone knows, please let me know. ;)

Take a look here (http://www.codeguru.com/cpp/misc/misc/math/article.php/c10123/).

chronozphere
16-01-2007, 12:08 PM
I may be wrong, but I think when the scaling is non uniform e. g. (1,2,3)
then the scaled base vectors will not be orthogonal anymore.


Do you mean that the basevectors are not perpendicular anymore??
Yeah.. that can happen. It'll change the area between (0.0.0) and (1.1.1) into a parallelogram. :)
I think it will happen when you create a rotation matrix and scale it afterwards. But i dont think it's a problem... those are still valid basevectors. isn't it??? :?



Take a look here.


That page looks interesting.. i'll take a look at it when i'm home. I'm at school right now ;)

Thank you for all the usefull info. :)

grudzio
16-01-2007, 06:43 PM
I may be wrong, but I think when the scaling is non uniform e. g. (1,2,3)
then the scaled base vectors will not be orthogonal anymore.


Do you mean that the basevectors are not perpendicular anymore??
Yeah.. that can happen. It'll change the area between (0.0.0) and (1.1.1) into a parallelogram. :)
I think it will happen when you create a rotation matrix and scale it afterwards. But i dont think it's a problem... those are still valid basevectors. isn't it??? :?



Yes they are (I was wrong in my first post). Base vectors must be linearly independent and don't have to be orthogonal (perpendicular) to each other.

But if they are non orthogonal, then they don't describe cartessian coordinate system, so they are rather useless.

chronozphere
16-01-2007, 07:25 PM
But if they are non orthogonal, then they don't describe cartessian coordinate system, so they are rather useless.

Yeah... useless, but still it's a nice effect.. let's skew the scene :razz:

Thanx for all your explanations.:) If i have further questions, i'll post them here ;)