scipy.spatial.transform.RigidTransform.
from_translation#
- classmethod RigidTransform.from_translation(cls, translation)#
从平移 numpy 数组初始化,没有旋转。
当将此变换应用于向量
v
时,结果与平移和向量相加相同。如果t
是平移的位移向量,则Tf.from_translation(t).apply(v) == t + v
- 参数:
- translationarray_like, shape (N, 3) or (3,)
单个平移向量或一堆平移向量。
- 返回值:
- transform
RigidTransform
实例
- transform
示例
>>> from scipy.spatial.transform import RigidTransform as Tf >>> import numpy as np
从单个平移向量创建变换
>>> 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
变换矩阵最右列的前 3x1 个点是平移向量
>>> 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
从一堆平移向量创建多个变换
>>> 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