from_translation#
- static RigidTransform.from_translation(translation)[source]#
Initialize from a translation numpy array, without a rotation.
When applying this transform to a vector
v
, the result is the same as if the translation and vector were added together. Ift
is the displacement vector of the translation, then:Tf.from_translation(t).apply(v) == t + v
- Parameters:
- translationarray_like, shape (N, 3) or (3,)
A single translation vector or a stack of translation vectors.
- Returns:
- transform
RigidTransform
instance
- transform
Notes
Array API Standard Support
from_translation
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 >>> import numpy as np
Creating a transform from a single translation vector:
>>> t = np.array([2, 3, 4]) >>> t + np.array([1, 0, 0]) array([3, 3, 4]) >>> tf = Tf.from_translation(t) >>> tf.apply([1, 0, 0]) array([3., 3., 4.]) >>> tf.single True
The top 3x1 points in the rightmost column of the transformation matrix is the translation vector:
>>> tf.as_matrix() array([[1., 0., 0., 2.], [0., 1., 0., 3.], [0., 0., 1., 4.], [0., 0., 0., 1.]]) >>> np.allclose(tf.as_matrix()[:3, 3], t) True
Creating multiple transforms from a stack of translation vectors:
>>> t = np.array([[2, 3, 4], [1, 0, 0]]) >>> t + np.array([1, 0, 0]) array([[3, 3, 4], [2, 0, 0]]) >>> tf = Tf.from_translation(t) >>> tf.apply([1, 0, 0]) array([[3., 3., 4.], [2., 0., 0.]]) >>> np.allclose(tf.as_matrix()[:, :3, 3], t) True >>> tf.single False >>> len(tf) 2