<<

Lecture 8

Overview, motivation

Background

Definition and Lecture 8 properties using unit Quaternions quaternions Intuition

Using quaternions to represent Matthew T. Mason Why we love quaternions.

Mechanics of Manipulation Lecture 8 Today’s outline Quaternions

Overview, Overview, motivation motivation Background

Definition and Background properties Rotation using unit quaternions

Definition and properties Intuition

Using quaternions to represent Rotation using unit quaternions rotations Why we love quaternions. Intuition

Using quaternions to represent rotations

Why we love quaternions. Lecture 8 Motivation Quaternions

Overview, motivation

Background

Definition and Motivation properties Rotation using unit quaternions I Quaternions have nice geometrical interpretation. Intuition

I Quaternions have advantages in representing Using quaternions to represent rotation. rotations I Quaternions are cool. Even if you don’t want to use Why we love quaternions. them, you might need to defend yourself from fanatics. 3 Lecture 8 Why can’t we invert vectors in R ? Quaternions

Overview, motivation

Background 1 Definition and I We can invert reals. x × x = 1. properties 2 Rotation using unit I We can invert elements of R using complex quaternions ∗ 2 ∗ . z × z /|z| = 1, where is complex Intuition

conjugate. Using quaternions 3 to represent I Can we invert v ∈ R ? rotations

I No. Why we love quaternions. 4 I How about v ∈ R ? 4 I Yes! Hamilton’s quaternions are to R what complex numbers are to R2. Lecture 8 Complex numbers versus quaternions Quaternions Definition (Complex numbers) Overview, motivation

I Define elements 1 and i; Background Definition and I Define complex numbers as a vector over properties reals: elements have the form x + iy; Rotation using unit quaternions 2 I One more axiom required: i = −1. Intuition

Using quaternions to represent Definition (Quaternions) rotations Why we love quaternions. I Define basis elements 1, i, j, k;

I Define quaternions as a over reals: elements have the form q0 + q1i + q2j + q3k; I One more axiom:

i2 = j2 = k 2 = ijk = −1 Lecture 8 Basis element Quaternions

Overview, From that one axiom, we can derive other products: motivation Background ijk = −1 Definition and properties

i(ijk) = i(−1) Rotation using unit quaternions − = − jk i Intuition jk = i Using quaternions to represent rotations

Writing them all down: Why we love quaternions. ij = k, ji = −k jk = i, kj = −i ki = j, ik = −j

Quaternion products of i, j, k behave like cross . Lecture 8 Quaternion notation Quaternions

Overview, motivation

Background

We can write a quaternion several ways: Definition and properties q = q0 + q1i + q2j + q3k Rotation using unit quaternions q = (q0, q1, q2, q3) Intuition q = q + q Using quaternions 0 to represent rotations

Why we love Definition ( part; vector part) quaternions.

For quaternion q0 + q, q0 is the scalar part and q is the vector part Lecture 8 Quaternion product Quaternions

Overview, We can write a quaternion product several ways: motivation Background

Definition and pq = (p0 + p1i + p2j + p3k)(q0 + q1i + q2j + q3k) properties = (p0q0 − p1q1 − p2q2 − p3q3) + ... i + ... j + ... k Rotation using unit quaternions pq = (p0 + p)(q0 + q) Intuition = (p q + p q + q p + pq) Using quaternions 0 0 0 0 to represent rotations The last product includes many different kinds of product: Why we love quaternions. product of two reals, scalar product of vectors. But what is pq? ? ? Both! Cross product minus dot product!

pq = (p0q0 − p · q + p0q + q0p + p × q) Lecture 8 Conjugate, Quaternions Definition (Conjugate) Overview, motivation

∗ Background q = q0 − q1i − q2j − q3k Definition and properties

Rotation using unit Note that quaternions Intuition ∗ qq = (q0 + q)(q0 − q) Using quaternions to represent 2 rotations = q0 + q0q − q0q − qq 2 Why we love = q0 + q · q − q × q quaternions. 2 2 2 2 = q0 + q1 + q2 + q3

Definition (Length)

q p ∗ 2 2 2 2 |q| = qq = q0 + q1 + q2 + q3 Lecture 8 Quaternion inverse Quaternions

