mindsponge.common.quat_multiply_by_vec

View Source On Gitee
mindsponge.common.quat_multiply_by_vec(quat, vec)[source]

Multiply a quaternion by a pure-vector quaternion.

\[\begin{split}\begin{split} &temp = QUAT\_MULTIPLY\_BY\_VEC * quat[..., :, None, None] * vec[..., None, :, None] \\ &result = sum(temp,axis=(-3, -2)) \\ \end{split}\end{split}\]
Parameters
  • quat (Tensor) – Quaternion.Tensor of shape \((..., 4)\).

  • vec (Tensor) – A pure-vector quaternion, \((b, c, d)\) not normalized quaternion. Quaternion can be expressed as \((1, b, c, d)\).

Returns

Tensor, the product of a quaternion with a pure vector quaternion. Shape is \((..., 4)\).

Supported Platforms:

Ascend GPU

Examples

>>> import numpy as np
>>> from mindsponge.common.geometry import quat_multiply_by_vec
>>> from mindspore.common import Tensor
>>> from mindspore import dtype as mstype
>>> np.random.seed(1)
>>> quat = Tensor(np.random.rand(4),dtype=mstype.float32)
>>> vec = Tensor(np.random.rand(3),dtype=mstype.float32)
>>> out = quat_multiply_by_vec(quat, vec)
>>> print(out)
[-0.16203496,  0.03330477, -0.05129148,  0.14417158]