Download Lecture 8. Quaternions

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Four-vector wikipedia , lookup

Orthogonal matrix wikipedia , lookup

Cross product wikipedia , lookup

Bivector wikipedia , lookup

Rotation matrix wikipedia , lookup

Transcript
Lecture 8.
Quaternions
Overview,
motivation
Background
Lecture 8.
Quaternions
Definition and
properties
Rotation using unit
quaternions
Intuition
Matthew T. Mason
Using quaternions
to represent
rotations
Why we love
quaternions.
Mechanics of Manipulation
Fall 2013
Today’s outline
Overview, motivation
Background
Lecture 8.
Quaternions
Overview,
motivation
Background
Definition and
properties
Rotation using unit
quaternions
Definition and properties
Intuition
Rotation using unit quaternions
Using quaternions
to represent
rotations
Why we love
quaternions.
Intuition
Using quaternions to represent rotations
Why we love quaternions.
Motivation
Lecture 8.
Quaternions
Overview,
motivation
Background
Motivation
I
Quaternions have nice geometrical interpretation.
I
Quaternions have advantages in representing
rotation.
I
Quaternions are cool. Even if you don’t want to use
them, you might need to defend yourself from
quaternion fanatics.
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Why can’t we invert vectors in R3 ?
Lecture 8.
Quaternions
Overview,
motivation
Background
1
x
I
We can invert reals. x ×
I
We can invert elements of R2 using complex
numbers. z × z ∗ /|z|2 = 1, where ∗ is complex
conjugate.
Can we invert v ∈ R3 ?
I
I
I
No.
How about v ∈
I
= 1.
R4 ?
Yes! Hamilton’s quaternions are to R4 what complex
numbers are to R2 .
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Complex numbers versus quaternions
Definition (Complex numbers)
Overview,
motivation
I
Define basis elements 1 and i;
I
Define complex numbers as a vector space over
reals: elements have the form x + iy ;
I
One more axiom required:
i2
Lecture 8.
Quaternions
= −1.
Definition (Quaternions)
I
Define basis elements 1, i, j, k ;
I
Define quaternions as a vector space over reals:
elements have the form q0 + q1 i + q2 j + q3 k ;
I
One more axiom:
i 2 = j 2 = k 2 = ijk = −1
Background
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Basis element multiplication
From that one axiom, we can derive other products:
Lecture 8.
Quaternions
Overview,
motivation
Background
ijk = −1
i(ijk ) = i(−1)
−jk = −i
jk = i
Writing them all down:
ij = k , ji = −k
jk = i, kj = −i
ki = j, ik = −j
Quaternion products of i, j, k behave like cross product.
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Quaternion notation
Lecture 8.
Quaternions
Overview,
motivation
We can write a quaternion several ways:
Background
Definition and
properties
q = q0 + q1 i + q2 j + q3 k
Rotation using unit
quaternions
q = (q0 , q1 , q2 , q3 )
Intuition
q = q0 + q
Definition (Scalar part; vector part)
For quaternion q0 + q, q0 is the scalar part and q is the
vector part
Using quaternions
to represent
rotations
Why we love
quaternions.
Quaternion product
We can write a quaternion product several ways:
Lecture 8.
Quaternions
Overview,
motivation
Background
pq = (p0 + p1 i + p2 j + p3 k )(q0 + q1 i + q2 j + q3 k )
= (p0 q0 − p1 q1 − p2 q2 − p3 q3 ) + . . . i + . . . j + . . . k
pq = (p0 + p)(q0 + q)
= (p0 q0 + p0 q + q0 p + pq)
The last product includes many different kinds of product:
product of two reals, scalar product of vectors. But what
is pq? Cross product? Dot product? Both! Cross product
minus dot product!
pq = (p0 q0 − p · q + p0 q + q0 p + p × q)
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Lecture 8.
Quaternions
Conjugate, length
Definition (Conjugate)
Overview,
motivation
q ∗ = q0 − q1 i − q2 j − q3 k
Background
Definition and
properties
Rotation using unit
quaternions
Note that
qq ∗ = (q0 + q)(q0 − q)
=
=
=
q02
q02
q02
+ q0 q − q0 q − qq
+q·q−q×q
+ q12 + q22 + q32
Definition (Length)
q
p
∗
|q| = qq = q02 + q12 + q22 + q32
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Lecture 8.
Quaternions
Quaternion inverse
Every quaternion except 0 has an inverse:
q −1 =
q∗
|q|2
Without commutativity, quaternions are a division ring, or
a non-commutative field, or a skew field.
Just as complex numbers are an extension of the reals,
quaternions are an extension of the complex numbers
(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) (Octonions are not
associative.)
Overview,
motivation
Background
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Rotation using unit quaternions
Lecture 8.
Quaternions
Overview,
motivation
Background
I
Let q be a unit quaternion, i.e. |q| = 1.
I
I
Rotation using unit
quaternions
It can be expressed as
q = cos
θ
θ
+ sin n̂
2
2
Let x = 0 + x be a “pure vector”.
x0
qxq ∗ .
I
Let
I
Then x 0 is the pure vector rot(θ, n̂)x!!!
=
Definition and
properties
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Proof that unit quaternions work
Lecture 8.
Quaternions
Overview,
motivation
Background
Definition and
properties
I
Expand the product qxq ∗ ;
Rotation using unit
quaternions
I
Apply half angle formulas;
Intuition
I
Simplify;
Using quaternions
to represent
rotations
I
Compare with Rodrigues’s formula.
Sadly, not all proofs confer insight.
Why we love
quaternions.
Why θ/2? Why qxq ∗ instead of qx?
Lecture 8.
Quaternions
Overview,
motivation
In analogy with complex numbers, why not use
Background
p = cos θ + n̂ sin θ
Definition and
properties
0
x = px
Rotation using unit
quaternions
To explore that idea, define a map Lp (q) = pq. Note that
Lp (q) can be written:


