Lect07 PDF
Lect07 PDF
P
PP
PP
PP
PP
PP
q
P
z
w
PP
PP
PP
PP
PP
q
P
z = w
PP
PP
PP
PP
PP
z
q
P
P
PP
PP
PP
PP
PP
q
x
u
x
x
(c) Rotate about z so that
(a) Rotate about x so that (b) Rotate about y so that
u and v coincide with x
w lies in xz -plane.
w coincides with z .
and y .
Rotating a frame to coincide with the standard frame
z
z
PPP
PP
PP
PP
q
any rotation in 3-space as triple of numbers, each in the range [0, 2].
With ca = cos(a) and sa = sin(a),
cy cz
sxsy cz cxsz
R(x, y , z ) =
c x sy c z + sx sz
0
c y sz
sx sy sz + c x c z
c x sy sz sx c z
0
sy
sx c y
cx cy
0
0
0
0
1
1 0
0
0 cx sx
Rx(x) =
0 sx
cx
0 0
0
cy
0 sy
0
1 0
Ry (y ) =
sy 0 cy
0
0 0
cz sz 0
sz
cz
0
Rz (z ) =
0
0
1
0
0
0
0
0
0
1
0
0
0
1
0
0
0
1
glMatrixMode (GL_MODELVIEW);
glRotatef(45, 1, 0, 0);
glRotatef(45, 0, 1, 0);
glRotatef(45, 0, 0, 1);
glutAirPlane(1);
Quaternions:
i = j = k = 1 ij = k, jk = i, ki = j.
Combining these, it follows that ji = k, kj = i and ik = j . A quaternion is defined
to be a generalized complex number of the form
q = q0 + q1i + q2j + q3k.
We will see that quaternions bear a striking resemblance to our notation for angular
displacement. In particular, we can rewrite the quaternion notation in terms of a scalar and
vector as
q = (s, ~
u) = s + uxi + uy j + uz k.
Furthermore define the product of quaternions to be
q1q2 = (s1 s2 (~
u1 ~
u2 ),
s1 ~
u2 + s2~
u1 + ~
u1 ~
u2 ).
|q|2 = q q = s2 + |~
u|2.
A unit quaternion is one of unit magnitude, |q| = 1. A pure quaternion is one with a 0
scalar component
p = (0, ~
v ).
Any quaternion of nonzero magnitude has a multiplicative inverse, which is
1
q.
2
|q|
Rq (p) = qpq .
Rq (p) = (0, (s2 (~
u~
u))~
v + 2~
u(~
u~
v ) + 2s(~
u~
v )).
Unit quaternions can be shown to be isomorphic to orientations and given by
q = (cos , (sin )~
u),
The University of Texas at Austin
where |~
u| = 1.
8
p = (0, ~
v ),
and we encode a rotation by angle about a unit vector u as a unit quaternion
q = (cos(/2), sin(/2)~
u),
then the image of the point under this rotation is given by the vector part of the result of
the quaternion rotation operator Rq (p) = qpq 1.
y
x
Rotation example.
10
Composing Rotations:
Rq Rq = Rq
where q = q q.
This follows from the associativity of quaternion multiplication, and the fact that (qq )1 =
1
q 1q , as shown below.
)q
= (q q)p(q 1q 1)
= (q q)p(qq )1
= q pq
= Rq (p).
11
q = (cos(/2), sin(/2)~
u) = (w, (x, y, z))
what is the corresponding affine transformation (expressed as a rotation matrix). By simply
expanding the definition of Rq (p), it is not hard to show that the following (homogeneous)
matrix is equivalent
1 2y 2 2z 2
2xy 2wz
2xz + 2wy
0
2
2
2xy + 2wz
1
2x
2z
2yz 2wx
0
2
2
2xz 2wy
2yz + 2wx
1 2x 2y
0
0
0
0
1
To convert from an orthogonal rotation matrix to a unit quaternion, we observe that if
M = [mi,j ] is the affine transformation in homogeneous form,
2
trace(M ) = 4 4(x + y + z ) = 4w .
The University of Texas at Austin
12
Once we have w, we can find the order quantities by cancelling symmetric terms:
m32 m23
,
x=
4w
m13 m31
y=
,
4w
m21 m12
z=
4w
13
Pitch
Rotation Axis = 1, 0, 0, 0
Rotation Angle = /4
Quaternion Vector = 0.382683 0.000000 0.000000 0.923880
14
Yaw
Rotation Axis = 0, 1, 0, 0
Rotation Angle = /4
Quaternion Vector = 0.000000 0.382683 0.000000 0.923880
15
Roll
Rotation Axis = 0, 0, 1, 0
Rotation Angle = /4
Quaternion Vector = 0.000000 0.000000 0.382683 0.923880
16
Additonal Examples
The following web-page contains a good quaternion intro and C++ source codes:
http://www.lboro.ac.uk/departments/ma/gallery/quat/intro.html
17
Before the next class please review Chapter 3 and its practice exercises, of the recommended
text.
(Recommended Text: Interactive Computer Graphics, by Edward Angel, Dave Shreiner, 6th
edition, Addison-Wesley)
Please track Blackboard for the most recent Announcements and Project postings related to
this course.
(http://www.cs.utexas.edu/users/bajaj/graphics2012/cs354/)
18