mindsponge.common.quaternion_from_tensor

mindsponge.common.quaternion_from_tensor(tensor, normalize=False)[source]

Take the input ‘tensor’ \([(xx, xy, xz, yx, yy, yz, zz)]\) to get the new ‘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}\]

Affine transformation is performed using the generated quaternion and translation. The process of affine transformation is referred to the quat_affine api.

Parameters
  • tensor (Tensor) – An initial Tensor \([(xx, xy, xz, yx, yy, yz, zz)]\) . \([(xx, xy, xz, yx)]\) is the same with quaternion. \((yy, yz, zz)\) is the same with translation.

  • normalize (bool) – Control whether to find the norm during quat_affine. Default: False.

Returns

  • Tensor, new quaternion.Tensor of shape \((..., 4)\) .

  • Tuple, new rotation, \((xx, xy, xz, yx, yy, yz, zx, zy, zz)\), and xx and xy are Tensor and have the same shape.

  • Tuple, translation vector \([(x, y, z)]\), where x, y and z are Tensor and have the same shape.

Supported Platforms:

Ascend GPU

Examples

>>> 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))