mindsponge.common.quat_to_rot

mindsponge.common.quat_to_rot(normalized_quat, use_numpy=False)[source]

Convert a normalized quaternion to a rotation matrix.

\[\begin{split}\begin{split} &xx = 1 - 2 * y * y - 2 * z * z \\ &xy = 2 * x * y + 2 * w * z \\ &xz = 2 * x * z - 2 * w * y \\ &yx = 2 * x * y - 2 * w * z \\ &yy = 1 - 2 * x * x - 2 * z * z \\ &yz = 2 * z * y + 2 * w * x \\ &zx = 2 * x * z + 2 * w * y \\ &zy = 2 * y * z - 2 * w * x \\ &zz = 1 - 2 * x * x - 2 * y * y \\ \end{split}\end{split}\]
Parameters
  • normalized_quat (tensor) – normalized quaternion, shape \((N_{res}, 4)\).

  • use_numpy (bool) – use numpy or not, Default: “False”.

Returns

tuple, rotation \((xx, xy, xz, yx, yy, yz, zx, zy, zz)\), every element shape \((N_{res}, )\).

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> import mindspore as ms
>>> from mindspore import Tensor
>>> from mindsponge.common.geometry import quat_to_rot
>>> input_0 = Tensor(np.ones((256, 4)), ms.float32)
>>> output = quat_to_rot(input_0)
>>> print(len(output), output[0].shape)
9, (256,)