Main Content

Quaternions to Direction Cosine Matrix

Convert quaternion vector to direction cosine matrix

  • Quaternions to Direction Cosine Matrix block

Libraries:
Aerospace Blockset / Utilities / Axes Transformations

Description

The Quaternions to Direction Cosine Matrix block transforms a four-element unit quaternion vector (q0, q1, q2, q3) into a 3-by-3 direction cosine matrix (DCM). The outputted DCM performs the coordinate transformation of a vector in inertial axes to a vector in body axes. Aerospace Blockset™ uses quaternions that are defined using the scalar-first convention. This block normalizes all quaternion inputs. For more information, see Algorithms.

Ports

Input

expand all

Quaternion, specified as a 4-by-1 vector.

Data Types: double

Output

expand all

Direction cosine matrix, returned as a 3-by-3 matrix.

Data Types: double

Algorithms

Using quaternion algebra, if a point P is subject to the rotation described by a quaternion q, it changes to P′ given by the following relationship:

P=qPqcq=q0+iq1+jq2+kq3qc=q0iq1jq2kq3P=0+ix+jy+kz

Expanding P′ and collecting terms in x, y, and z gives the following for P′ in terms of P in the vector quaternion format:

P=[0xyz]=[0(q02+q12q22q32)x+2(q1q2q0q3)y+2(q1q3+q0q2)z2(q0q3+q1q2)x+(q02q12+q22q32)y+2(q2q3q0q1)z2(q1q3q0q2)x+2(q0q1+q2q3)y+(q02q12q22+q32)z]

Since individual terms in P′ are linear combinations of terms in x, y, and z, a matrix relationship to rotate the vector (x, y, z) to (x′, y′, z′) can be extracted from the preceding. This matrix rotates a vector in inertial axes, and hence is transposed to generate the DCM that performs the coordinate transformation of a vector in inertial axes into body axes.

DCM=[(q02+q12q22q32)2(q1q2+q0q3)2(q1q3q0q2)2(q1q2q0q3)(q02q12+q22q32)2(q2q3+q0q1)2(q1q3+q0q2)2(q2q3q0q1)(q02q12q22+q32)]

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a