p0 −p1 −p2 −p3
q0
 p1 p0 −p3 p2   q1

Lp (q) = 
 p2 p3
p0 −p1   q2
p3 −p2 p1
p0
q3




Note that the matrix above is orthonormal. Lp is a rotation
of Euclidean 4 space!
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Lecture 8.
Quaternions
Geometrical explanation
Although Lp (q) rotates the 4D space of quaternions, it is
not a rotation of the 3D subspace of pure vectors. Some
of the 3D subspace leaks into the fourth dimension.
Consider an example using p = i. Is it a rotation about i
of π/2?
Overview,
motivation
Background
Definition and
properties
Rotation using unit
quaternions
Intuition
Li q
iq
i
Ri q
i
i
1
1
k
k
j- k plane
Li
iqi
2
2
1- i plane
qi
2
j
Ri
q
no
rotation
1
k
2
j
j
Using quaternions
to represent
rotations
Why we love
quaternions.
What do we do with a representation?
Rotate a point: qxq ∗ .
Lecture 8.
Quaternions
Overview,
motivation
Compose two rotations:
Background
q(pxp∗ )q ∗ = (qp)x(qp)∗
Definition and
properties
Rotation using unit
quaternions
Convert to other representations:
I
From axis-angle to quaternion:
q = cos
I
θ
θ
+ sin n̂
2
2
From quaternion to axis-angle:
θ = 2 tan−1 (|q|, q0 )
n̂ = q/|q|
assuming θ is nonzero.
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Lecture 8.
Quaternions
From quaternion to rotation matrix
Overview,
motivation
Background
Definition and
properties
Just expand the product
qxq ∗ =
 2
q0 + q12 − q22 − q32
 2(q1 q2 + q0 q3 )
2(q1 q3 − q0 q2 )
Rotation using unit
quaternions
Intuition
2(q1 q2 − q0 q3 )
− q12 + q22 − q32
2(q2 q3 + q0 q1 )
q02

