mindsponge.common.rots_from_two_vecs

View Source On Gitee
mindsponge.common.rots_from_two_vecs(e0_unnormalized, e1_unnormalized)[source]

Put in two vectors \(\vec a = (a_x, a_y, a_z)\) and \(\vec b = (b_x, b_y, b_z)\). Calculate the rotation matrix between local coordinate system, in which the x-y plane consists of two input vectors and global coordinate system.

Calculate the unit vector \(\vec e_0 = \frac{\vec a}{|\vec a|}\) as the unit vector of x axis.

Then calculate the projected length of \(\vec b\) on a axis. \(c = |\vec b| \cos\theta = \vec b \cdot \frac{\vec a}{|\vec a|}\) .

So the projected vector of \(\vec b\) on a axis is \(c\vec e_0\). The vector perpendicular to e0 is \(\vec e_1' = \vec b - c\vec e_0\) .

The unit vector of \(\vec e_1'\) is \(\vec e_1 = \frac{\vec e_1'}{|\vec e_1'|}\), which is the y axis of the local coordinate system.

Finally get the unit vector of z axis \(\vec e_2\) by calculating cross product of \(\vec e_1\) and \(\vec e_0\).

The final rots is \((e_{0x}, e_{1x}, e_{2x}, e_{0y}, e_{1y}, e_{2y}, e_{0z}, e_{1z}, e_{2z})\).

Parameters
  • e0_unnormalized (tuple) – vectors \(\vec a\) as x-axis of x-y plane, length is 3. Data type is constant or Tensor with same shape.

  • e1_unnormalized (tuple) – vectors \(\vec b\) forming x-y plane, length is 3. Data type is constant or Tensor with same shape.

Returns

tuple, rotation matrix \((e_{0x}, e_{1x}, e_{2x}, e_{0y}, e_{1y}, e_{2y}, e_{0z}, e_{1z}, e_{2z})\) .

Data type is constant or Tensor with same shape.

Supported Platforms:

Ascend GPU

Examples

>>> import mindsponge
>>> v1 = (1, 2, 3)
>>> v2 = (3, 4, 5)
>>> ans = mindsponge.common.rots_from_two_vecs(v1, v2)
>>> print(ans)
(0.4242640686695021, -0.808290367995452, 0.40824828617045156, 0.5656854248926695,
 -0.1154700520346678, -0.8164965723409039, 0.7071067811158369, 0.5773502639261153,
 0.4082482861704521)