scipy.spatial.transform.Rotation.

from_matrix#

classmethod Rotation.from_matrix(cls, matrix)#

从旋转矩阵初始化。

3 维旋转可以用 3 x 3 正交矩阵表示 [1]。如果输入不是正交的,则通过使用 [2] 中描述的方法对输入矩阵进行正交化来创建近似值,然后使用 [3] 中描述的算法将正交旋转矩阵转换为四元数。矩阵必须是右手系的。

参数:
matrixarray_like, shape (N, 3, 3) 或 (3, 3)

单个矩阵或矩阵堆栈,其中 matrix[i] 是第 i 个矩阵。

返回:
rotationRotation 实例

包含由旋转矩阵表示的旋转的对象。

注释

此函数以前称为 from_dcm。

在 1.4.0 版本中添加。

参考文献

[3]

F. Landis Markley, “Unit Quaternion from Rotation Matrix”, Journal of guidance, control, and dynamics vol. 31.2, pp. 440-442, 2008.

示例

>>> from scipy.spatial.transform import Rotation as R
>>> import numpy as np

初始化单个旋转

>>> r = R.from_matrix([
... [0, -1, 0],
... [1, 0, 0],
... [0, 0, 1]])
>>> r.single
True
>>> r.as_matrix().shape
(3, 3)

在单个对象中初始化多个旋转

>>> r = R.from_matrix([
... [
...     [0, -1, 0],
...     [1, 0, 0],
...     [0, 0, 1],
... ],
... [
...     [1, 0, 0],
...     [0, 0, -1],
...     [0, 1, 0],
... ]])
>>> r.as_matrix().shape
(2, 3, 3)
>>> r.single
False
>>> len(r)
2

如果输入矩阵不是特殊的正交矩阵(行列式等于 +1 的正交矩阵),则会存储特殊的正交估计

>>> a = np.array([
... [0, -0.5, 0],
... [0.5, 0, 0],
... [0, 0, 0.5]])
>>> np.linalg.det(a)
0.125
>>> r = R.from_matrix(a)
>>> matrix = r.as_matrix()
>>> matrix
array([[ 0., -1.,  0.],
       [ 1.,  0.,  0.],
       [ 0.,  0.,  1.]])
>>> np.linalg.det(matrix)
1.0

也可以有一个包含单个旋转的堆栈

>>> r = R.from_matrix([[
... [0, -1, 0],
... [1, 0, 0],
... [0, 0, 1]]])
>>> r.as_matrix()
array([[[ 0., -1.,  0.],
        [ 1.,  0.,  0.],
        [ 0.,  0.,  1.]]])
>>> r.as_matrix().shape
(1, 3, 3)