Visualizing Quaternions Andrew J. Hanson Computer Science Department Indiana University Siggraph 1 Tutorial 1
GRAND PLAN I: Fundamentals of Quaternions II: Visualizing Quaternion Geometry III: Quaternion Frames IV: Clifford Algebras
I: Fundamentals of Quaternions Motivation D Frames: Simple example, complex numbers. 3D Frames: Rotations and quaternions. 3
II: Visualizing Quaternion Geometry The Spherical Projection Trick: unit vectors. Visualizing Quaternion Frames Quaternion Curves Quaternion Splines 4
III: Quaternion Frames Quaternion Curves: generalize the Frenet Frame Quaternion Frame Evolution Quaternion Curve and Surface Optimization 5
IV: Clifford Algebras Clifford Algebras: Generalize quaternion structure to N-dimensions Reflections and Rotations: New ways of looking at rotations Pin(N), Spin(N), O(N), and SO(N)
Visualizing Quaternions Part I: Fundamentals of Quaternions Andrew J. Hanson Indiana University
Part I: OUTLINE Motivation D Frames: Simple example, complex numbers. 3D Frames: Rotations and quaternions. 8
Motivation Quaternion methods are now commonplace in graphics. Quaternions are very geometric, but we seldom attempt to visualize their properties geometrically. That s going to be our job today! 9
Basic Issues Basic fact number 1: Rotation matrices are Coordinate Frame Axes. Basic fact number : Rotation matrices form groups, which have geometric properties. 1
Task vs Strategy Our task: Understand Rotations. Rotations don t just act on geometry, rotations are geometry. Our strategy: the geometry should help us to visualize the properties of rotations. 11
Simple Example: D Rotations D rotations ) geometric origin for complex numbers. Complex numbers are a special subspace of quaternions. Thus D rotations introduce us to quaternions and their geometric meaning. 1
Frames in D The tangent and normal to D curve move continuously along the curve: N^ T^ θ 13
Frames in D The tangent and normal to D curve move continuously along the curve: N^ T^ θ 14
Frames in D The tangent and normal to D curve move continuously along the curve: N^ T^ θ 15
5 : Frame Matrix in D This motion is described at each point (or time) by the matrix: R () = h ^T ^N i 3 4, sin cos cos sin = 1
A,B 4 A B 5 : Another D Frame If we did not know about cos + sin = 1, we might represent the frame differently, e.g., as: 3 R (A; B) = with the constraint A + B = 1. 1
The Belt Trick: Is There a Problem? Demonstration: Rotations want to be doubled to get back where you started. See: Hart, Francis, and Kauffman. 18
4 cos, sin, cos sin cos sin cos, sin 5 Half-Angle Transform: A Fix for the Problem? 3 R () = 19
a, b,ab 4 a, b ab 5 : Half-Angle Transform: A Fix for the Problem? Or, with a = cos(=), b = sin(=), (i.e., A = a, b, B = ab), we could parameterize as: 3 R (a; b) = where orthonormality implies + b ) = 1 (a which reduces back a to + b = 1.
a, b,ab 4 a, b ab 5 : Half-Angle Transform: So the pair (a; b) provides an odd double-valued parameterization of the frame: 3 h ^T ^N i = where (a; b) is precisely the same frame as (,a;,b). 1
_^T(t) = + ^N 5 : Frame Evolution in D Examine time-evolution of D frame (on our way to 3D): First in (t) coordinates: 3 h ^T ^N i = 4, sin cos cos sin Differentiate to find frame equations: =,^T ; _^N(t) (t) = d=dt where is the curvature.
4 _^T(t) _^N(t) = 5 +(t) 4,(t) ^T(t) ^N(t) Frame Evolution in D Rearrange to make a vector matrix: 3 3 3 5 5 4 3
_^T = a_a, b _b 4 + b_a a_b a,b 4 a b 4 _a _b Frame Evolution in (a; b): Using the basis (^T; ^N) we have Four equations with Three constraints from orthonormality, for One true degree of freedom. Major Simplification occurs in (a; b) coordinates!! 3 3 3 = 5 5 5 4
,ab 4, b a a,b 4 a b a,b 4 a b,1 4 1 4 a b,b 4 a Frame Evolution in (a; b): But this formula for _^T is just ^N, where 3 3 ^N = 3 = 5 5 5 or 3 3 3 5 5 5 ^N = 5
4 _a _b, 4 + 4 a b D Quaternion Frames! Rearranging terms, both _^T and _^N eqns reduce to 3 3 3 5 5 = 1 5 This is the square root of frame equations.
_^T = + ^N D Quaternions... So one equation in the two quaternion variables (a; b) with the constraint a +b = 1 contains both the frame equations _^N =,^T ) this is much better for computer implementation, etc.
Rotation as Complex Multiplication If we let (a + ib) = exp (i =) we see that rotation is complex multiplication! Quaternion Frames in D are just complex numbers, with Evolution Eqns = derivative of exp (i =)! 8
(a a + ib = e i= ib i( )(a + ib) = e +)= A + ib = + )R()=R( R( A, B,AB 4 A, B AB Rotation with no matrices! This is the miracle: represents rotations more nicely than the matrices R(). where if we want the matrix, we write: 3 5 + )= 9
; b ) (a; b) = (a (a ib )(a + ib) + a a, b b + i(a b + ab ) = = (aa, bb; ab + ab) The Algebra of D Rotations The algebra corresponding to D rotations is easy: just complex multiplication!! = (A; B) 3
The Geometry of D Rotations (a; b) with a + b = 1 is a point on the unit circle, also written S 1. Rotations are just complex multiplication, and take you around the unit circle like this: (a a-b b, a b+ab ) (a, b ) θ + θ θ / θ/ (a,b) (1,) 31
The Geometry of D Rotations (a; b) with a + b = 1 is a point on the unit circle, also written S 1. Rotations are just complex multiplication, and take you around the unit circle like this: (a a-b b, a b+ab ) (a, b ) θ + θ θ / θ/ (a,b) (1,) 3
The Geometry of D Rotations (a; b) with a + b = 1 is a point on the unit circle, also written S 1. Rotations are just complex multiplication, and take you around the unit circle like this: (a a-b b, a b+ab ) (a, b ) θ + θ θ / θ/ (a,b) (1,) 33
Quaternion Frames In 3D, repeat our trick: take square root of the frame, but now use quaternions: Write down the 3D frame. Write as double-valued quadratic form. Rewrite linearly in the new variables. 34
The Geometry of 3D Rotations We begin with a basic fact: Euler theorem: every 3D frame can be written as a spinning by about a fixed axis ^n, the eigenvector of the rotation matrix: n ^ θ 35
The Geometry of 3D Rotations We begin with a basic fact: Euler theorem: every 3D frame can be written as a spinning by about a fixed axis ^n, the eigenvector of the rotation matrix: n ^ θ 3
The Geometry of 3D Rotations We begin with a basic fact: Euler theorem: every 3D frame can be written as a spinning by about a fixed axis ^n, the eigenvector of the rotation matrix: n ^ θ 3
c + (n 1 ) (1, c) n 1 n (1, c), sn 3 n 3 n 1 (1, c) + sn Quaternion Frames... Matrix giving 3D rotation by about axis ^n: R 3 (; ^n) = 3 1 n (1, c) + sn 3 c + (n ) (1, c) n 3 n (1, c), sn 1 n 1 n 3 (1, c), sn n n 3 (1, c) + sn 1 c + (n 3 ) (1, c) n 4 5 where c = cos, s = sin, and ^n ^n = 1. 38
Quaternion Frame Parameters To find and axis ^n, givenany rotation matrix or frame M, we need two steps: ) solve for. TrM = 1 + cos M, M t = 3,n 3 sin +n sin 3 sin,n 1 sin +n 4 5,n sin +n 1 sin ) solve for ^n as long as =. 39
Quaternions and Rotations Some set of axes can be chosen as the identity matrix: y 1 = 1 z 11 1111 x 1 4
Quaternions and Rotations Any arbitrary set of axes forms the columns of an orthogonal rotation matrix: b 1 11 11 11 1 1 11 1 1 1 c 11 11 a a a x y z b b x = a b c y z c c x y z 41
Quaternions and Rotations Any arbitrary set of axes forms the columns of an orthogonal rotation matrix: c b 11 11 11 11 111 11 1 11 1 1 111 a a a x y z b b x = a b c y z c c x y z 4
Quaternions and Rotations Any arbitrary set of axes forms the columns of an orthogonal rotation matrix: c b 1 1 1 1 11 1 1111 11 11 11 a 11 a a x y z b b x = a b c y z c c x y z 43
Quaternions and Rotations Any arbitrary set of axes forms the columns of an orthogonal rotation matrix: c 1 b 1 1 1 1 1 111 11 a a a x y z b b x = a b c y z c c x y z 44
Quaternions and Rotations By Euler s theorem, that matrix has an eigenvector ^n, and so is representable as a single rotation about ^n applied to the identity: b 11 11 11 11 1 11 1 1 11 c 11 11 a = y a a a x y z b b b x y z c c c x y z = ^ n θ z 11 11 11 1 111111111111 x = 1 1 1 45
4 a, b,ab 4 a, b ab q + q 1, q, q 3 q 1 q, q q 3 q 1 q 3 + q q 1 q + q q 3 q, q 1 + q, q 3 q q 3, q q 1 q 1 q 3, q q q q 3 + q q 1 q, q 1, q + q 3 q 5 Rotations and Quadratic Polynomials Remember R () = 5? 3 What if we try a 3 3 matrix R 3 instead of? 3 Hint: set q 1 = q = or any other (i = j) pair to see a familiar sight! 4
Quaternions and Rotations Why does this matrix parameterize a rotation? Because Columns R of (q ; q 1 ; q ; q 3 ) 3 are orthogonal: col i col = j i = j for What is LENGTH of 3-vector column? col i col = (q i q 1 + q + q 3 ) + 4
Quaternions and Rotations... So if we q require + q 1 + q + q 3 = 1, orthonormality is assured and 3 (q ; q 1 ; q ; q 3 ) is a rotation. R This q implies is a point on 3-sphere in 4D. NOTE: q ),q gives same R 3 (). 48
Quaternions and Rotations... HOW does q = (q ; q) represent rotations? LOOK at R 3 (; ^n)? = R 3(q ; q 1 ; q ; q 3 ) NOTICE: Choosing q(; ^n) = (cos ; ^n sin ) makes the R 3 equation an IDENTITY. 49
)R(q) = R(Q) R(q Quaternions and Rotations... WHAT happens if you do TWO rotations? EXAMINE the action of two rotations EXPRESS in quadratic forms in q and LOOK FOR an analog of complex multiplication: 5
4 Q = h q q i Q 1 = h q q i 1 Q = h q q i Q 3 = h q q i 3 5 4 q q, q 1 q 1, q q, q 3 q 3 q q 1 + q 1 q + q q 3, q 3 q q q + q q + q 3 q 1, q 1 q 3 q q 3 + q 3 q + q 1 q, q q 1 5 Quaternions and Rotations... RESULT: the following multiplication rule q = Q yields exactly the correct 3 3 rotation q matrix R(Q): 3 3 = This is Quaternion Multiplication. 51
Algebra of Quaternions = 3D Rotations! D rotation matrices are represented by complex multiplication 3D rotation matrices are represented by quaternion multiplication 5
; b ) (a; b) = (a a, b b; a b + ab ) (a q q = (q q q, q1q 1, qq, q3q 3 ; q + qq + q3q 1, q1q 3 ; q q Algebraic D/3D Rotations Therefore in 3D, the D complex multiplication is replaced by 4D quaternion multiplication: q 3, q q 1 + q 1 q + q 3 q ; 1 q, q q 3 + q 3 q + q q 1) 53
Algebra of Quaternions... The is easier to remember by dividing it into the scalar piece q and the vector piece ~q: q q = (q q, ~ q ~q; q ~q + q ~ q + ~ q ~q) 54
a + ib = e i= = q + iq 1 + jq + kq 3 = e (I^n=) Quaternions and Rotations Another miracle: let us generalize the D equation How? We set q = (q ; q 1 ; q ; q 3 ) with q = cos(=) and ~q = ^n sin(=) and I = (i; j; k). 55
Quaternions and Rotations... Then if we take i = j = k =,1, and i j = k (cyclic), quaternion multiplication rule is automatic! ) q = q + iq 1 + jq + kq 3 is the standard representation for a quaternion, and we can also use Pauli matrices in place of (i; j; k) if we want. 5
Key to Quaternion Intuition Fundamental Intuition: We know q = cos(=); ~q = ^n sin(=) We also know that any coordinate frame M canbewritten as M = R(; ^n). Therefore ~q points exactly along the axis we have to rotate around to go from identity I to M, and the length of ~q tells us how much to rotate. 5
4 p] [q p] 1 [q p] [q p] 3 [q 5 4 p, q 1 p 1, q p, q 3 p 3 q p 1 + q 1 p + q p 3, q 3 p q p + q p + q 3 p 1, q 1 p 3 q p 3 + q 3 p + q 1 p, q p 1 q 5 Summarize Quaternion Properties Unit four-vector. Take q = (q ; q 1 ; q ; q 3 ) = (q ; ~q) to obey q q = constraint 1. Multiplication rule. The quaternion product q and p is q p = (q p, ~q ~p; q ~p + p ~q + ~q ~p), or, alternatively, 3 3 = 58
4 q + q 1, q, q 3 q 1 q, q q 3 q 1 q 3 + q q 1 q + q q 3 q, q 1 + q, q 3 q q 3, q q 1 q 1 q 3, q q q q 3 + q q 1 q, q 1, q + q 3 q 5 Quaternion Summary... Rotation Correspondence. The unit quaternions q and,q correspond to a single 3D rotation R 3 : 3 59
Quaternion Summary... Rotation Correspondence. Let q = (cos ; ^n sin ) ; with ^n a unit 3-vector, ^n ^n = 1. Then R(; ^n) is usual 3D rotation by in the plane? to ^n. Inversion. Any 3 3 matrix R can be inverted for q up to a sign. Carefully treat singularities! Can choose sign, e.g., by local consistency, to get continuous frames.
SUMMARY Complex numbers represent D frames. Complex multiplication represents D rotation. Quaternions represent 3D frames. Quaternion multiplication represents 3D rotation. 1