mindsponge.common.quaternion_from_tensor
- mindsponge.common.quaternion_from_tensor(tensor, normalize=False)[源代码]
利用输入的 tensor \([(xx, xy, xz, yx, yy, yz, zz)]\) ,进行仿射变换得到新的 quaternion , rotation, translation。
\[\begin{split}\begin{split} &tensor = [(xx, xy, xz, yx, yy, yz, zz)] \\ &quaternion = (xx, xy, xz, yx) \\ &translation = (yy, yz, zz) \\ \end{split}\end{split}\]再用生成的 quaternion 和 translation 进行仿射变换。仿射变换的过程参照 quat_affine API。
- 参数:
tensor (Tensor) - 输入的初始Tensor \([(xx, xy, xz, yx, yy, yz, zz)]\) ,其中 \([(xx, xy, xz, yx)]\) 与 quaternion 一致,\((yy, yz, zz)\) 与 translation 一致。
normalize (bool) - 控制是否要在仿射变换过程求范数。默认值:
False
。
- 返回:
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相同。
- 支持平台:
Ascend
GPU
样例:
>>> import numpy as np >>> from mindsponge.common.geometry import quaternion_from_tensor >>> from mindspore.common import Tensor >>> tensor = Tensor(np.random.rand(7),dtype=mstype.float32) >>> quaternion, rotation, translation = quaternion_from_tensor(tensor) >>> print(quaternion) [4.17021990e-01, 7.20324516e-01, 1.14374816e-04, 3.02332580e-01] >>> print(rotation) (Tensor(shape=[], dtype=Float32, value= 0.60137), Tensor(shape=[], dtype=Float32, value= -0.251994), Tensor(shape=[], dtype=Float32, value= 0.435651), Tensor(shape=[], dtype=Float32, value= 0.252323), Tensor(shape=[], dtype=Float32, value= -0.436365), Tensor(shape=[], dtype=Float32, value= -0.600713), Tensor(shape=[], dtype=Float32, value= 0.43546), Tensor(shape=[], dtype=Float32, value= 0.600851), Tensor(shape=[], dtype=Float32, value= -0.253555)) >>> print(translation) (Tensor(shape=[], dtype=Float32, value= 0.146756),Tensor(shape=[], dtype=Float32, value= 0.0923386), Tensor(shape=[], dtype=Float32, value= 0.18626))