Maya: xform matrices

From wikinotes

Matrix Anatomy

Description

1. A vector describes a relative change in position. For example, the vector (1x, 2y, 3z) describes the movement from a point moving +1 units in x, +2 units in y, +3 units in Z.

2. A normalized vector is a vector whose magnitude (distance from original point as a straight-line) is 1

3. A transformation matrix describes the orientation/warping of the X,Y,Z axis, the position of the object, and in maya the affine transformation space which affects cameras (producing effects like altering the focal length).

    • the X,Y,Z vectors must be normalized
    • the X,Y,Z vectors must be orthogonal (perpendicular to each other)


#                 (affine transformation space)
#                       |
#                      \/
matrix = [
  norm-vector(1, 0, 0), 0,  # x-axis direction, and scale
  norm-vector(0, 1, 0), 0,  # y-axis direction, and scale
  norm-vector(0, 0, 1), 0,  # z-axis direction, and scale
  coordinates(0, 0, 0), 1,  # position, relative to parent
]
  • top-left 3x3 is normalized-vectors indicating the direction/scale of this object's X,Y,Z axis
  • bottom-left 1x3 is the position relative to the parent object (or origin, if no parents)
  • the 4th column is only relevant for camera objects. It is the affine transformation space and changes how other objects appear when looked at through the lens of this object.
    • first 3x rows affect perspective shifts (warping along X,Y,Z axis)
    • last row indicates a scale shift (larger number, means objects appear smaller)

Examples

neutral

Object is at the origin, with no rotation/scale applied to it.

  • from origin, X-vector describes a movement of 1 towards +X
  • same with Y-vector, and Z-vector
  • position is 0,0,0
[
    1, 0, 0, 0,  # X-axis
    0, 1, 0, 0,  # Y-axis
    0, 0, 1, 0,  # Z-axis
    0, 0, 0, 1,  # pos relative to parent (origin if no parent)
]

rotate 90Y

Object is at the origin, rotated 90* in Y.

  • from origin, X-vector now describes a movement of -1 in Z. (The X-axis now points towards -Z)
  • the Y axis remains the same
  • the Z axis now describes a movement of +1 in X. (The Z axis now points towards +X)
[
    0, 0,-1, 0,
    0, 1, 0, 0,
    1, 0, 0, 0,
    0, 0, 0, 1,
]

rotate 45Y

Object is at the origin, rotated 45* in Y. This is less easy to visualize, but it is the same as the above

  • X-axis moves +0.7 in X and -0.7 in Z. (this is still a normalized vector, so the vector's magnitude is still fixed at 1).
  • Y-axis remains unchanged
  • Z-axis moves +0.7 in X, and +0.7 in Z.
[
    0.7, 0, -0.7, 0,
    0,   1,    0, 0,
    0.7, 0,  0.7, 0,
    0,   0,    0, 1,
]

scale 2X

Object is at origin, with no rotation, but is scaled *2 in X.

[
    2, 0, 0, 0,  # X-axis
    0, 1, 0, 0,  # Y-axis
    0, 0, 1, 0,  # Z-axis
    0, 0, 0, 1,  # pos
]

Helpful Material

The following two posts were invaluable in my understanding of this, I only wish I was able to find them sooner.


Maya

print object matrix

matrix = cmds.xform(q=True, matrix=True)
for i in range(4):
    base = i * 4
    print(', '.format([str(m) for m in matrix[base:base+4]]))

[
    1.0, 0.0, 0.0, 0.0,   # rotations (0-1), ??
    0.0, 1.0, 0.0, 0.0,   # rotations (0-1), ??
    0.0, 0.0, 1.0, 0.0,   # rotations (0-1), ??
    0.0, 0.0, 0.0, 1.0,   # transforms, 1.0
]


References

http://help.autodesk.com/view/MAYAUL/2018/ENU/?guid=__cpp_ref_class_m_matrix_html Maya C++ API MMatrix documentation
http://www.macaronikazoo.com/?p=435 euler rotation and matrices
http://www.macaronikazoo.com/?p=451 matrices in the wild
http://www.macaronikazoo.com/?p=395 scale and rotation matrix
http://www.macaronikazoo.com/?p=380 matrix anatomy
http://www.macaronikazoo.com/?p=378 matrix math
http://blog.duber.cz/3ds-max/the-transformation-matrix-is-useful-when-understood differences between 3dsmax and maya matrices