Quaternions 2 AUI Course Denbigh Starkey

Similar documents
sin(α + θ) = sin α cos θ + cos α sin θ cos(α + θ) = cos α cos θ sin α sin θ

Introduction to quaternions

The Quaternions & Octonions: A Basic introduction to Their Algebras. By: Kyle McAllister. Boise State University

Quaternions. R. J. Renka 11/09/2015. Department of Computer Science & Engineering University of North Texas. R. J.

Why Transforms? Want to animate objects and camera Translations Rotations Shears And more.. Want to be able to use projection transforms

Chapter 5 Trigonometric Functions of Angles

Quaternions. Mike Bailey. Computer Graphics Quaternions.pptx

Spherical Trigonometry. CESAR s Booklet

Designing Information Devices and Systems I Fall 2018 Lecture Notes Note 21

QUATERNIONS AND ROTATIONS

MATH 221: SOLUTIONS TO SELECTED HOMEWORK PROBLEMS

Lecture for Week 2 (Secs. 1.3 and ) Functions and Limits

Contents. D. R. Wilkins. Copyright c David R. Wilkins

MATH 12 CLASS 2 NOTES, SEP Contents. 2. Dot product: determining the angle between two vectors 2

Course 2BA1: Hilary Term 2007 Section 8: Quaternions and Rotations

5. Vector Algebra and Spherical Trigonometry (continued)

BSc (Hons) in Computer Games Development. vi Calculate the components a, b and c of a non-zero vector that is orthogonal to

Chapter 8. Rigid transformations

3 What You Should Know About Complex Numbers

Page 52. Lecture 3: Inner Product Spaces Dual Spaces, Dirac Notation, and Adjoints Date Revised: 2008/10/03 Date Given: 2008/10/03

Vectors Part 1: Two Dimensions

Confidence intervals

Section 7.3 Double Angle Identities

Quaternions and Octonions

Conceptual Explanations: Simultaneous Equations Distance, rate, and time

Complex numbers, the exponential function, and factorization over C

Be fruitful and multiply Genesis 1:28

SOLUTIONS to ECE 2026 Summer 2017 Problem Set #2

Lecture 3f Polar Form (pages )

Chapter 1A -- Real Numbers. iff. Math Symbols: Sets of Numbers

Feedback D. Incorrect! Exponential functions are continuous everywhere. Look for features like square roots or denominators that could be made 0.

Tutorial 2 - Learning about the Discrete Fourier Transform

A (Mostly) Linear Algebraic Introduction to Quaternions

Quaternion Dynamics, Part 1 Functions, Derivatives, and Integrals. Gary D. Simpson. rev 00 Dec 27, 2014.

Chapter 8B - Trigonometric Functions (the first part)

3.2 Constructible Numbers

ENGINEERING MATH 1 Fall 2009 VECTOR SPACES

MA232A Euclidean and Non-Euclidean Geometry School of Mathematics, Trinity College Michaelmas Term 2017 Vector Algebra and Spherical Trigonometry

N-CN Complex Cube and Fourth Roots of 1

Designing Information Devices and Systems I Discussion 2A

What is proof? Lesson 1

VECTORS. Given two vectors! and! we can express the law of vector addition geometrically. + = Fig. 1 Geometrical definition of vector addition

Lie Algebra of Unit Tangent Bundle in Minkowski 3-Space

1MA1 Introduction to the Maths Course

Spanning, linear dependence, dimension

Lecture 1 - Vectors. A Puzzle... Introduction. Vectors: The quest begins! TA s Information. Vectors

Understanding Quaternions: Rotations, Reflections, and Perspective Projections. Ron Goldman Department of Computer Science Rice University

Math 24 Spring 2012 Questions (mostly) from the Textbook

Complex Numbers and Quaternions for Calc III

The Quaternions. The Quaternions. John Huerta. Department of Mathematics UC Riverside. Cal State Stanislaus

Group Representations

Course MA2C02, Hilary Term 2010 Section 4: Vectors and Quaternions

An Intuitive Introduction to Motivic Homotopy Theory Vladimir Voevodsky

STEP Support Programme. Hints and Partial Solutions for Assignment 5

A Learning Progression for Complex Numbers

Getting Started with Communications Engineering

Math 100 Sections E/F Fundamental Theorem of Algebra Extra Credit Due Monday, April 23

5.4 Continuity: Preliminary Notions

Midterm 1 Review. Distance = (x 1 x 0 ) 2 + (y 1 y 0 ) 2.

Physics 342 Lecture 2. Linear Algebra I. Lecture 2. Physics 342 Quantum Mechanics I

The VQM-Group and its Applications

Linear Algebra. Min Yan

2. FUNCTIONS AND ALGEBRA

Rings If R is a commutative ring, a zero divisor is a nonzero element x such that xy = 0 for some nonzero element y R.

