mindsponge.common.pre_compose

mindsponge.common.pre_compose(quaternion, rotation, translation, update)[source]

Return a new QuatAffine which applies the transformation update first.

The process of obtaining the updated translation vector and rotation matrix is as follows:

\[\begin{split}\begin{split} &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 \\ \end{split}\end{split}\]

vector_quaternion_update and quaternion are multiplied by the quat_multiply_by_vec function, Affine transformation is performed using the generated new_quaternion and new_translation. The process of affine transformation is referred to the quat_affine api.

Parameters
  • quaternion (Tensor) – The initial quaternion to be updated, shape \([(..., 4)]\).

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

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

  • update (Tensor) – The update-assisted matrix has shape \([(..., 6)]\). 3-vector of x, y, and z such that the quaternion update is \((1, x, y, z)\) and zero for the 3-vector is the identity quaternion. 3-vector for translation concatenated.

Returns

  • Tensor, new quaternion.The updated Tensor tuple has shape \([(..., 4)]\).

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

  • Tuple, the updated 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 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))