Overview, motivation Every quaternion except 0 has an inverse: Background q∗ Definition and −1 = properties q 2 |q| Rotation using unit quaternions Without commutativity, quaternions are a , or Intuition Using quaternions a non-commutative field, or a skew field. to represent Just as complex numbers are an extension of the reals, rotations Why we love quaternions are an extension of the complex numbers quaternions. (and of the reals). If 1D numbers are the reals, and 2D numbers are the complex numbers, then 4D numbers are quaternions, and that’s all there is. (Frobenius) ( are not associative.) Lecture 8 Rotation using unit quaternions Quaternions

Overview, motivation

Background

Definition and I Let q be a unit quaternion, i.e. |q| = 1. properties Rotation using unit I It can be expressed as quaternions θ θ Intuition q = cos + sin nˆ Using quaternions 2 2 to represent rotations

I Let x = 0 + x be a “pure vector”. Why we love 0 ∗ quaternions. I Let x = qxq . 0 I Then x is the pure vector rot(θ, nˆ)x!!! Lecture 8 Proof that unit quaternions work Quaternions

Overview, motivation

Background

Definition and properties ∗ Rotation using unit I Expand the product qxq ; quaternions

I Apply half formulas; Intuition Using quaternions I Simplify; to represent rotations

I Compare with Rodrigues’s formula. Why we love quaternions. Sadly, not all proofs confer insight. ∗ Lecture 8 Why θ/2? Why qxq instead of qx? Quaternions

Overview, In analogy with complex numbers, why not use motivation Background p = cos θ + nˆ sin θ Definition and properties 0 x = px Rotation using unit quaternions

Intuition To explore that idea, define a Lp(q) = pq. Note that Using quaternions Lp(q) can be written: to represent rotations

    Why we love p0 −p1 −p2 −p3 q0 quaternions.  p1 p0 −p3 p2   q1  Lp(q) =      p2 p3 p0 −p1   q2  p3 −p2 p1 p0 q3

Note that the above is orthonormal. Lp is a rotation of Euclidean 4 space! Lecture 8 Geometrical explanation Quaternions

Although Lp(q) rotates the 4D space of quaternions, it is Overview, not a rotation of the 3D subspace of pure vectors. Some motivation Background of the 3D subspace leaks into the fourth . Definition and Consider an example using p = i. Is it a rotation about i properties Rotation using unit of π/2? quaternions Intuition

Using quaternions to represent Li qiq iqiLR q Ri qqi i i rotations i iiWhy we love no quaternions. 1- i 2 2 rotation

1 1 1

k k k j- k plane 2 2

j jj Lecture 8 What do we do with a representation? Quaternions

∗ Rotate a : qxq . Overview, motivation Compose two rotations: Background Definition and q(pxp∗)q∗ = (qp)x(qp)∗ properties Rotation using unit quaternions

Convert to other representations: Intuition I From axis-angle to quaternion: Using quaternions to represent rotations θ θ q = cos + sin nˆ Why we love 2 2 quaternions.

I From quaternion to axis-angle:

−1 θ = 2 tan (|q|, q0) nˆ = q/|q|

assuming θ is nonzero. Lecture 8 From quaternion to Quaternions

Overview, motivation

Background

Definition and properties Just expand the product Rotation using unit quaternions qxq∗ = Intuition  2 2 2 2  Using quaternions q0 + q1 − q2 − q3 2(q1q2 − q0q3) 2(q1q3 + q0q2) to represent 2 2 2 2 rotations  2(q1q2 + q0q3) q0 − q1 + q2 − q3 2(q2q3 − q0q1)  x 2 2 2 2 Why we love 2(q1q3 − q0q2) 2(q2q3 + q0q1) q0 − q1 − q2 + q3 quaternions. Lecture 8 From rotation matrix to quaternion Quaternions

Overview, Given R = (rij ), solve expression on previous slide for motivation quaternion elements qi Background Definition and Linear combinations of diagonal elements seem to solve properties the problem: Rotation using unit quaternions

Intuition 2 1 q0 = (1 + r11 + r22 + r33) Using quaternions 4 to represent rotations 2 1 q1 = (1 + r11 − r22 − r33) Why we love 4 quaternions. 1 q2 = (1 − r + r − r ) 2 4 11 22 33 1 q2 = (1 − r − r + r ) 3 4 11 22 33 so take four roots and you’re done? You have to figure the signs out. There is a better way ... Lecture 8 Look at the off-diagonal elements Quaternions

