A 4×4 matrix of floating point values.
4×4 matrices are typically used in Houdini to represent a 3D transformation (e.g. some combination of rotation, scaling, shearing, translation, etc.). A single matrix compactly represents a transformation, and is much easier to deal with than multiple translate, rotate, scale, shear, transformation order, and rotation order values.
Note that Houdini’s matrices are stored in row-major format, and vectors that are multiplied with matrices are treated as row vectors. So, if
p is a hou.Vector4 representing a point and
M is a Matrix4, you write
p*M1*M2 will first transform
M1, and then transform it by
Most mathematical notations assume matrices are stored in column-major format and that points are stored as column vectors. They will often use
A*B*C (or simply
ABC) to refer to a combined transform that first applies
C's transform, then
B's, and then applies
A's. To represent the same matrix expression in Houdini, you need to concatenate the transforms in the reverse order. So, you would instead write
You can multiply Matrix4s by Vector3s or Vector4s. If you multiply by a Vector3, it is the same as multiplying by a Vector4 where the fourth component is 1.
To transform a vector (as opposed to a point), you need to multiply by the inverse transpose of the matrix. For example, if
p is a hou.Vector3 object representing a point (a position in space) and
v is a hou.Vector3 object representing a vector (a direction with a length but no fixed location in space, and
m is a transform matrix, you would write:
p * m v * m.inverted().transposed()
>>> m = hou.hmath.buildTranslate(1, 1, 2) >>> m <hou.Matrix4 [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 1, 2, 1]]> >>> p = hou.Vector3(1, 2, 3) >>> p * m <hou.Vector3 [2, 3, 5]>
Both Vex and the UT_DMatrix4 class in the Houdini Development Kit (HDK) also store matrices in row-major format.
at(self, row, col)→
explode(self, transform_order='srt', rotate_order='xyz')→
extractRotates(self, transform_order='srt', rotate_order='xyz', pivot=hou.Vector3())→ hou.Vector3
extractScales(self, transform_order='srt', pivot=hou.Vector3())→ hou.Vector3
extractShears(self, transform_order='srt', pivot=hou.Vector3())→ hou.Vector3
extractTranslates(self, transform_order="srt")→ hou.Vector3
Returns the translate component of this matrix.
This method treats the matrix as a transformation matrix and extracts the translate component. The transform order determines how the matrix is interpreted and can affect the return value.
For example, imagine a transformation where you first translate in x by one unit, then you rotate in z by 45 degrees. With a transform order of “trs” (translate, rotate, scale), the translate component is (1, 0, 0). However, this same transformation could be constructed, for example, by first by first scaling, then rotating, and then translating. For this transformation order, the translate component would be (1.0 / math.sqrt(2), 1.0 / math.sqrt(2), 0).
>>> matrix = hou.hmath.buildTranslate(1, 0, 0) * hou.hmath.buildRotate(0, 0, 45) >>> matrix.extractTranslates("trs") <hou.Vector3 [4, 0, 0]> >>> matrix.extractTranslates("srt") <hou.Vector3 [0.707107, 0.707107, 0]>
If the matrix does not represent a valid transform matrix, this method will raise hou.OperationFailed.
isAlmostEqual(self, matrix4, tolerance=0.00001)→
Return whether this matrix is equal to another, within a tolerance.
plus(self, matrix4)→ hou.Matrix4
preMult(self, matrix4)→ hou.Matrix4
setAt(self, row, col, value)
times(self, vector3)→ hou.Vector3
__add__(self, matrix4)→ hou.Matrix4
__mul__(self, matrix4) -> Matrix4 OR __mul__(self, scalar)→ hou.Matrix4
__sub__(self, matrix4)→ hou.Matrix4