Scale component of aTransform matrix

I’m diving back in to what Matrix numbers mean. I have read 2 explanations for the scale component of transform matrix. Given the row-major (maya) matrix :

	[ xx xy xz 0 ]
	[ yx yy yz 0 ]
	[ zx zy zz 0 ]
	[ tx ty tz 1 ]

Explanation 1 :
Scale factor is the length of the X Y Z components of the 3x3 rotation sub matrix

	Scale X = length [ xx xy xz ]
	Scale Y = length [ yx yy yz ]
	Scale Z = length [ zx zy zz ]

Explanation 2:
Scale factor is the diagonal elements of the 3x3 rotation sub matrix

	Scale  = [ xx yy zz ]

I suspect Explanation 1 is always correct,
and Explanation2 is only true with no rotation - when it’s a scale matrix only

Is this correct?

You are indeed correct.

In fact, here’s something to play around with to give you a better feel for things. I wrote it for a coworker of mine just last week to explain how matrices work. It’s a rig that directly builds a matrix in Maya. It just plugs the translation values of some objects directly into a fourByFourMatrix node.

You can grab the x, y, and z axes and move them around and see what it does.

2 Likes

Thanks! that will be a fun toy.

Had to update create_shader() to fix the typing to get it running.

from typing import Tuple, List

from maya import cmds
# ...

def create_shader(
    name: str, 
    rgb: Tuple[float, float, float],
    target: List[str], 
    node_type: str = "lambert",
 ):
    material: str = cmds.shadingNode(node_type, name=name, asShader=True)
    sg: str = cmds.sets(name=f"{name}SG", empty=True, renderable=True, noSurfaceShader=True)
    cmds.connectAttr(f"{material}.outColor", f"{sg}.surfaceShader")
    cmds.sets(target, edit=True, forceElement=sg)
    cmds.setAttr(f"{material}.color", *rgb, type="double3")

Ah, yeah. My code works in python 3.9 and later. And I’m on Maya 2024 which is python 3.10.

Ugh. And apparently they had a proposal to add those “generic type annotations” to a __future__ import, but they delayed it. And it’s not like maya 2022 is gonna get any python updates :frowning:

It’s probably better to just strip the types for maximum compatibility

1 Like

good to know that typing stuff got more simple in newer versions