You are on page 1of 3

Quaternions

Sebastian O.H. Madgwick September 24, 2011


A quaternion is a four-dimensional complex number that can be used to represent the orientation of a rigid body or coordinate frame in three-dimensional space. An arbitrary orientation of frame B relative to frame A can be achieved through a rotation of angle around an axis A r dened in frame A. This is represented graphically in gure 1 where the mutually orthogonal unit vectors xA , yA and zA , and xB , yB and zB dene the principle axis of coordinate frames A and B respectively. The quaternion describing this orientation, A q, B A is dened by equation (1) where rx , ry and rz dene the components of the unit vector r in the x, y and z axes of frame A respectively. A notation system of leading super-scripts and sub-scripts adopted from Craig [1] is used to denote the relative frames of orientations and vectors. A leading sub-script denotes the frame being described and a leading super-script denotes the frame this is with reference to. For example, A q describes the orientation of B A frame B relative to frame A and r is a vector described in frame A. Quaternion arithmetic often requires that a quaternion describing an orientation is rst normalised. It is therefore conventional for all quaternions describing an orientation to be of unit length.
zB zA

yB yA

xA xB

Figure 1: The orientation of frame B is achieved by a rotation, from alignment with frame A, of angle around the axis A r.
A Bq = q0 q1 q2 q3 = cos 2 rx sin 2 ry sin 2 rz sin 2

(1)

The quaternion conjugate, denoted by , can be used to swap the relative frames described by an orientation. For example, B q is the conjugate of A q and describes the orientation of A B A is dened by equation (2). frame A relative to frame B. The conjugate of B q 1

A Bq

= B q = q0 q1 q2 q3 A

(2)

The quaternion product, denoted by , can be used to dene compound orientations. For example, for two orientations described by A q and B q, the compounded orientation A q B C C can be dened by equation (3).
A Cq

= Bq Aq C B

(3)

For two quaternions, a and b, the quaternion product can be determined using the Hamilton rule and dened as equation (4). A quaternion product is not commutative; that is, a b = b a. a b = a0 a1 a2 a3 b 0 b 1 b 2 b 3 T a0 b 0 a1 b 1 a2 b 2 a3 b 3 a b + a1 b 0 + a2 b 3 a3 b 2 = 0 1 a0 b 2 a1 b 3 + a2 b 0 + a3 b 1 a0 b3 + a1 b2 a2 b1 + a3 b0

(4)

A three dimensional vector can be rotated by a quaternion using the relationship described in equation (5) [2]. A v and B v are the same vector described in frame A and frame B respectively where each vector contains a 0 inserted as the rst element to make them 4 element row vectors.
B

v = A q Av A q B B

(5)

The orientation described by A q can B by equation (6) [2]. 2 2 2q0 1 + 2q1 A B R = 2(q1 q2 q0 q3 ) 2(q1 q3 + q0 q2 )

be represented as the rotation matrix A R dened B 2(q1 q2 + q0 q3 ) 2(q1 q3 q0 q2 ) 2 2 2q0 1 + 2q2 2(q2 q3 + q0 q1 ) 2 2 2(q2 q3 q0 q1 ) 2q0 1 + 2q3

(6)

A quaternion may be obtain from a rotation matrix using the inverse of the relationships dened in (6); however, in some practical applications an available rotation matrix may not be orthogonal and so a more robust method is prefered. Bar-Itzhack provides a method [3] to extract the optimal, best t quaternion from an imprecise and non-orthogonal rotation matrix. The method requires the construction of the symmetric 4 by 4 matrix K (equation (7)) where rmn corresponds to the element of the mth row and nth column of A R. The optimal B quaternion, A q, is found as the normalised Eigen vector corresponding to the maximum B Eigen value of K. This is dened by equation (8) where v0 to v3 dene the elements of the normalised Eigen vector. r11 r22 r33 r21 + r12 r31 + r13 r23 r32 1 r21 + r12 r22 r11 r33 r32 + r23 r31 r13 (7) K= r31 + r13 r32 + r23 r33 r11 r22 r12 r21 3 r23 r32 r31 r13 r12 r21 r11 + r22 + r33 2

A Bq

= v3 v0 v1 v2

(8)

The ZYX Euler angles , and describe an orientation of frame B achieved by the sequential rotations, from alignment with frame A, of around zB , around yB , and A around xB . This Euler angle representation of B q can be calculated [4] using equations (9) to (11).
2 2 = atan2 2(q2 q3 q0 q1 ), 2q0 1 + 2q3

(9)

= arctan

2(q1 q3 + q0 q2 ) 1 (2q1 q3 + 2q0 q2 )2

(10) (11)

2 2 = atan2 2(q1 q2 q0 q3 ), 2q0 1 + 2q1

References
[1] John J. Craig. Introduction to Robotics Mechanics and Control. Pearson Education International, 2005. [2] J. B. Kuipers. Quaternions and Rotation Sequences: A Primer with Applications to Orbits, Aerospace and Virtual Reality. Princeton University Press, 1999. [3] Itzhack Y Bar-Itzhack. New method for extracting the quaternion from a rotation matrix. AIAA Journal of Guidance, Control and Dynamics, 23(6):10851087, Nov.Dec 2000. (Engineering Note). [4] Mei Wang, Yunchun Yang, R.R. Hatch, and Yanhua Zhang. Adaptive lter for a miniature mems based attitude and heading reference system. Position Location and Navigation Symposium, 2004. PLANS 2004, pages 193 200, apr. 2004.

You might also like