SciPy

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:
dcm : array_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.

References

[1](1, 2) Direction Cosine Matrix
[2](1, 2) F. Landis Markley, Unit Quaternion from Rotation Matrix

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)