Main Content

angle2quat

Convert rotation angles to quaternion

Description

quaternion = angle2quat(rotationAng1,rotationAng2,rotationAng3) calculates the quaternion for three rotation angles, using the default rotation sequence of 'ZYX' (yaw, pitch, roll).. Aerospace Toolbox uses quaternions that are defined using the scalar-first convention. The rotation angles represent a series of right-hand intrinsic passive rotations from frame A to frame B. The resulting quaternion represents a right-hand passive rotation from frame A to frame B.

quaternion = angle2quat(rotationAng1,rotationAng2,rotationAng3,rotationSequence) calculates the quaternion using a rotation sequence. The rotation sequence parameter also specifies the order of the three rotation angles.

example

Examples

collapse all

Determine the quaternion from rotation angles.

yaw = 0.7854; 
pitch = 0.1; 
roll = 0;
q = angle2quat(yaw, pitch, roll)
q = 1×4

    0.9227   -0.0191    0.0462    0.3822

Determine the quaternion from rotation angles using the YXZ rotation sequence:

yaw = [0.7854 0.5]; 
pitch = [0.1 0.3]; 
roll = [0 0.1];
q = angle2quat(pitch, roll, yaw, 'YXZ')
q = 2×4

    0.9227    0.0191    0.0462    0.3822
    0.9587    0.0848    0.1324    0.2371

Input Arguments

collapse all

First rotation angles, specified as an m-by-1 array, in radians. The rotationAng1 argument represents the first rotation in rotationSequence.

Data Types: double | single

Second rotation angles, specified as an m-by-1 array, in radians. The rotationAng2 argument represents the second rotation in rotationSequence.

Data Types: double | single

Third rotation angles, specified as an m-by-1 array, in radians. The rotationAng3 argument represents the third rotation in rotationSequence.

Data Types: double | single

Rotation sequence, specified as:

  • 'ZYX'

  • 'ZYZ'

  • 'ZXY'

  • 'ZXZ'

  • 'YXZ'

  • 'YXY'

  • 'YZX'

  • 'YZY'

  • 'XYZ'

  • 'XZY'

  • 'XYX'

  • 'XZX'

where rotationAng1 is the first angle in the sequence, rotationAng2 is the second angle in the sequence, and rotationAng3 is the third angle in the sequence.

Data Types: char | string

Output Arguments

collapse all

Converted quaternion, returned as an m-by-4 matrix containing m quaternions. quaternion has its scalar number as the first column.

Version History

Introduced in R2007b