Overview, I motivation 1 Background q0q1 = (r32 − r23) Definition and 4 properties 1 q q = (r − r ) Rotation using unit 0 2 4 13 31 quaternions 1 Intuition q0q3 = (r21 − r12) Using quaternions 4 to represent 1 rotations q1q2 = (r12 + r21) Why we love 4 quaternions. 1 q q = (r + r ) 1 3 4 13 31 1 q q = (r + r ) 2 3 4 23 32

I Given any one qi , could solve the above for the other three. Lecture 8 The procedure Quaternions

Overview, motivation 1. Use first four equations to find the largest q2. Take its Background i Definition and , with either . properties Rotation using unit 2. Use the last six equations (well, three of them quaternions anyway) to solve for the other qi . Intuition Using quaternions to represent I That way, only have to worry about getting one sign rotations right. Why we love quaternions. I Actually q and −q represent the same rotation, so no worries about signs.

I Taking the largest square root avoids division by small numbers. Lecture 8 Properties of unit quaternions Quaternions

Overview, motivation

Background

Definition and properties

Rotation using unit 4 quaternions I Unit quaternions live on the unit in R . Intuition

I Quaternions q and −q represent the same rotation. Using quaternions ∗ to represent I Inverse of rotation q is the conjugate q . rotations

Why we love I Null rotation, the identity, is the quaternion 1. quaternions. Lecture 8 Metric on SO(3) Quaternions

Overview, motivation

Background What is the right metric between two spatial rotations? Definition and properties I.e. between two points in SO(3)? Rotation using unit I provided an answer in Lecture 2! SO(3) is a quaternions Intuition configuration space. Let R and R be two displacements 1 2 Using quaternions of the sphere S2. Let x by a point on the sphere. Let α be to represent rotations

the usual metric on the sphere—the length of the shortest Why we love great arc joining two points. Define quaternions. d(R1, R2) = maxx∈S2 α(R1(x), R2(x)). That is equivalent −1 to taking the rotation angle of R1 R2. In brief, the angle of the rotation that takes you from R1 to R2. Lecture 8 Metric on sphere of unit quaternions Quaternions

I Consider unit quaternion Overview, motivation θ θ q = cos + sin nˆ Background 2 2 Definition and properties Shortest path on the joining ±q with 1 Rotation using unit quaternions

has length θ/2. Intuition I What is the shortest on the unit quaternion Using quaternions 3 to represent sphere S from ±p to ±q? rotations Why we love I Multiplication by a unit quaternion is a rotation of the quaternions. unit quaternion sphere. I.e. distance-preserving. So the distance from ±p to ±q is the same as the distance from ±pq∗ to 1. I.e. α/2, where α is the rotation angle required from p to q.

I So usual metric on the sphere, applied to unit quaternions, is the right metric for SO(3). (Factor of two is irrelevant.) Lecture 8 Topology of SO(3) Quaternions

Overview, motivation

Background

Definition and properties

Rotation using unit The right metric matters. Our representation is smooth quaternions and one-to-one, apart from the fact that antipodes Intuition represent the same rotation. That the unit Using quaternions to represent quaternions, with antipodes identified, have the same rotations topology as SO(3). That’s how we know the topology of Why we love quaternions. SO(3) is Projective 3-space, P3. Lecture 8 Measure, probabilities, sampling Quaternions

I Likewise we can our attention to measure. Overview, motivation I Easiest way is to think in terms of probabilities. Background Suppose you are given some probability density Definition and on SO(3). How can you decide whether it is properties Rotation using unit unbiased? quaternions I Pick some subset of SO(3), integrate the probability Intuition of that subset. Now rigidly rotate that subset. If the Using quaternions to represent probability is with respect to rotation, the rotations PDF is unbiased. A measure with this property is the Why we love quaternions. Haar measure, and it is uniquely determined some scale factor.

I Look at a uniform density function on the unit quaternion sphere S3. It has the right property — it is invariant with respect to rotations. The quaternion representation gives you the right measure, and is an easy way to correctly sample SO(3).