Jump to content

Transformation Matrix


Recommended Posts

I guess I've asked this question to the List about 6 months ago. Never quite to an answer for it probably due to the complexity.

So for those of you with plenty of time, how does a 3x3 or 4x4 transformation matrix works?

I have googled the web, haven't quite found any good explaination for it...

Anyway, off to bed I go.

Link to comment
Share on other sites

A matrix is nothing more than a collection of data arranged in the form of a table. A transform matrix is no exception.

Matrix Algebra however turns this thing into a very useful device by defining all the possible (algebraic) operations that can be done with them. It sets out rules (based on strict proof) for how to combine them (mult, div, inverse, etc) and categorize them (identity, square, symmetric, etc).

This makes it much simpler, for example, to solve sets of linear equations (2 or more equation with 2 or more unknowns). A 3D transformation can be represented as one or more linear equations, and so can also be represented by a matrix. There are also a lot of properties of an xform matrix (all matrices really) that can also be exploited and would be much more complicated if you were to keep everything in functional form.

An xform matrix is usually a 4x4 (homogeneous) table of numbers, usually indexed like this:

i1j1 i1j2 i1j3 i1j4

i2j1 i2j2 i2j3 i2j4

i3j1 i3j2 i3j3 i3j4

i4j1 i4j2 i4j3 i4j4

Where 'i' is the row number, and 'j' is the column number.

Some simple roadmaps for a typical xform matrix:

Identity (no transformation):

1 0 0 0

0 1 0 0

0 0 1 0

0 0 0 1

Scaling:

Sx 0 0 1

0 Sy 0 1

0 0 Sz 1

0 0 0 1

Translation:

0 0 0 1

0 0 0 1

0 0 0 1

Tx Ty Tz 1

Rotation is a little trickier and spread accross the i1j1-i3j3 sub-matrix.

For a nice basic intro, check out

http://www.vuse.vanderbilt.edu:8888/es130/...re9/matwhat.htm

Link to comment
Share on other sites

Hi Mario,

Thank you for your information. I guess I should be going back to the basic matrix algebra first before I jump on board to try to understand transformation matrix.

Welp, I guess I'll post more about it after I've gone through the basic matrix algebra first.

Thanks!

Link to comment
Share on other sites

What goes on inside a matrix is a bit of voodoo I wouldn't bother learning. The thing is just learn how to USE them. Don't bother with the mathematics behind it.

basically: Describe a transformation as a matrix using special functions, and then apply that matrix to something like a vector. Thats all.

matrix mat = ident(); // initialise xform

mat = rotate( some_angle_and_axis ); // describe xform

newpos = oldpos * mat; // apply xform

easy!

later,

j.

  • Like 1
Link to comment
Share on other sites

Hey Alex :)

There was a post to the mailing list awhile back which you may remember (forgot who the poster was, DOH sorry!). It was about a math book which they were recommending for quick referencing of transformation Matrixs and other such voodoo. Its helped me out quite a bit along with some other "math for dummies" type books. :D

Book name, "Essential Mathematics for Computer Graphics - fast, by John Vince"

Mike C.

Link to comment
Share on other sites

My pleasure,

1. Yip - correct.

2. Get a vector from A to B and define a matrix using rotate(), like so:

vector newP;

matrix mat = ident();

vector axis = normalize( B -A );

rotate( mat, axis, p_amount );

newP = P * mat;

ps. Make sure A and B are defined in the same space as P, or you'll get silly results:) In a SOP, this doesnt matter too much, but in a shader you'll have to do some transforms with wo_space(), etc - because P is defined in camera ("world") space instead of object space.

enjoy,

The Technical Tapir.

Link to comment
Share on other sites

Suppose pouints P, A, B are in the "object" space.

In this case the rotation

will be only about the object origin, and the "axis" actually

represents only the direction of the rotation. Is this right?

How can I rotate P about the axis, the origin of which is in point A?

Is it correct solution:

matrix mat = ident();

//transform to A space

vector newP = P - A;

vector axis = normalize(B-A);

rotate( mat, axis, p_amount );

newP *= mat;

//reset transform

newP+=A;

