from_rotation#
- static RigidTransform.from_rotation(rotation)[source]#
Initialize from a rotation, without a translation.
When applying this transform to a vector
v
, the result is the same as if the rotation was applied to the vector.Tf.from_rotation(r).apply(v) == r.apply(v)
- Parameters:
- rotation
Rotation
instance A single rotation or a stack of rotations.
- rotation
- Returns:
- transform
RigidTransform
instance
- transform
Notes
Array API Standard Support
from_rotation
has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1
and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
✅
PyTorch
✅
✅
JAX
✅
✅
Dask
⛔
n/a
See Support for the array API standard for more information.
Examples
>>> from scipy.spatial.transform import RigidTransform as Tf >>> from scipy.spatial.transform import Rotation as R >>> import numpy as np
Creating a transform from a single rotation:
>>> r = R.from_euler("ZYX", [90, 30, 0], degrees=True) >>> r.apply([1, 0, 0]) array([0. , 0.8660254, -0.5 ]) >>> tf = Tf.from_rotation(r) >>> tf.apply([1, 0, 0]) array([0. , 0.8660254, -0.5 ]) >>> tf.single True
The upper 3x3 submatrix of the transformation matrix is the rotation matrix:
>>> np.allclose(tf.as_matrix()[:3, :3], r.as_matrix(), atol=1e-12) True
Creating multiple transforms from a stack of rotations:
>>> r = R.from_euler("ZYX", [[90, 30, 0], [45, 30, 60]], degrees=True) >>> r.apply([1, 0, 0]) array([[0. , 0.8660254 , -0.5 ], [0.61237244, 0.61237244, -0.5 ]]) >>> tf = Tf.from_rotation(r) >>> tf.apply([1, 0, 0]) array([[0. , 0.8660254 , -0.5 ], [0.61237244, 0.61237244, -0.5 ]]) >>> tf.single False >>> len(tf) 2