2(q1 q3 + q0 q2 )
2(q2 q3 − q0 q1 )  x
q02 − q12 − q22 + q32
Using quaternions
to represent
rotations
Why we love
quaternions.
From rotation matrix to quaternion
Lecture 8.
Quaternions
Given R = (rij ), solve expression on previous slide for
quaternion elements qi
Overview,
motivation
Linear combinations of diagonal elements seem to solve
the problem:
Definition and
properties
1
q02 = (1 + r11 + r22 + r33 )
4
1
2
q1 = (1 + r11 − r22 − r33 )
4
1
q22 = (1 − r11 + r22 − r33 )
4
1
q32 = (1 − r11 − r22 + r33 )
4
so take four square roots and you’re done? You have to
figure the signs out. There is a better way . . .
Background
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Look at the off-diagonal elements
Overview,
motivation
I
1
q0 q1 = (r32 − r23 )
4
1
q0 q2 = (r13 − r31 )
4
1
q0 q3 = (r21 − r12 )
4
1
q1 q2 = (r12 + r21 )
4
1
q1 q3 = (r13 + r31 )
4
1
q2 q3 = (r23 + r32 )
4
I
Lecture 8.
Quaternions
Given any one qi , could solve the above for the other
three.
Background
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
The procedure
Lecture 8.
Quaternions
Overview,
motivation
1. Use first four equations to find the largest qi2 . Take its
square root, with either sign.
Background
2. Use the last six equations (well, three of them
anyway) to solve for the other qi .
Rotation using unit
quaternions
I
That way, only have to worry about getting one sign
right.
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.
Definition and
properties
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Properties of unit quaternions
Lecture 8.
Quaternions
Overview,
motivation
Background
Definition and
properties
Rotation using unit
quaternions
I
Unit quaternions live on the unit sphere in R4 .
I
Quaternions q and −q represent the same rotation.
I
Inverse of rotation q is the conjugate q ∗ .
Using quaternions
to represent
rotations
I
Null rotation, the identity, is the quaternion 1.
Why we love
quaternions.
Intuition
Metric on SO(3)
Lecture 8.
Quaternions
Overview,
motivation
Background
What is the right metric between two spatial rotations?
I.e. between two points in SO(3)?
I provided an answer in Lecture 2! SO(3) is a
configuration space. Let R1 and R2 be two displacements
of the sphere S 2 . Let x by a point on the sphere. Let α be
the usual metric on the sphere—the length of the shortest
great circle arc joining two points. Define
d(R1 , R2 ) = maxx∈S 2 α(R1 (x), R2 (x)). That is equivalent
to taking the rotation angle of R1−1 R2 . In brief, the angle
of the rotation that takes you from R1 to R2 .
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Metric on sphere of unit quaternions
I
Consider unit quaternion
q = cos
Lecture 8.
Quaternions
Overview,
motivation
θ
θ
+ sin n̂
2
2
Shortest path on the unit sphere joining ±q with 1
has length θ/2.
I
What is the shortest distance on the unit quaternion
sphere S 3 from ±p to ±q?
I
Multiplication by a unit quaternion is a rotation of the
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.)
Background
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Topology of SO(3)
Lecture 8.
Quaternions
Overview,
motivation
Background
Definition and
properties
The right metric matters. Our representation is smooth
and one-to-one, apart from the fact that antipodes
represent the same rotation. That means the unit
quaternions, with antipodes identified, have the same
topology as SO(3). That’s how we know the topology of
SO(3) is Projective 3-space, P3 .
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.
Measure, probabilities, sampling
I
Likewise we can turn our attention to measure.
I
Easiest way is to think in terms of probabilities.
Suppose you are given some probability density
function on SO(3). How can you decide whether it is
unbiased?
I
I
Pick some subset of SO(3), integrate the probability
of that subset. Now rigidly rotate that subset. If the
probability is invariant with respect to rotation, the
PDF is unbiased. A measure with this property is the
Haar measure, and it is uniquely determined up to
some scale factor.
Look at a uniform density function on the unit
quaternion sphere S 3 . 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).
Lecture 8.
Quaternions
Overview,
motivation
Background
Definition and
properties
Rotation using unit
quaternions
Intuition
Using quaternions
to represent
rotations
Why we love
quaternions.