One more question...

Does Vex have "world" coordsys, as in renderman SL?

If I understand correctly, then

vex world = sl current,camera

vex object = sl object

vex texture = sl shader

:unsure: = sl world

Link to comment
Share on other sites

Ah yes, true! I forgot about the pivot point. I guess I would have found out the hard way;)

Unfortunately VEX doesn't have a world coordinate system. :-/ Version 5+ has an option to "Seperate Camera Transform" and so on, but I am not sure if this can be used to manufacture a renderman equivalent of a world space.

Link to comment
Share on other sites

I completely trust your knowledge on the matter, though one detail bewilders me. I was under the impression that in matrix algebra the transformation matrix had to stand to the left of the vector, upon which it is acting. Thus you'd have to write matrix*vector, instead of vector*matrix, due to the formats of the two matrices involved. Is this not the case in Houdini?

As for the 4*4 transformation matrices, is it correct that a 3*3 matrix would do the job, while the extra elements populated with 0 or 1 indicates object-/world-space?

Thanks

Link to comment
Share on other sites

  • 1 month later...

Whoohoo! It's finally starting to click a bit. :D

Ok, so how do you multiply a matrix by a vector (in math)?

Why is it necessary to compute identity matrix first through: matrix mat = ident();? What's happening there behind the scene...?

Also, how do you extract an element within a matrix?

Back in vector3(), I can specify as `vector3(1,2,3)[0]`to extract it. But something like this won't even work...`matrix("[[1,2][3,4]]")[0][1]`

did I do something wrong...?

Link to comment
Share on other sites

Ok, so how do you multiply a matrix by a vector (in math)?

well, if you know how to multiply two matrices, you already know the answer to that one :)

just look at a vector as a one row or a one column matrix, matrix multiplication rules apply....

Why is it necessary to compute identity matrix first through: matrix mat = ident();? What's happening there behind the scene...?

not much, I guess....an identity matrix is just a square matrix, one which is all zeroes and has a diagonal of 1s...I guess it's just faster use predefined functions and fill it with ident() rather than try to do it manually, since these functions are usually optimized...

But something like this won't even work...`matrix("[[1,2][3,4]]")[0][1]`

dunno 'bout that one...it's probably a syntax thing (duh!) :)

enjoy!

Link to comment
Share on other sites

well, if you know how to multiply two matrices, you already know the answer to that one :)

just look at a vector as a one row or a one column matrix, matrix multiplication rules apply....

Duh. :D Forgot about that one. I was thinking about something else completely. That was really easy. :)

so the ident() is basically just to ensure that the matrix is a square matrix instead of, say, 4x2?

Link to comment
Share on other sites

Hey Thanks.

Well, I am beginning to understand more about matrix algebra now. However, I still haven't figure out how to apply matrix within Houdini yet... Or even the transformation matrix...

I guess another things that I have yet to absorb is what's happening behind the transformation matrix... :unsure:

Any tips? samples?

Thanks.

Link to comment
Share on other sites

 so in a transformation matrix, you can't rotate 2 axis at the same time in the same matrix space, right?

right....but that doesn't necessarily mean you need quaternion matrices...

one of the reasons why matrices are so popular in CG, is that you can concatenate them ("bundle them up" by multiplying them) the result is a single transform matrix you can apply to your points...if you need 2 (or 3, 4, 5 ) consecutive rotations (or even a combo: rotation, translation, scale), all you have to do is multiply their matrices and apply them to P.

I'll assume you're using transform matrices for animation, so if you consider a frame to be your time unit, then nothing prevents you from applying as many transform matrices as you want to your object before displaying the final result of this one single frame - that's what all packages do.....concatenating individual matrices...

besides, I'm no expert, but I think the quaternion implementation is more involved than regular transform matrices math...and only useful if you want to avoid gimbal lock at any cost...

confused yet? like Jason said, you can pretty much use all that stuff as an "end user" ... guilt free :D

reader's digest:

http://www.gamasutra.com/features/20020510.../johnson_01.htm

pure linear algebra, no transform stuff :

http://www.cfxweb.net/modules.php?name=New...article&sid=614

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...