27 views (last 30 days)

The various quaternion functions in the Aerospace Toolbox (see <http://www.mathworks.com/help/aerotbx/flight-parameters-1.html>) 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 <http://www.mathworks.com/help/aerotbx/ug/defining-coordinate-systems.html#bqsgj4j-5>). 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.

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.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/352465-what-is-the-aerospace-blockset-quaternion-convention#comment_794457

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/352465-what-is-the-aerospace-blockset-quaternion-convention#comment_794457

Sign in to comment.