Quaternion Computation Neil Dantam [email protected] Institute for Robotics and Intelligent Machines, Georgia Institute of Technology, Atlanta, GA, USA

Quaternion Computation Neil Dantam Ntd@Gatech.Edu Institute for Robotics and Intelligent Machines, Georgia Institute of Technology, Atlanta, GA, USA

1 Quaternion Computation Neil Dantam [email protected] Institute for Robotics and Intelligent Machines, Georgia Institute of Technology, Atlanta, GA, USA Work in Progress – Updated 2014-10-01. IV-F Conjugate................6 IV-G Exponential...............6 Abstract—Quaternions are a useful representation for orienta- tion, and dual quaternions extend the representation to handle IV-H Logarithm................7 translations as well. This report discusses computations that can IV-I Chaining Transforms..........7 be performed using quaternions. To accurately compute results IV-J Transforming a point..........7 near singularities, we provide Taylor series approximations which can be efficiently computed to within machine precision. IV-K Derivatives................7 IV-K1 Product Rule.........7 IV-K2 Angular Velocity.......7 CONTENTS IV-K3 Translational Velocity....7 I Introduction 1 IV-L Integration................7 I-A Notation.................2 V Implicit Dual Quaternions 7 II Quaternions 2 V-A Chaining transforms...........7 II-A Representation..............2 V-B Transforming points...........8 II-B Multiplication..............2 V-C Conjugate................8 II-B1 Cross and dot product defi- V-D Derivatives................8 nition.............2 II-B2 Matrix definition.......2 VI Matrices and Euclidean Transforms 8 II-B3 Properties..........3 VI-A Rotation Matrix.............8 II-B4 Pure Multiplication.....3 VI-B Transformation Matrix.........8 II-C Norm...................3 VI-C Transforming Points...........8 II-D Conjugate................3 II-E Inverse..................3 VI-D Chaining Transforms..........8 II-F Exponential...............3 II-G Logarithm................3 References 8 II-H Power..................4 II-I Pure Exponential Derivative.......4 Appendix A: History 8 II-J Unit Logarithm Derivative.......4 II-K Unit Quaternion Angle.........4 Appendix B: Derivation of Quaternion Multiplication 9 II-L Product Rule...............4 B-A Derivation of Quaternion Basis Equalities9 B-B Derivation of Quaternion Multiplication9 III Representing Orientation 4 III-A Rotating a vector............5 III-B Chaining rotations............5 I. INTRODUCTION III-C Angular Derivatives...........5 III-D Axis-Angle................5 Quaternions are a convenient representation for spatial mo- III-E Spherical Linear Interpolation.....5 tion that provides some computational advantages over other III-F Integration................5 methods. III-G Finite Difference.............6 The straightforward definitions of many quaternion quan- tities, particularly exponentials, logarithms, and derivatives, IV Dual Quaternions and Euclidean Transforms 6 contain singularities where a denominator goes to zero. We can IV-A Dual Numbers..............6 avoid computational problems at these points by computing IV-B Representation..............6 key factors near the singularity using a Taylor series, though IV-C Construction...............6 this may require some careful rearrangement of terms to IV-D Multiplication..............6 identify suitable factors and series. IV-E Matrix Form...............6 A Taylor series evaluated near point a is: Quaternions Associative p ⊗ (q ⊗ r) = (p ⊗ q) ⊗ r Distributive p ⊗ (q + r) = p ⊗ q + p ⊗ r 1 (n) NOT Commutative p ⊗ q 6= q ⊗ p X f (a) ∗ ∗ ∗ f(x) = (x − a)n Conjugate Mul. (p ⊗ q) = q ⊗ p n! Conjugate Add. (p + q)∗ = q∗ + p∗ n=0 TABLE I f 0(a) f 00(a) ALGEBRAIC QUATERNION PROPERTIES = f(a) + (x − a) + (x − a)2 + 1! 2! f (3)(a) (x − a)3 + ::: (1) 3! A. Representation To evaluate the infinite series to machine precision, we only We represent a quaternion as a 4-tuple of real numbers: need to compute up the term below floating point round-off. The resulting approximation is a polynomial which can q = w + xi + yj + zk be efficiently evaluated using Horner’s Rule, Algorithm1. = (x y z w) f(n)(a) The coefficients are the terms n! and the indeterminate = H(qv; w) (7) variable is x − a. Note than many Taylor series have zero coefficents for the odd or even terms. We can produce a more Historically, qv is called the vector part of the quaternion compact Horner polynomial by omitting the zero coefficients, and qw the scalar part. using (x − a)2 as the indeterminate variable, and perhaps It is convenient to define quaternion operations in terms of multiplying the whole result by (x − a). vector and matrix operations, so we also the whole quaternion as a column vector. This also provides an in-memory storage representation. Algorithm 1: Horner’s Rule T Input: b0; b1; : : : bn : Coefficients ~q = [x y z w] (8) Input: z : Indeterminate Variable T ~qv = [x y z] (9) Output: y : Result 1 y bn A alternate convention stores terms in wxyz order, so when 2 y bn−1 + zy using different software packages, it is sometimes necessary 3 y bn−2 + zy to convert between orderings. 4 ... 5 y b0 + zy B. Multiplication From the definition of the basis elements (2), we obtain a formula for quaternion multiplication. See section B for the detailed derivation. A. Notation 1) Cross and dot product definition: We define quaternion We adopt the following abbreviations to condense notation: multiplication in terms of cross products and dot products of its elements: • Quaternions are typeset as q. • Dual Quaternions are typeset as S. ~qv × ~pv + qw~pv + pw~qv • Vectors are typeset as ~x. q ⊗ p = (10) qwpw − ~qv · ~pv • Matrices are typeset as A. • Time derivatives of variable x are given as x_. 2) Matrix definition: Expanding the above terms, we can • Sines and cosines are abbreviated as s and c. express quaternion multiplication as matrix multiplication: q ⊗ p = 2 3 II. QUATERNIONS qw −qz qy qx q q −q q Quaternions are an extension of the complex numbers, using Q ~p = 6 z w x y 7 ~p = L 6−q q q q 7 basis elements i, j, and k defined as: 4 y x w z 5 −qx −qy −qz qw 2 2 2 2 3 i = j = k = ijk = −1 (2) pw pz −py px 6−pz pw px py 7 From (2), it follows: PR~q = 6 7 ~q = 4 py −px pw pz 5 −px −py −pz pw jk = −k j = i (3) 2 3 qxpw + qypz + qwpx − qzpy ki = −ik = j (4) 6 qzpx + qwpy + qypw − qxpz 7 6 7 (11) ij = −ji = k (5) 4 qwpz + qzpw + qxpy − qypx 5 −(qypy + qxpx + qzpz − qwpw) A quaternion, then, is: This matrix form is more suitable for efficient implementa- q = w + xi + yj + zk (6) tion computation using SIMD instructions. 2 Quaternions 3) Properties: Quaternion multiplication is associative and I distributive, but it is not commutative. 4) Pure Multiplication: When multiplying by a pure quater- nion, i.e., zero scalar part, we can simplify: 2 3 qw −qz qy q q −q jq j ⊗ (v; 0) = 6 z w x7 v = v q 6−q q q 7 4 y x w 5 φ −qx −qy −qz 2 q v 3 2q v 3 2 q v 3 R y z z y w x qw q v q v q v 6 z x 7 − 6 x z7 + 6 w y 7 (12) 6 q v 7 6q v 7 6 q v 7 4 x y 5 4 y x5 4 w z 5 Fig. 1. Imaginary Plane for Quaternions −qxvx qyvy −qzvz 2 3 qw qz −qy 6−qz qw qx 7 some useful trigonometric ratios for analyzing quaternion (v; 0) ⊗ q = 6 7 v = 4 qy −qx qw 5 functions: −qx −qy −qz 2 3 2 3 2 3 φ = atan2 (jqvj ; qw) (19) vyqz vzqy vxqw jqvj 6 vzqx 7 6vxqz7 6 vyqw 7 sin (φ) = (20) 6 7 − 6 7 + 6 7 (13) jqj 4 vxqy 5 4vyqx5 4 vzqw 5 qw −vxqx vyqy −vzqz cos (φ) = (21) 2 3 jqj uyvz − uzvy 6 uzvx − uxvz 7 u × v The quaternion exponential is: (u; 0) ⊗ (v; 0) = 6 7 = (14) 4 uxvy − uyvx 5 −u · v sin (jq j) q qw v −uxvx − uyvy − uzvz e = e H qv ; cos (jqvj) (22) jqvj Thus, the case of multiplying two pure quaternions simpli- fies to the commonly used cross (×) and dot (·) products. When jqvj approaches zero, we can use the Taylor series approximation: C. Norm sin (θ) θ2 θ4 θ6 = 1 − + − + ::: (23) p θ 6 120 5040 jqj = ~q · ~q (15) For a pure quaternion, the exponential simplifies to: A unit quaternion has norm of one. ( q sin(jqv j) e = H qv ; cos (jqvj) jqv j D. Conjugate qw = 0 =) (24) jeq j = 1 ∗ q = H(−qv; qw) (16) G. Logarithm E. Inverse To compute the logarithm, first consider the angle between the vector and scalar parts of the quaternion. q∗ q−1 = (17) ~q · ~q q jq j φ = cos−1 w = sin−1 v = atan2 (jq j ; q ) (25) Note that for unit quaternions, the inverse is equal to the jqj jqj v w conjugate. The atan2 form to compute φ is generally best for numerical F. Exponential stability. The exponential shows the relationship between quaternions and complex numbers. Recall Euler’s formula for complex φ ln q = H qv; ln (jqj) (26) numbers: jqvj φ iθ When jqvj approaches zero, we can compute as follows: e = cos (θ) + i sin (θ) (18) jqv j which relates the exponential function with angles in the φ φ φ φ complex plane. Similarly for quaternions, we can consider the = jqj = jqj = sin(φ) jq j (27) jqvj v sin (φ) jqj angle between the real and imaginary parts, Figure 1, yielding jqj 3 Representing Orientation φ Representation Storage Then, sin(φ) can be approximated by Taylor series: Quaternion 4 Axis-Angle 4 θ θ2 7θ4 31θ6 Rotation Vector 3 = 1 + + + + ::: (28) Euler Angles 3 sin (θ) 6 360 15120 Rotation Matrix 9 TABLE II For a unit quaternion, the logarithm simplifies to: STORAGE REQUIREMENTS FOR ORIENTATION REPRESENTATIONS φ q = 1 =) ln(q) = H qv; 0 (29) Representation Chain Rotate Point sin (φ) Quaternion 16 multiply, 12 add 15 multiply, 15 add Rotation Matrix 27 multiply, 18 add 9 multiply, 6 add TABLE III H.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    9 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us