hou.Matrix4 class

A 4×4 matrix of floating point values.

All Methods Replaces

See also: hou.Vector4, hou.Vector3, hou.hmath.identityMatrix, hou.hmath 3 more , hou.ObjNode, hou.Vector3, hou.hmath

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*M, not M*p. Similarly, p*M1*M2 will first transform p by M1, and then transform it by M2.

Note

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 C*B*A.

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.

Methods

asTuple(self)tuple of float

Not documented yet

asTupleOfTuples(self)tuple of tuple of float

Not documented yet

at(self, row, col)double

Not documented yet

determinant(self)double

Not documented yet

explode(self, transform_order='srt', rotate_order='xyz')dict of str to hou.Vector3

Not documented yet

extractRotates(self, transform_order='srt', rotate_order='xyz', pivot=hou.Vector3())hou.Vector3

Not documented yet

extractScales(self, transform_order='srt', pivot=hou.Vector3())hou.Vector3

Not documented yet

extractShears(self, transform_order='srt', pivot=hou.Vector3())hou.Vector3

Not documented yet

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.

inverted(self)hou.Matrix4

Not documented yet

isAlmostEqual(self, matrix4, tolerance=0.00001)bool

Return whether this matrix is equal to another, within a tolerance.

plus(self, matrix4)hou.Matrix4

Not implemented yet

preMult(self, matrix4)hou.Matrix4

Not documented yet

setAt(self, row, col, value)

Not documented yet

setTo(self, tuple)

Not documented yet

setToIdentity(self)

Not documented yet

setToZero(self)

Not documented yet

times(self, vector3)hou.Vector3

Not implemented yet

transposed(self)hou.Matrix4

Not documented yet

__add__(self, matrix4)hou.Matrix4

Not documented yet

__mul__(self, matrix4) -> Matrix4 OR __mul__(self, scalar)hou.Matrix4

Not documented yet

__sub__(self, matrix4)hou.Matrix4

Not documented yet

Replaces

matrix expression function , determinant expression function , explodematrix expression function , vorigin expression function , vrorigin expression function , invert expression function , identity expression function , mzero expression function , transpose expression function