scipy.spatial.transform.RigidTransform.
__mul__#
- RigidTransform.__mul__(self, RigidTransform other)#
将此变换与另一个变换组合。
如果 p 和 q 是两个变换,那么“q 之后是 p”的组合等价于 p * q。就变换矩阵而言,该组合可以表示为
p.as_matrix() @ q.as_matrix()
。就平移和旋转而言,应用于向量
v
的组合等价于p.translation + p.rotation.apply(q.translation) + (p.rotation * q.rotation).apply(v)
。此函数支持一次组合多个变换。以下情况是可能的
要么
p
要么q
包含单个或长度为 1 的变换。在这种情况下,结果包含另一个对象中每个变换与该单个变换组合的结果。如果两者都是单个变换,则结果是单个变换。p
和q
都包含N
个变换。在这种情况下,每个变换p[i]
与相应的变换q[i]
组合,结果包含N
个变换。
- 参数:
- other
RigidTransform
实例 包含要与此变换组合的变换的对象。
- other
- 返回值:
RigidTransform
实例组合变换。
示例
>>> from scipy.spatial.transform import RigidTransform as Tf >>> from scipy.spatial.transform import Rotation as R >>> import numpy as np
组合两个变换
>>> tf1 = Tf.from_translation([1, 0, 0]) >>> tf2 = Tf.from_translation([0, 1, 0]) >>> tf = tf1 * tf2 >>> tf.translation array([1., 1., 0.]) >>> tf.single True
应用于向量时,两个变换的组合以从右到左的顺序应用。
>>> t1, r1 = [1, 2, 3], R.from_euler('z', 60, degrees=True) >>> t2, r2 = [0, 1, 0], R.from_euler('x', 30, degrees=True) >>> tf1 = Tf.from_components(t1, r1) >>> tf2 = Tf.from_components(t2, r2) >>> tf = tf1 * tf2 >>> tf.apply([1, 0, 0]) array([0.6339746, 3.3660254, 3. ]) >>> tf1.apply(tf2.apply([1, 0, 0])) array([0.6339746, 3.3660254, 3. ])
当至少一个变换不是单个变换时,结果是变换堆栈。
>>> tf1 = Tf.from_translation([1, 0, 0]) >>> tf2 = Tf.from_translation([[0, 2, 0], [0, 0, 3]]) >>> tf = tf1 * tf2 >>> tf.translation array([[1., 2., 0.], [1., 0., 3.]]) >>> tf.single False >>> len(tf) 2