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:
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
.rotation (Tuple) – Rotation matrix,
, and xx and xy are Tensor and have the same shape.translation (Tuple) – Translation vector
, where x, y and z are Tensor and have the same shape.update (Tensor) – The update-assisted matrix has shape
. 3-vector of x, y, and z such that the quaternion update is 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
.Tuple, the updated rotation matrix
, and xx and xy are Tensor and have the same shape.Tuple, the updated translation vector
, 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))