Rotate#

Functions for rotating 2D or 3D data around a specified axis/center using spline interpolation.

splineops.rotate.rotate.rotate(data: ndarray[tuple[int, ...], dtype[_ScalarType_co]], angle: float, axis: Tuple[float, float, float] | None = None, center: Tuple[float, float, float] | None = None, degree: int = 3, mode: str = 'zero') ndarray[tuple[int, ...], dtype[_ScalarType_co]]#

Rotate 2D or 3D data around a specified center using spline interpolation.

Parameters:
  • data (ndarray) – 2D or 3D input data array to rotate.

  • angle (float) – Rotation angle in degrees.

  • axis (tuple of float, optional) – The axis of rotation for 3D data. Defaults to (0, 0, 1).

  • center (tuple of float, optional) – The center of rotation. Defaults to the array center.

  • degree (int, optional) – B-spline degree (0 to 7). Default is 3.

  • mode (str, optional) – Boundary handling mode (e.g., “zero”, “mirror”). Default is “zero”.

Returns:

rotated_data – The data array after rotation.

Return type:

ndarray

Examples

Rotate a 2D array by 45 degrees:

>>> import numpy as np
>>> from splineops.interpolate.rotate import rotate
>>> data = np.array([[1, 2], [3, 4]])
>>> rotated_data = rotate(data, angle=45)
>>> rotated_data.shape
(2, 2)

Rotate a 3D array around a custom axis:

>>> data_3d = np.random.rand(4, 4, 4)
>>> rotated_data_3d = rotate(data_3d, angle=30, axis=(1, 0, 0))
>>> rotated_data_3d.shape
(4, 4, 4)

See also#

TensorSpline

The base class used internally for spline interpolation.