mindsponge.common.pre_compose
- mindsponge.common.pre_compose(quaternion, rotation, translation, update)[源代码]
利用旋转矩阵rotation和辅助矩阵update更新输入的四元数quaternion和平移向量translation,并进行新的仿射变化过程,得到更新的平移向量。
旋转矩阵的过程如下:
\[update = (xx, xy, xz, yx, yy, yz) vector_quaternion_update = (xx, xy, xz) x = (yx) y = (yy) z = (yz) trans_update = [(x, y, z)] new_quaternion = quaternion + vector_quaternion_update * quaternion rotated_trans_update = rotation * trans_update new_translation = translation + rotated_trans_update\]其中 vector_quaternion_update 与 quaternion 的相乘使用 quat_multiply_by_vec 函数相乘, rotation 与 trans_update 的相乘用 rots_mul_vecs 函数, translation 与 rotated_trans_update 相加过程使用 vecs_add 函数。 再用生成的 new_quaternion 和 new_translation 进行仿射变换。仿射变换的过程参照 quat_affine API。
- 参数:
quaternion (Tensor) - 初始的待更新四元数,shape为 \([(..., 4)]\) 的Tensor。
rotation (Tuple) - 旋转矩阵 \((xx, xy, xz, yx, yy, yz, zx, zy, zz)\) ,且xx, xy等均为Tensor且shape相同。
translation (Tuple) - 平移向量 \((x, y, z)\) ,其中x, y, z均为Tensor,且shape相同。
update (Tensor) - 用于辅助更新的矩阵,shape为 \([(..., 6)]\) 的Tensor,最后一维前三个元素为代表旋转矩阵的四元数三维向量表示,参考 quat_multiply_by_vec 。
- 返回:
quaternion (Tensor) - 更新后的四元数,shape为 \([(..., 4)]\) 的Tensor。
rotation (Tensor) - 更新后的旋转矩阵 \((xx, xy, xz, yx, yy, yz, zx, zy, zz)\) ,且xx, xy等均为Tensor且shape相同。
translation (Tensor) - 更新后的平移向量 \((x, y, z)\) ,其中x, y, z均为Tensor,且shape相同。
- 支持平台:
Ascend
GPU
样例:
>>> import numpy as np >>> from mindsponge.common.geometry import pre_compose >>> from mindspore.common import Tensor >>> from mindspore import dtype as mstype >>> np.random.seed(1) >>> quaternion = Tensor(np.random.rand(4),dtype=mstype.float32) >>> update = Tensor(np.random.rand(6),dtype=mstype.float32) >>> rotation = Tensor(np.random.rand(9),dtype=mstype.float32) >>> translation = Tensor(np.random.rand(3),dtype=mstype.float32) >>> quaternion, rotation, translation = pre_compose(quaternion,rotation,translation,update) >>> print(quaternion) [ 0.27905196 0.82475466 -0.05600705 0.48864394] >>> print(rotation) (Tensor(shape=[], dtype=Float32, value= 0.516181), Tensor(shape=[], dtype=Float32, value= -0.365098), Tensor(shape=[], dtype=Float32, value= 0.774765), Tensor(shape=[], dtype=Float32, value= 0.18033), Tensor(shape=[], dtype=Float32, value= -0.837986), Tensor(shape=[], dtype=Float32, value= -0.515034), Tensor(shape=[], dtype=Float32, value= 0.837281), Tensor(shape=[], dtype=Float32, value= 0.405564), Tensor(shape=[], dtype=Float32, value= -0.366714)) >>> print(translation) (Tensor(shape=[], dtype=Float32, value= 0.724994), Tensor(shape=[], dtype=Float32, value= 1.47631), Tensor(shape=[], dtype=Float32, value= 1.40978))