Transform.compose#
- Transform.compose(
- transform: TransformLike,
- *,
- point: VectorLike[float] | None = None,
- multiply_mode: Literal['pre', 'post'] | None = None,
Compose a transformation matrix.
Create a 4x4 matrix from any transform-like input and compose it with the current transformation
matrixaccording to pre-multiply or post-multiply semantics.Internally, the matrix is stored in the
matrix_list.- Parameters:
- transform
TransformLike Any transform-like input such as a 3x3 or 4x4 array or matrix.
- point
VectorLike[float],optional Point to transform about. By default, the object’s
pointis used, but this can be overridden. If set, two additional transformations are composed and added to thematrix_list:translate()topointbefore the transformationtranslate()away frompointafter the transformation
Added in version 0.47.
- multiply_mode‘pre’ | ‘post’,
optional Multiplication mode to use when composing the matrix. By default, the object’s
multiply_modeis used, but this can be overridden. Set this to'pre'for pre-multiplication or'post'for post-multiplication.
- transform
See also
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.]])]