pyvista.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
matrix
according 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
point
is used, but this can be overridden. If set, two additional transformations are composed and added to thematrix_list
:translate()
topoint
before the transformationtranslate()
away frompoint
after 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_mode
is used, but this can be overridden. Set this to'pre'
for pre-multiplication or'post'
for post-multiplication.
- transform
See also
Examples
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.]])]