Transform.compose

Transform.compose#

Transform.compose(
transform: TransformLike,
*,
point: VectorLikeFloat | None = None,
multiply_mode: Literal['pre', 'post'] | None = None,
) → Transform[source]#

Compose a transformation matrix.

Create a 4x4 matrix from any transform-like input and compose it with the current transformation matrix according to pre-multiply or post-multiply semantics.

Internally, the matrix is stored in the matrix_list.

Parameters:
transformTransformLike

Any transform-like input such as a 3x3 or 4x4 array or matrix.

pointVectorLikeFloat, optional

Point to transform about. By default, the object’s point is used, but this can be overridden. If set, two additional transformations are composed and added to the matrix_list:

Added in version 0.47.

multiply_mode‘pre’ | ‘post’, optional

Multiplication mode to use when composing the matrix. By default, the object’s multiply_mode is used, but this can be overridden. Set this to 'pre' for pre-multiplication or 'post' for post-multiplication.

Examples#

Download Python source code | Download Jupyter notebook

Define an arbitrary 4x4 affine transformation matrix and compose it.

>>> import pyvista as pv
>>> array = [
...     [0.707, -0.707, 0, 0],
...     [0.707, 0.707, 0, 0],
...     [0, 0, 1, 1.5],
...     [0, 0, 0, 2],
... ]
>>> transform = pv.Transform().compose(array)
>>> transform.matrix
array([[ 0.707, -0.707,  0.   ,  0.   ],
       [ 0.707,  0.707,  0.   ,  0.   ],
       [ 0.   ,  0.   ,  1.   ,  1.5  ],
       [ 0.   ,  0.   ,  0.   ,  2.   ]])

Define a second transformation and use * to compose it.

>>> array = [[1, 0, 0], [0, 0, -1], [0, -1, 0]]
>>> transform = transform * array
>>> transform.matrix
array([[ 0.707, -0.707,  0.   ,  0.   ],
       [ 0.   ,  0.   , -1.   , -1.5  ],
       [-0.707, -0.707,  0.   ,  0.   ],
       [ 0.   ,  0.   ,  0.   ,  2.   ]])

Compose the transform about a point. Check the matrix_list to see that a translation is added before and after the transform.

>>> transform = pv.Transform().compose(transform, point=(1, 2, 3))
>>> transform.matrix_list
[array([[ 1.,  0.,  0., -1.],
        [ 0.,  1.,  0., -2.],
        [ 0.,  0.,  1., -3.],
        [ 0.,  0.,  0.,  1.]]),
 array([[ 0.707, -0.707,  0.   ,  0.   ],
        [ 0.   ,  0.   , -1.   , -1.5  ],
        [-0.707, -0.707,  0.   ,  0.   ],
        [ 0.   ,  0.   ,  0.   ,  2.   ]]),
 array([[1., 0., 0., 1.],
        [0., 1., 0., 2.],
        [0., 0., 1., 3.],
        [0., 0., 0., 1.]])]

See Also#

decompose