Electro Magnetic Field Dr. Harishankar Ramachandran Department of Electrical Engineering Indian Institute of Technology Madras

Physics 342 Lecture 2. Linear Algebra I. Lecture 2. Physics 342 Quantum Mechanics I

Revision History Date Version Description Author 03/06/ Initial Version Sergio Miguel Martin. Table of Contents

Chapter 1. Introduction to Vectors. Po-Ning Chen, Professor. Department of Electrical and Computer Engineering. National Chiao Tung University

Topic 4 Notes Jeremy Orloff

CHAPTER 4. APPLICATIONS AND REVIEW IN TRIGONOMETRY

( )( b + c) = ab + ac, but it can also be ( )( a) = ba + ca. Let s use the distributive property on a couple of

15. LECTURE 15. I can calculate the dot product of two vectors and interpret its meaning. I can find the projection of one vector onto another one.

Quaternions and their applications

Mechanics, Heat, Oscillations and Waves Prof. V. Balakrishnan Department of Physics Indian Institute of Technology, Madras

MATH141: Calculus II Exam #4 review solutions 7/20/2017 Page 1

Quaternions. Basilio Bona. Semester 1, DAUIN Politecnico di Torino. B. Bona (DAUIN) Quaternions Semester 1, / 40

Chapter 7: Trigonometric Equations and Identities

Be fruitful and multiply Genesis 1:28

Analytic Trigonometry. Copyright Cengage Learning. All rights reserved.

Ruminations on exterior algebra

Trigonometry Exam II Review Problem Selected Answers and Solutions

Course Notes Math 275 Boise State University. Shari Ultman

Mathematics for Chemists 2 Lecture 14: Fourier analysis. Fourier series, Fourier transform, DFT/FFT

Hongbing Zhang October 2018

INTRODUCTION TO DIFFERENTIATION

Hypercomplex numbers

9709 MATHEMATICS. 9709/32 Paper 3, maximum raw mark 75

Math 016 Lessons Wimayra LUY

The modulus, or absolute value, of a complex number z a bi is its distance from the origin. From Figure 3 we see that if z a bi, then.

!t + U " #Q. Solving Physical Problems: Pitfalls, Guidelines, and Advice

CHAPTER 4 VECTORS. Before we go any further, we must talk about vectors. They are such a useful tool for

Complex Numbers. 1 Introduction. 2 Imaginary Number. December 11, Multiplication of Imaginary Number

Second quantization: where quantization and particles come from?

MATH 320, WEEK 11: Eigenvalues and Eigenvectors

has a lot of good notes on GR and links to other pages. General Relativity Philosophy of general relativity.

Dot Products, Transposes, and Orthogonal Projections

Volume vs. Diameter. Teacher Lab Discussion. Overview. Picture, Data Table, and Graph

Vectors Summary. can slide along the line of action. not restricted, defined by magnitude & direction but can be anywhere.

Mathematics for Graphics and Vision

Physics 2A Chapter 1 - Vectors Fall 2017

Transcription:

Quaternions 2 AUI Course Denbigh Starkey 1. Background 2 2. Some Basic Quaternion Math 4 3. The Justification of the Quaternion Rotation Formula 5 4. Interpolation between two Unit Quaternions SLERP vs. LERP 9

1. Background This is a continuation of my previous set of notes, where I defined quaternions and showed how to use them to do rotations around an arbitrary axis through the origin. So I ll assume here that you understand these concepts and that I don t need to reintroduce the notation. Quaternions were originally created by Sir William Rowan Hamilton on October 16, 1843, when he was working on ways to extend the complex plane into a complex cube. 1 He came up with his three complex axes system while he was walking along the Royal Canal to the Royal Irish Academy where he had a Council meeting, and he carved the equation that lies at the heart of quaternion theory i 2 = j 2 = k 2 = ijk = -1 into the Brougham Bridge. Hamilton describes this event twenty years later in a letter to his son, which can be read at http://www.maths.tcd.ie/pub/histmath/people/hamilton/letters/broomebri dge.html. This equation, along with the three equations ij = k jk = i ki = j are now called Hamilton s rules. He published a number of papers on quaternions, many of which are available on the Web including his November 1843 paper On a new Species of Imaginary Quantities connected with a theory of Quaternions which is at http://www.maths.tcd.ie/pub/histmath/people/hamilton/quatern1/quatern1. html. This is a fun paper to read, given the amazing amount of new material that he published there, particularly since he presented it only four weeks after he first though of the idea. I also find it impressive that he requested permission to present this paper on October 16, the day that he first though of the Hamilton rules. 1 He had been trying to add just one extra imaginary axis, but the math hadn t worked out. 2

