about matrix

454 views
Skip to first unread message

delibrax

unread,
Oct 17, 2018, 1:33:52 PM10/17/18
to Python Programming for Autodesk Maya
Hi guys,

As a rigger or TD in CG I think knowlegde about matrix as basic foundation is absolutely necessary. Anyone can explain with an example as comprehensive between World Matrix, Xform Matrix, Parent Matrix, Matrix and inverse of them? what if we calculate like multimatrix or add matrix? what if their condition as parent or child and so on.. I have google it but then don't find particular case in maya.

I am asking because sometimes i'm affraid when found and these part becomes obstacles. Thanks in advance! :)


Cheers,

Phil Sloggett

unread,
Oct 18, 2018, 4:34:41 AM10/18/18
to python_in...@googlegroups.com
This is maybe a little too long to explain on an email - but I'll try. I'll also assume you know what a Vector is, otherwise this is definitely too much for an email, I'll give this the 5 minute write up and hopefully others can correct my mistakes.

A matrix is an amazing unit of mathematics that can transform a Vector from one "space" to another. Think maya's "object" space and "world" space, thats _exactly_ what we're talking about.

A untransformed matrix at the origin would look like

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

This is called the identity matrix - it has no translation, rotation, scale or shearing applied to it. You can tell just by looking at it because the 4 rows are easily readable vectors in their own right.

1 0 0 0  <- X-axis vector of this "space"
0 1 0 0  <- Y-axis "" ""
0 0 1 0  <- Z-axis "" "" 
0 0 0 1  <- translation of this "space"

The last column is always [0, 0, 0, 1] I think, just because they need to be for the math to work.

given the X-axis vector is <1, 0, 0> (perfectly aligned with scene-X) and the Y, Z vectors are the same - we can see this matrix is not rotated.
given the translation vector is <0, 0, 0> we can see this matrix is not translated.
given the 3 axis vectors are all exactly 1-unit long, we can see this hasnt been scaled in any axis.
given the 3 axis vectors are all at right-angles (easy to tell in this case, usually not so easy) we can see the matrix is not sheared.

So this is the matrix of a node sitting at the origin - completely untransformed.

Thats how you "read" a matrix, try moving a node around in maya and query its "worldMatrix[0]" in different positions, you'll quickly see whats going on.

Which brings us to matrix vs worldMatrix.

Matrices can be "added together" - which I believe is actually matricies being multiplied together, mathemically speaking - and is super efficient for calculating hierarchy transformations (because you can build a single "world" matrix to transform a vector in worldspace to an equivalent vector in local space.)

The "matrix" attribute is a description of the matrix relative to a node's parent (i.e. the node's local space). The "worldMatrix" as a description of the matrix relative to the scene. The worldMatrix can be computed by multiplying, in order, the local matrix of each parent of a node. The "parentMatrix" is a shortcut attribute in maya to access the worldMatrix of the node's immediate parent.

Knowing this, the "inverse" matrix is kinda what it sounds like. If a matrix is a math object to transform a vector from one space to another, the same matrix's "inverse" is a matrix to go the other way. In our world, I think, matrices will always have a possible inverse - this isn't the case in pure math world.


The details of "how" you multiply matrices, or "how" you multiply a vector by a matrix isn't important. But knowing what result to expect _is_.

I'd just start creating some Vectors, and multiplying them by a matrix that you can move around.
e.g.
vector = pymel.core.dt.Vector(1, 0, 0)
matrix = pymel.core.PyNode("someTransformNode").worldMatrix[0].get()
result = vector * matrix

Just play with it. Try using inverses too.

Finally, I'd point out there _is_ a difference between Points and Vectors. (points are actually length=4). - I think Multiplying a vector by a matrix will essentially rotate your vector in to the new space's orientation, while multiplying a Point will fully transform a translated point in to a new space.

Good luck!

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7cfa02c9-6cb9-4beb-aa27-5be9487d8c98%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages