scipy.spatial.transform.Rotation.
from_matrix#
- classmethod Rotation.from_matrix(cls, matrix)#
從旋轉矩陣初始化。
三維旋轉可以使用 3 x 3 真實正交矩陣 [1] 表示。如果輸入不是真實正交矩陣,則會使用 [2] 中描述的方法建立近似值。
- 參數:
- matrixarray_like,形狀為 (N, 3, 3) 或 (3, 3)
單個矩陣或矩陣堆疊,其中
matrix[i]
是第 i 個矩陣。
- 回傳值:
- rotation
Rotation
實例 包含由旋轉矩陣表示的旋轉的物件。
- rotation
註解
此函數之前稱為 from_dcm。
在 1.4.0 版本中新增。
參考文獻
[2]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.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)
如果輸入矩陣不是特殊正交矩陣(正交且行列式等於 +1),則會儲存特殊正交估計值
>>> a = np.array([ ... [0, -0.5, 0], ... [0.5, 0, 0], ... [0, 0, 0.5]]) >>> np.linalg.det(a) 0.12500000000000003 >>> r = R.from_matrix(a) >>> matrix = r.as_matrix() >>> matrix array([[-0.38461538, -0.92307692, 0. ], [ 0.92307692, -0.38461538, 0. ], [ 0. , 0. , 1. ]]) >>> np.linalg.det(matrix) 1.0000000000000002
也可以有一個包含單個旋轉的堆疊
>>> 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)