Transform.rotate#
- Transform.rotate(
- rotation: RotationLike,
- *,
- point: VectorLike[float] | None = None,
- multiply_mode: Literal['pre', 'post'] | None = None,
Compose a rotation matrix.
Create a rotation matrix and
compose()it with the current transformationmatrixaccording to pre-multiply or post-multiply semantics. The rotation may be right-handed or left-handed.Internally, the matrix is stored in the
matrix_list.- Parameters:
- rotation
RotationLike 3x3 rotation matrix or a SciPy
Rotationobject.- point
VectorLike[float],optional Point to rotate 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 rotationtranslate()away frompointafter the rotation
- 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.
- rotation
See also
rotate_x,rotate_y,rotate_z,rotate_vectorSimilar rotation methods.
rotation_matrix,rotation_axis_angle,as_rotation,has_rotationGet this transform’s rotation component.
pyvista.DataObjectFilters.rotateRotate a mesh.
Examples#
Download Python source code | Download Jupyter notebook
Compose a rotation matrix. In this case the rotation rotates about the z-axis by 90 degrees.
>>> import pyvista as pv
>>> rotation_z_90 = [[0, -1, 0], [1, 0, 0], [0, 0, 1]]
>>> transform = pv.Transform().rotate(rotation_z_90)
>>> transform.matrix
array([[ 0., -1., 0., 0.],
[ 1., 0., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
Compose a second rotation matrix. In this case we use the same rotation as before.
>>> _ = transform.rotate(rotation_z_90)
The result is a matrix that rotates about the z-axis by 180 degrees.
>>> transform.matrix
array([[-1., 0., 0., 0.],
[ 0., -1., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
Rotate about a point. Check the matrix_list to see that a translation
is added before and after the rotation.
>>> transform = pv.Transform().rotate(rotation_z_90, point=(1, 2, 3))
>>> translation_to_origin = transform.matrix_list[0]
>>> translation_to_origin
array([[ 1., 0., 0., -1.],
[ 0., 1., 0., -2.],
[ 0., 0., 1., -3.],
[ 0., 0., 0., 1.]])
>>> rotation = transform.matrix_list[1]
>>> rotation
array([[ 0., -1., 0., 0.],
[ 1., 0., 0., 0.],
[ 0., 0., 1., 0.],
[ 0., 0., 0., 1.]])
>>> translation_from_origin = transform.matrix_list[2]
>>> translation_from_origin
array([[1., 0., 0., 1.],
[0., 1., 0., 2.],
[0., 0., 1., 3.],
[0., 0., 0., 1.]])