scipy.spatial.transform.Rotation.from_dcm¶
-
classmethod
Rotation.
from_dcm
(dcm)[source]¶ Initialize from direction cosine matrices.
Rotations in 3 dimensions can be represented using 3 x 3 proper orthogonal matrices [1]. If the input is not proper orthogonal, an approximation is created using the method described in [2].
- Parameters
- dcmarray_like, shape (N, 3, 3) or (3, 3)
A single matrix or a stack of matrices, where
dcm[i]
is the i-th matrix.
- Returns
- rotation
Rotation
instance Object containing the rotations represented by the input direction cosine matrices.
- rotation
References
- 1(1,2)
https://en.wikipedia.org/wiki/Rotation_matrix#In_three_dimensions
- 2(1,2)
F. Landis Markley, “Unit Quaternion from Rotation Matrix”, Journal of guidance, control, and dynamics vol. 31.2, pp. 440-442, 2008.
Examples
>>> from scipy.spatial.transform import Rotation as R
Initialize a single rotation:
>>> r = R.from_dcm([ ... [0, -1, 0], ... [1, 0, 0], ... [0, 0, 1]]) >>> r.as_dcm().shape (3, 3)
Initialize multiple rotations in a single object:
>>> r = R.from_dcm([ ... [ ... [0, -1, 0], ... [1, 0, 0], ... [0, 0, 1], ... ], ... [ ... [1, 0, 0], ... [0, 0, -1], ... [0, 1, 0], ... ]]) >>> r.as_dcm().shape (2, 3, 3)
If input matrices are not special orthogonal (orthogonal with determinant equal to +1), then a special orthogonal estimate is stored:
>>> a = np.array([ ... [0, -0.5, 0], ... [0.5, 0, 0], ... [0, 0, 0.5]]) >>> np.linalg.det(a) 0.12500000000000003 >>> r = R.from_dcm(a) >>> dcm = r.as_dcm() >>> dcm array([[-0.38461538, -0.92307692, 0. ], [ 0.92307692, -0.38461538, 0. ], [ 0. , 0. , 1. ]]) >>> np.linalg.det(dcm) 1.0000000000000002
It is also possible to have a stack containing a single rotation:
>>> r = R.from_dcm([[ ... [0, -1, 0], ... [1, 0, 0], ... [0, 0, 1]]]) >>> r.as_dcm() array([[[ 0., -1., 0.], [ 1., 0., 0.], [ 0., 0., 1.]]]) >>> r.as_dcm().shape (1, 3, 3)