scipp.spatial.rotation#

scipp.spatial.rotation(*, value)#

Creates a rotation-type variable from the provided quaternion coefficients.

The quaternion coefficients are provided in scalar-last order (x, y, z, w), where x, y, z and w form the quaternion

\[q = w + xi + yj + zk.\]

Attention

The quaternion must be normalized in order to represent a rotation. You can use, e.g.:

q = np.array([1, 2, 3, 4])
rot = sc.spatial.rotation(value=q / np.linalg.norm(q))
Parameters:

value (ndarray[tuple[Any, ...], dtype[TypeVar(_Float, bound= float64 | float32, covariant=True)]] | Sequence[TypeVar(_Float, bound= float64 | float32, covariant=True)]) – A NumPy array or list with length 4, corresponding to the quaternion coefficients (x*i, y*j, z*k, w)

Returns:

Variable – A scalar variable of dtype rotation3.

See also

scipp.spatial.rotations

Create multiple rotation transformations.

scipp.spatial.rotations_from_rotvecs

Create rotations from rotation vectors.

Examples

Create an identity rotation (no rotation):

>>> import scipp as sc
>>> rot = sc.spatial.rotation(value=[0, 0, 0, 1])
>>> rot
<scipp.Variable> ()  rotation3  [dimensionless]  (1+0i+0j+0k)

Create a 180 degree rotation around the z-axis and apply it to a vector:

>>> rot_180z = sc.spatial.rotation(value=[0, 0, 1, 0])
>>> vec_x = sc.vector(value=[1, 0, 0])
>>> rot_180z * vec_x
<scipp.Variable> ()    vector3  [dimensionless]  (-1, 0, 0)