Rotations of Moment of Inertia Tensor using Quaternions Mikica B Kocic, 202-04-22, v0.3 There is a wonderful connection between complex numbers (and quaternions, as their extension) and geometry in which, translations correspond to additions, rotations and scaling to multiplications, and reflections to conjugations. However, the beauty of describing spatial rotations with quaternions is shadowed by an expression like: - 2 Iy 2 + z 2 M 2 xy- 2 wz 2 wy+ 2 xz 2 xy+ 2 wz - 2 Ix 2 + z 2 M 2 yz- 2 wx ÿ 2 xz- 2 wy 2 wx+ 2 yz - 2 Ix 2 + y 2 M - 2 Iy 2 + z 2 M 2 xy- 2 wz 2 wy+ 2 xz T ÿ ÿ 2 xy+ 2 wz - 2 Ix 2 + z 2 M 2 yz- 2 wx 2 xz- 2 wy 2 wx+ 2 yz - 2 Ix 2 + y 2 M which actually represents such simple transformation as the rotation of moment of inertia tensor using quaternions [2]. The purpose of this document is to express spatial rotations of a moment of inertia tensor in the pure quaternionic form and to highlight the algebraical meaning behind such rotations by proving some interesting theorems. ü Conventions and Definitions Load quaternions package (see Quat.nb for the annotated source code) Get@ "Quat.m", Path > 8 NotebookDirectory @D < D; ô Conventions In this document, matrices, vectors and matrix representation of quaternions are shown in uppercase font (roman-bold font in text) and quaternions and other numbers are shown in lowercase font (italic font in text). Since the symbol I in Mathematica is used for imaginary unit, the selected symbol for moment of inertia is the uppercase script J i.e.. The identity matrix is suffixed with a number of dimensions, i.e. I4 represents the identity matrix in 4. Matrices 4ä4 originated from quaternions may be geometrically partitioned into scalar (real), vector (pure imaginary) and cross-product parts [3]. Such partitions are visualized using row and column divider lines throughout this document: scalar É vector É É É É É vector É cross product É É É É É ô General symbols and variables used in theorems (definitions) Hamilton's quaternions q, q and q 2 with real number components (but not with complex number components as biquaternions; see definition of default $Assumptions bellow): q = @ w, x, y, z D; q = @ w, x, y, z D; q2 = @ w2, x2, y2, z2 D; Identity matrix I4 in 4 : I4 = IdentityMatrix@4D;
2 Rotations of Tensors using Quaternions v0.3.nb Common 4 matrices A and B: A = Aww Awx Awy Awz Axw Axx Axy Axz Ayw Ayx Ayy Ayz Azw Azx Azy Azz ; B = Bww Bwx Bwy Bwz Bxw Bxx Bxy Bxz Byw Byx Byy Byz Bzw Bzx Bzy Bzz ; Symmetrical 4 matrix representing moment of inertia tensor : = 0 0 0 0 Ixx Ixy Ixz ; 0 Ixy Iyy Iyz 0 Ixz Iyz Izz Default assumption used for all asserted statements and expressions in this notebook is that previously defined entities q, q, q 2, A, B and are on field of, i.e. that their components are elements in : $Assumptions = latten@8 ToList ê@ 8 q, q, q2 <, A,B, < Reals; ü Different Types of Multiplications The ordirary notation for multiplication in Mathematica is A. B a ä b p ** q multiplication between matrices ("dot" multiplication) cross-product between 3D vectors quaternion multiplication (both in Quat.m and Mathematica Quaternions package) Beside the ordinary notation for multiplication, this document also introduces the following notation based on the center dot ( ) operator. A B p q q A := multiplication between matrices := quaternion multiplication := column-wise quaternion-matrix multiplication Note that the center dot operator in Mathematica is without built-in meaning. ô Matrix multiplication Define center dot operator A B as matrix multiplication (otherwise, Mathematica uses plain dot "." for matrix multiplications). CenterDot@ m? MatrixQ D := Dot@ m D ô Quaternion multiplication Mathematica uses non-commutative multiply (**) operator as symbol for quaternion multiplication. The Quat.m package and this document follow this convention. Here we define also the center dot operator as symbol for quaternion multiplication, just for convinience and esthetics CenterDot@ q? Q D := NonCommutativeMultiply@ q D
Rotations of Tensors using Quaternions v0.3.nb 3 ô Column-wise (or horizontal) quaternion-matrix multiplication Let us now define multiplication between quaternion q and matrix M, where it is assumed that matrix is a row vector of quaternions in columns, i.e. M = H q q 2... q n L, so that quaternion multiplication is done between q and q j in every column j. q q j q n qq q j = qq j qq n q q 2 q n q q 2 q n q ÿ q 2 q 22 q 2n q 3 q 32... q 3n := q 2 q 22 q 2n q 3 q 32... q 3n q 4 q 42 q 4n q 4 q 42 q 4n Since the quaternion multiplication is not commutative, there are several cases to distinguish: a) Left multiplication q ÿ M, where a quaternion in each column in M is multiplied by the quaternion q from the left: CenterDot@ q_? Q, mat_? MatrixQ D := Transpose@ TableA ToListA q To @ mat PAll,jT, 9j,, Dimensions@matD P2T = b) Right multiplication M ÿ q, where a quaternion in each column in M is multiplied by the quaternion q from the right: CenterDot@ mat_? MatrixQ, q_? Q D := Transpose@ TableA ToListA To @ mat PAll,jT q, 9j,, Dimensions@matD P2T = c) Compound multiplication from both sides p ÿ M ÿ q, where multiplication of each column in M by the quaternion p from the left and q from the right: CenterDot@ q_? Q, mat_? MatrixQ, q2_? Q D := Transpose@ TableA ToListA q To @ mat PAll,jT q2, 9j,, Dimensions@matD P2T = The multiplication between a quaternion and a matrix is associative, i.e. it holds: q ÿ M ÿ q 2 ã q ÿ HM ÿ q 2 L ã Hq ÿ ML ÿ q 2 which is proved as a theorem in the following sections. Note that for a single column matrix M, the multiplication between a quaternion and a matrix falls back to an ordinary quaternion multiplication. ô Row-wise (or vertical) quaternion-matrix multiplication Row-wise quaternion-matrix multiplication can be defined by transposing matrices and using column-wise multiplication: I q ÿ M ÿ q 2 M ô Conj[] matrix operator Conj[] operator conjugates only the vector part of the matrix, but not the scalar and the cross product parts: Conj@ q_? MatrixQ D := q P,T q P,2T q P,3T q P,4T q P2,T q P2,2T q P2,3T q P2,4T q P3,T q P3,2T q P3,3T q P3,4T q P4,T q P4,2T q P4,3T q P4,4T Note that Conj[] is not a conjugate of a quaternion! The conjugate of a quaternion corresponds to the plain transpose of the matrix.
4 Rotations of Tensors using Quaternions v0.3.nb Idea behind quaternion-matrix multiplication Basic idea behind the quaternion-matrix multiplication comes from an expression: AssertA @, 0, 0, 0 D q @, 0, 0, 0 D q, for which it is assumed to be also valid when transforming identity matrix I4 that is equvalent representation of the quaternion [, 0, 0, 0 ] in matrix form, i.e. that there should be kind of multiplication where: H 0 0 0 L q H 0 0 0 L q, ü Theorems ô Quaternion-matrix multiplication Quaternion multiplication associativity (sanity-check): q q q2 q H q q2l Hq ql q2 Quaternion-matrix multiplication associativity theorems: q A q2 q H A q2 L H q A L q2 q A q H q A L q q A q q H A q L H q I4 L q I4 H I4 q L I4 q Hq I4L A q A HI4 ql A A q Hq I4L HI4 q2l q I4 q2
Rotations of Tensors using Quaternions v0.3.nb 5 HI4 q2l HHq I4L A L Hq AL q2 q A q2 HI4 q2l Hq I4L A q A q2 Ï HI4 q2l Hq I4L A q A q2 Ï Hq I4L HI4 q2l A q A q2 Ï Hq I4 q2l A q A q2 Conjugations of quaternion-matrix multiplications: Conj@ q A D Conj@AD q Conj@ A q D q Conj@AD Conj@ q A q2d Conj@ q HA q2ld Conj@A q2d q q2 Conj@AD q Conj@ q A q D q Conj@AD q ô Left and right rotation matrices Because the quaternion multiplication is bilinear, it can be expressed in a matrix form, and in two different ways ([]). Multiplication on the left qp gives L q ÿp where p is now treated as a 4-dimensional column vector p and multiplication on the right pq gives p ÿr q. Let us define L q and R q as quaternion-multiplication with identity matrix: ClearAll@ L, R, Q D L q_ := q I4 R q_ := I4 q Q q_ := L q R q Proof that the quaternion multiplication can be decomposed into L&R matrix parts and that L q R q * p corresponds to qpq * : AssertA L q R q ToVector@qD ToVector@ q q q D, ô Properties of L, R and Q matrices L q IL q M R q IR q M I q R q M A q I R q A M IL q A M q
6 Rotations of Tensors using Quaternions v0.3.nb Q q L q R q IR q L q M IR q L q M R q L q Q q R q L q == L q R q Q q Q q q 4 I4 ConjAL q A q ConjA q IL q AM êêassert ConjAL q A q ConjAL q A q ô L & R matrices components Grid @9 9 "L q ", "L q ", "R q ", "R q " =, 9 L q êê Qorm, L q êê Qorm, R q êê Qorm, R q êê Qorm = = L q L q R q R q w x y z w x y z w x y z w x y z x w z y y z w x z y x w x w z y y z w x z y x w x w z y y z w x z y x w x w z y y z w x z y x w ô Rotation matrix Q components Grid @9 9 "Q q L q R q R q L q ", "Q q L q R q R q L q " =, 9 SimplifyA Q q, êê Qorm, SimplifyA Q q, êê Qorm = = Q q L q R q R q L q Q q L q R q R q L q 0 0 0 0 0 0 0 2y 2 2z 2 2xy 2wz 2Hw y+ xzl 0 2y 2 2z 2 2 Hx y+ wzl 2 wy+ 2xz 0 2 Hx y+ wzl 2x 2 2z 2 2wx+ 2yz 0 2 x y 2wz 2x 2 2z 2 2 Hw x+ yzl 0 2 wy+ 2xz 2Hw x+ yzl 2x 2 2y 2 0 2 Hw y+ xzl 2 wx+ 2yz 2x 2 2y 2 ô Shoemake's rotation matrix from quaternion Classical Shoemake's form of the rotation matrix from a quaternion is given as (a transformation matrix based on the Cayley- Klein parameters; see [2]): RotationMatrix4@ q D êê Qorm 0 0 0 0 2 Iy 2 + z 2 M 2xy 2wz 2wy+ 2xz 0 2xy+ 2wz 2 Ix 2 + z 2 M 2 wx+ 2yz 0 2 wy+ 2xz 2wx+ 2yz 2 Ix 2 + y 2 M
Rotations of Tensors using Quaternions v0.3.nb 7 ô Scalar, vector and cross-product parts of L&R matrices Scalar part: 2 IL q + L q M 2 IR q + R q M Vector part: w 0 0 0 0 w 0 0 0 0 w 0 0 0 0 w 2 IL q R qm == 2 IR q L qm 0 x y z x 0 0 0 y 0 0 0 z 0 0 0 2 IL q R q M == 2 IR q L q M 0 x y z x 0 0 0 y 0 0 0 z 0 0 0 Cross product part: 2 IL q R q M 0 0 0 0 0 0 z y 0 z 0 x 0 y x 0 2 IL q R q M 0 0 0 0 0 0 z y 0 z 0 x 0 y x 0 Q Q + 2 Q (vector part) form. Note that the vector part is a pure imaginary part of a quaternion. To @0 q 2 + 2 q To @Im@q D q 2 Q q == L q L q + 2 L q 0 x y z x 0 0 0 y 0 0 0 z 0 0 0 L q L q + 2 L q 2 IR q L qm L q R q 2 L q IL q L q Q q M == 2 IL q R q M
8 Rotations of Tensors using Quaternions v0.3.nb quality of rotation matrix from quaternion and uler-rodrigues' formula uler-rodrigues' formula for the rotation matrix corresponding to a rotation by an angle q about a fixed axis specified by the unit vector u. Reference: http://mathworld.wolfram.com/rodriguesrotationormula.html ulerrodrigues@ θ_, 8 x_, y_, z_ <D:= Cos@θD 0 0 0 0 0 0 + H Cos@θDL xx yx zx xy yy zy xz yz zz + Sin@θD 0 z y z 0 x y x 0 Proof that the rotation matrix from a quaternion (as defined in Quat.m package) is equivalent to uler-rodrigues' formula. BlockA 8 x, y, z, θ, q<, q = To $AngleAxis@ θ, 8 x, y, z <D; AssertA RotationMatrix@ q D ulerrodrigues@ θ, 8 x, y, z <D, Assumptions π θ πïx 2 + y 2 + z 2 Ï8x, y, z, θ < Reals ô Rotation matrix theorems RM = RotationMatrix4@ q D; RM êê Qorm 0 0 0 0 2 Iy 2 + z 2 M 2xy 2wz 2wy+ 2xz 0 2xy+ 2wz 2 Ix 2 + z 2 M 2 wx+ 2yz 0 2 wy+ 2xz 2wx+ 2yz 2 Ix 2 + y 2 M RM Q q L q R q Ì RM Q q R q L q, AssertA RM ToVector@qD L q R q ToVector@qD ToVector@ q q q D,
Rotations of Tensors using Quaternions v0.3.nb 9 RM A RM Q q A Q q L q R q A L q R q J q H q A q L q N, I4 Hq I4 q L I4 Hq I4 q L IL q R q M I4 IL q R q M L q R q I4 R q L q L q IR q I4 R q M L q, RM A RM Hq I4 q L A Hq I4 q L IL q R q M A IL q R q M L q R q A R q L q L q IR q A R q M L q, Proof that both Q q and R M are orthogonal matrices: Q q Q q IL q R q M IL q R q M L q R q IR q M IL q M L q R q R q L q I4,
0 Rotations of Tensors using Quaternions v0.3.nb AssertA Q q Q q Q q Q q RM RM I4, ô Quaternionic meaning of RHqL A RHqL T The hint how quaternion multplication affects a (moment of inertia or any other) tensor A can be seen from the earlier proven theorem: RM A RM J q H q A q L q N, which shows that the tensor A is rotated, at first, by rotating quaternions across each column A c = q ÿ A ÿ q *, and at second, by rotating quaternions across each row A rc = Iq ÿ HA c L ÿ q * M. q ÿ HL q ÿ HL q q 2 q 3 q 4 q 2 q 22 q 23 q 24 q 3 q 32 q 33 q 34 q 4 q 42 q 43 q 44 HL ÿ q * HL ÿ q * The meaning of the compound multiplications across columns and rows is extracting and affecting individual components of quaternions embedded from the previous rotations of the tensor. The moment of inertia tensor can always be reduced to its principal axes in diagonal form. In a matrix representation of a quaternion, the diagonal of the matrix contains the repeated scalar (real) part of the quaternion. (or any quaternion q there exist quaternion p such that qp is scalar.) The principal moment of inertia, on the other hand, has on its diagonal three different scalars in general case, which gives origin to three different quaternions that are embedded and independently shuffled across-columns/rows during rotations. ü References [] berly, David H. with a contrib. by Shoemake, Ken - Game Physics, Morgan Kaufmann, 2004, Chapter 0 "Quaternions", pp. 507-544, http://books.google.se/books?id=a9szhpj0mwc [2] Shoemake, Ken - Uniform random rotations, in: D. Kirk (d.), Graphics Gems III, Academic Press, London, 992, pp. 24-32, http://books.google.se/books?id=xmw_u3mqlmqc [3] Shoemake, Ken - Quaternions, Department of Computer and Information Science, University of Pennsylvania, 2005-0-07, downloaded from C+MS course CS7 at Caltech: http://courses.cms.caltech.edu/cs7/quatut.pdf