MATLAB Answers

What is the Aerospace Blockset quaternion convention?

27 views (last 30 days)
The various quaternion functions in the Aerospace Toolbox (see <>) all indicate that an input quaternion q should have "its scalar number as the first column" (i.e., [w x y z] ordering rather than [x y z w]). However, this convention doesn't always seem to produce the expected result.
For example, the quaternion:
[cos(pi/2) + 0i + 0j + sin(pi/2)] = [1/sqrt(2) + 0i + 0j + 1/sqrt(2)k]
represents a rotation about the Z-axis ([0 0 1]) by 90 degrees. Accordingly, if this quaternion is used to rotate the vector [1 1 1] in a right-handed coordinate system, the result should be [-1 1 1].
If MATLAB's "quatrotate" function is used to perform this rotation, the result is the following:
>> quatrotate([1/sqrt(2) 0 0 1/sqrt(2)], [1 1 1])
ans =
1.0000 -1.0000 1.0000
This result corresponds to a rotation about the Z-axis by -90 degrees, not 90 as expected.
Another example: rotating [0 0 1] by the quaternion [1/sqrt(2) 1/sqrt(2) 0 0] (which represents a 90 degree rotation about the x axis) yields the following:
>> quatrotate([1/sqrt(2) 1/sqrt(2) 0 0],[0 0 1])
ans =
0 1.0000 0
when the expected result is [0 -1 0].
The result from quatrotate (at least for these two examples) seems to be determined using a left-handed coordinate system, yet the documentation for the Aerospace Toolbox explicitly states that "[t]he Aerospace Toolbox software uses right-handed (RH) Cartesian coordinate systems" (see <>). Other quaternion functions exhibit similar behaviour (e.g., using the quaternion from the first example, quat2dcm produces a matrix that performs a -90 degree rotation about the z axis).
Have I missed a part of the documentation that explains this behavior, or am I using these functions incorrectly? Any assistance would be appreciated.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 11 Aug 2017
Most common rotations are made for aerospace applications. Usually, the rotations are mostly made from earth (or inertial reference frame) to body reference frame. This causes for the DCM's to be the inverse or transpose of what the usual non-aerospace applications are used for. The to and from direction cosine matrix functions have this approach, as does the "quatrotate" function. Therefore the results, even though they "look" as if they are calculated using left-hand notation, have been calculated using right hand notation. They were calculated to use the most common approach in aerospace applications (inertial to body). 
Workflow difference (quatrotate): There are two conventions for performing rotations. Aerospace Toolbox is using the rotation "convention most commonly used" as stated by Stevens and Lewis in quatrotate and the customer is using the other one. A potential solution is to make quatrotate more flexible with the type of rotation available as a choice. Would this be a workable solution for the customer? 
1. "quatrotate" - rotates vector in inertial frame to body frame. Rational behind the choice of rotation equation in Aerospace Toolbox: 
From: Stevens, Brian L., Frank L. Lewis, Aircraft Control and Simulation, Wiley-Interscience, 2nd Edition, page 18. 
Workflow differences (DCM): The quat2dcm and dcm2quat functions are not incorrect, but does not return what the is expected. Below are the descriptions for each function:
quat2dcm - outputs DCM (inertial to body) from quaternion (body to inertial orientation -> right-handed rotation) 
% QUAT2DCM Convert quaternion to direction cosine matrix. 
% N = QUAT2DCM( Q ) calculates the direction cosine matrix, N, for a 
% given quaternion, Q. Input Q is an M-by-4 matrix containing M 
% quaternions. N returns a 3-by-3-by-M matrix of direction cosine 
% matrices. The direction cosine matrix performs the coordinate 
% transformation of a vector in inertial axes to a vector in body axes. 
% Each element of Q must be a real number. Additionally, Q has its 
% scalar number as the first column.
dcm2quat - outputs quaternion (body to inertial orientation -> right-handed rotation) from DCM (inertial to body) 
% DCM2QUAT Convert direction cosine matrix to quaternion. 
% Q = DCM2QUAT( N ) calculates the quaternion, Q, for given 
% direction cosine matrix, N. Input N is a 3-by-3-by-M matrix of 
% orthogonal direction cosine matrices. The direction cosine matrix performs the 
% coordinate transformation of a vector in inertial axes to a vector in 
% body axes. Q returns an M-by-4 matrix containing M quaternions. Q has 
% its scalar number as the first column.
Workflows are the same: The following functions are not affected by the handedness of the quaternion.  * quatconj  * quatdivide  * quatinv  * quatmod  * quatmultiply * Aerospace Toolbox uses the calculation from Steven's calculation which matches the customer derivation, not the paper in question  * quatnorm  * quatnormalize 
MathWorks is constantly taking into account the feedback regarding relevant functions in Aerospace Toolbox and blocks in Aerospace Blockset and we will enhance product documentation to include more information.

  1 Comment

James Tursa
James Tursa on 6 Feb 2020
quatrotate, and other Aerospace Toolbox functions that operate on quaternions, treat the quaternions as passive coordinate system transformations, not as active vector rotations (in spite of the unfortunate misleading language in the documentation). See my Answer for an explanation of this. The Aerospace Toolbox functions are fine. The only thing I would suggest changing is the descriptions in the documentation. You should be using the phrase "coordinate system transformation" instead of the phrase "vector rotation" in your docs.
The Robotics Toolbox uses a quaternion convention that is the conjugate of the Aerospace Toolbox convention. The Robotics Toolbox quaternions can be viewed as "Active", rotating a vector within the same frame.

Sign in to comment.


No tags entered yet.