Quaternions have been used in a number of mathematical disciplines, and so, for example, to algebraists they can be studied as a non-abelian group 2. 2 Weirder mathematicians will remember Martin Gardner s question in Scientific American What s purple and commutes? (http://math.berkeley.edu/~mgsa/halloweenpics/img014.html) although it has nothing to do with graphics. 3

2. Some Basic Quaternion Math If q 1 and q 2 are quaternions with q 1 = (s 1, v 1 ) and q 2 = (s 2, v 2 ), then it is simple to show that q 1 + q 2 = (s 1 + s 2, v 1 + v 2 ) q 1 q 2 = (s 1 s 2 v 1. v 2, s 1 v 2 + s 2 v 1 + v 1! v 2 ) Note that the multiplication is not commutative because of the vector cross product term. If q = (s, v) = (s, v 1, v 2, v 3 ) then the magnitude of q, q, is given by the formula q 2 = (s 2 + v 1 2 + v 2 2 + v 3 2 ) = (s 2 + v 2 ) = (s 2 + v. v) The conjugate of q is (s, -v). The inverse of q, written as usual as q -1, is given by the formula q -1 1 = q 2 (s, -v). (Note: The value (0, 0) is not a valid quaternion.) To confirm this equation, use the formula for quaternion multiplication which gives: qq -1 1 = q 2 (s 2 + v. v, sv - sv + v! -v) The scalar part in the parentheses is q 2, and the vector part is 0, so q q -1 = (1, 0) which is what we want. Note that if q = (s, v) is a unit quaternion, then q -1 is just (s, -v), the conjugate of q, which I assumed in the first set of notes. 4

3. The Justification for the Quaternion Rotation Formula In the first set of notes I stated that to rotate a point P by θ around an arbitrary unit axis, u, through the origin one can use the formula P = qpq -1, where q = (cos( 2! ), sin( 2! )u). Obviously I need to justify this. Before I get into this I ll need a number of equivalencies as I go through the derivation, and don t want to keep breaking off when I need them. I ll list them all here, without proofs. They are for all vectors u, v, and w, and for all angles α. Study them carefully, and ask for proofs in class for any that you cannot prove. (a) sin 2 (α) + cos 2 (α) = 1 (b) 2sin 2 (α) = 1 + sin 2 (α) cos 2 (α) (c) sin(α) = 2cos( 2! )sin( 2! ) (d) cos(α) = cos 2 ( 2! ) sin 2 ( 2! ) (e) (u + v). w = u. w + v. w (f) (u + v)! w = u! w + v! w (g) (u! v) = -(v! u) (h) (u. v) = (v. u) (i) (u! u) = 0 (j) (u. u) = 1 if u is a unit vector (k) (u! v). u = 0 (l) (u! v)! u = v (u. v)u if u is a unit vector I ll start with some basic 3D rotation math, and will then show that the result of this matches the quaternion rotation formula. I ll break it down into 2D pieces. I ll start with the picture below, where I want to rotate the vector r by θ around a unit vector n to get a new vector r R. This is equivalent to rotating the point r around n. 5

n n n n r r r 1 r r 2 r 1 r (n.r)n α (0,0,0) r 2 (0,0,0) r 2 (0,0,0) r-(n.r)n (0,0,0) The left hand diagram shows the plane containing r and n. I then decompose r into two vectors in the plane, r 1 which is parallel to n and r 2 which is perpendicular to n, and show this in the second diagram. If the angle between r and n is α, as shown, then r 1 has length r cos(α), which is (n. r) since n is a unit vector. It is in the direction of n, and so: r 1 = (n. r) n Next, r 2 is the same as the extra vector shown in the third diagram, and so r 1 + r 2 = r, which gives the fourth diagram since: r 2 = r (n. r) n Now instead of a single vector, r, to rotate around n, I have two, r 1 and r 2. However, r 1 is parallel to n, and so rotating it around n leaves it untouched. So I just have to rotate r 2 around n and add that result to r 1 to get the rotated vector. To do the rotation by θ we have the circle shown on the left below, which is a view looking down on n, and so n is vertical at the center of the circle. r 2 θ r 2 θ r 3 r 3 r 4 To define r 3 I ll use another vector, r 4, which lies in the plane and is at right angles to r 2, as shown in the second circle. So r 3 = cos(θ)r 2 + sin(θ)r 4. 6

Going back to the first figures, the length of r 2 is r sin(α), and since r 2, n, and r all lie in the same plane, r 4 is also perpendicular to r. So n! r is a vector in the direction or r 4 which has the same length as r 2. 3 Since r 2 and r 4 have the same length we get the surprisingly simple result that r 4 = n! r. Combining all of this, including that r 2 = r (n. r) n from above, we get: r 3 = (r (n. r) n)cos(θ) + (n! r)sin(θ) Now since, as discussed above, the rotated vector is this plus r 1, we have: r R = (n. r) n + (r (n. r) n)cos(θ) + (n! r)sin(θ) This finishes the general rotation formula. Now I have to show that the usual quaternion multiplication qrq -1 where q = (cos( 2! ), sin( 2! )n), r = (0, r), and q -1 = (cos( 2! ), -sin( 2! )n) gives the same result. We know that for any two quaternions: q 1 q 2 = (s 1 s 2 v 1. v 2, s 1 v 2 + s 2 v 1 + v 1! v 2 ), and so setting s = sin( 2! ) and c = cos( 2! ), to make this readable, we get: qrq -1 = (-sn.r, cr + s(n! r)) (c, -sn) = (-csn.r + csr.n + s 2 (n! r). n, s 2 (n.r)n + c 2 r + cs(n! r) cs(r! n) s 2 (n! r)! n. This might look awful, but I ll take it a piece at a time. First, the scalar part is zero because the first two parts cancel out and the third part is zero. The vector part can be rearranged into: s 2 (n.r)n + c 2 r + 2cs(n! r) s 2 (r (n.r)n) = 2s 2 (n.r)n + (c 2 s 2 )r + 2cs(n! r) = (1 + s 2 c 2 )(n.r)n + (c 2 s 2 )r + 2cs(n! r) = (n.r)n - cos(θ)(n.r)n + cos(θ)r + sin(θ)(n! r) 3 I ll assume until the end of this section that n! r is not the zero vector, because otherwise I ll need a bunch of special cases which will confuse things further. I ll handle that case when I m finished with the normal cases. 7

which matches the equation that I had for a 3D rotation. This just leaves the case that I ignored throughout the preceding derivation, which is when n! r = 0. For this to happen we need r = kn for some k, and I need to show that the rotation quaternion formula works correctly under these circumstances. Since r lies along n, the result of the rotation of kn should be that it isn t affected for any half angle cosine and sine, c and s. (c, sn) (0, kn) (c, -sn) = (-sk(n. n), ckn + sk(n! n)) (c, -sn) = (-sk, ckn) (c, -sn) = (-skc + skc(n. n), s 2 kn + c 2 kn csk(n! n)) = (0, (s 2 + c 2 )kn) = (0, kn) and so, as required, kn has not been affected by the transformation. 8

4. Interpolation Between two Unit Quaternions SLERP vs. LERP A common use of quaternions is to provide a smooth animation by interpolating between two quaternions, q 1 and q 2. There are two basic approaches to doing this interpolation, LERP and SLERP. LERP, which is linear interpolation, has the problem that the animation first speeds up and then slows down (although this could be considered an advantage in many cases) whereas SLERP (spherical linear interpolation) smoothly changes the angle between the two quaternions and so gives a steady interpolation. The descriptions of SLERP in the literature can get a bit scary, because they constantly include comments like the entire group of rotations maps onto the surface of the four-dimensional unit hypersphere. Fortunately much of this is mathematical obfuscation which can be ignored. E.g., since there are four components in a quaternion and rotations are equivalent to unit quaternions, it is obvious that they define the surface of a 4D hypersphere, just as 3D unit vectors define the surface of a 3D sphere and 2D unit vectors define a circle. The basic idea is that if we have two quaternions, q 1 and q 2, as shown in the diagrams below, q 1 q 2 q 1 q 2 then in the left diagram we are interpolating linearly since the points of the quaternions are equally separated, and in the second the angles are equal. As 9

a result in the LERP case (left) the rotation angles are bigger as one gets closer to the middle of the rotation, and so the rotation will speed up until the middle, and then slow down. In the SLERP case (right) the lines are interpolated around the projected circle in the sphere, and so the angular velocity will be constant. As an extra disadvantage the interpolated quaternions in the LERP case will have to be normalized, or they will not represent rotations. To produce a series of quaternions using SLERP, we use the following formula: sin((1 " t)! ) q(t) = q 1 sin(! ) where sin( t! ) + q 2, 0 t 1 sin(! ) q 1. q 2 = cos(θ). This is justified using the interpolation of vectors, and then extending into quaternions. Watt and Policarpo say that this solution is trivial, which is a bit of an exaggeration, but I ll give it as an exercise. Unfortunately, for small t increments, this solution requires many expensive calculations of sin functions, and so work has been done to find faster implementations which give the same intermediate quaternions. A pair of 2004 papers by Barrera, Hast, and Bengtsson, where the most relevant is available at http://www.ep.liu.se/ecp/013/004/ecp01304.pdf, compare six different ways to do incremental SLERPs on quaternions, including a complex number approach via De Moivre s formula, using Chebyshev polynomials, solving a differential equation using the Euler method, and matrix multiplication. They conclude that in general the Chebyshev approach is the most efficient, although any of the six methods are much faster than using the standard trigonometric approach. 10