pyvista.core._validation.validate.validate_rotation

pyvista.core._validation.validate.validate_rotation#

validate_rotation(
rotation: pyvista.RotationLike,
must_have_handedness: Literal['right', 'left'] | None = None,
name: str = 'Rotation',
)[source]#

Validate a rotation as a 3x3 matrix.

The rotation is valid if its transpose equals its inverse and has a determinant of 1 (right-handed or “proper” rotation) or -1 (left-handed or “improper” rotation). By default, right- and left-handed rotations are allowed. Use must_have_handedness to restrict the handedness.

Parameters:
rotationRotationLike

3x3 rotation matrix or a SciPy Rotation object.

must_have_handedness‘right’ | ‘left’ | None, default: None

Check if the rotation has a specific handedness. If right, the determinant must be 1. If left, the determinant must be -1. By default, either handedness is allowed.

namestr, default: “Rotation”

Variable name to use in the error messages if any of the validation checks fail.

Returns:
np.ndarray

Validated 3x3 rotation matrix.

Examples

Validate a rotation matrix. The identity matrix is used as a toy example.

>>> import numpy as np
>>> from pyvista import _validation
>>> rotation = np.eye(3)
>>> _validation.validate_rotation(rotation)
array([[1., 0., 0.],
       [0., 1., 0.],
       [0., 0., 1.]])

By default, left-handed rotations (which include reflections) are allowed.

>>> rotation *= -1  # Add reflections
>>> _validation.validate_rotation(rotation)
array([[-1., -0., -0.],
       [-0., -1., -0.],
       [-0., -0., -1.]])