Unformatted text preview: Introduction to
Computer Graphics
CS 445 / 645
Gimbal Lecture 10
Chapter 7: Transformations Overview
Rotation representations
• Euler
• Axisangle
• Quaternion Camera Transformations
• Projections Basic 3D Transformations
Rotate around Z axis: x' cos Θ − sin Θ y ' sin Θ cos Θ z ' = 0
0
w 0
0 x ' cos Θ y ' 0
Rotate around Y axis: = z ' − sin Θ w 0 Rotate around X axis: x' 1 y ' 0 z ' = 0
w 0 0
1
0
0 0
0
1
0 0 x 0 y 0 z 1w sin Θ 0 x 0
0 y cos Θ 0 z 0
1w 0
0
cos Θ − sin Θ
sin Θ cos Θ
0
0 0 x 0 y 0 z 1w 3D Rotation
General rotations in 3D require rotating about an
General
arbitrary axis of rotation
arbitrary axis
Deriving the rotation matrix for such a rotation
Deriving
directly is a good exercise in linear algebra
directly
Standard approach: express general rotation as
Standard
composition of canonical rotations
composition
canonical
• Rotations about X, Y, Z
Rotations
X, Composing Canonical Rotations
Goal: rotate about arbitrary vector A by α
Goal:
• Idea: we know how to rotate about X,Y,Z
Idea:
– So, rotate about Y by θ until A lies in the YZ plane
So,
– Then rotate about X by ϕ until A coincides with +Z
Then
– Then rotate about Z by α
Then
– Then reverse the rotation about X (by ϕ)
Then
(by
– Then reverse the rotation about Y (by θ)
Then
(by Composing Canonical Rotations
First: rotating about Y by θ until A lies in YZ
First:
How exactly do we calculate θ ?
How
• Project A onto XZ plane (Throw away ycoordinate)
Project onto
• Find angle τ that rotates A to xaxis:
Find
xaxis
θ = (90°  τ) = τ  90 ° Second: rotating about xaxis by ϕ until A lies on zaxis
Second:
zaxis
How do we calculate ϕ ?
How Composing Matrices
So we have the following matrices:
• p: The point to be rotated about A by α
The
• Ryθ : Rotate about Y by θ
• Rx ϕ : Rotate about X by ϕ
• Rzα : Rotate about Z by α
1
• Rx ϕ 1: Undo rotation about X by ϕ
Undo • Ryθ1 : Undo rotation about Y by θ In what order should we multiply them? Compositing Matrices
Short answer: the transformations, in order, are
Short
written from right to left
right
left
• In other words, the first matrix to affect the vector goes next
In
to the vector, the second next to the first, etc.
to So in our case:
1
p’ = Ryθ 1 Rx ϕ 1 Rzα Rx ϕ Ryθ p
p’ Rotation Matrices
Notice these two matrices:
Rx ϕ : Rotate about X by ϕ
1
Rx ϕ 1: Undo rotation about X by ϕ
Undo
1
How can we calculate Rx ϕ 1? Rotation Matrices
Notice these two matrices:
Rx ϕ : Rotate about X by ϕ
1
Rx ϕ 1: Undo rotation about X by ϕ
Undo
1
How can we calculate Rx ϕ 1? • Obvious answer: calculate Rx (ϕ)
• Clever answer: exploit fact that rotation matrices are
Clever
orthonormal
orthonormal Rotation Matrices
Notice these two matrices:
Rx ϕ : Rotate about X by ϕ
1
Rx ϕ 1: Undo rotation about X by ϕ
Undo
1
How can we calculate Rx ϕ 1? • Obvious answer: calculate Rx (ϕ)
• Clever answer: exploit fact that rotation matrices are orthonormal
Clever What is an orthonormal matrix?
What
What property are we talking about? Rotation Matrices
Orthonormal matrix:
Orthonormal
• orthogonal (columns/rows linearly independent)
• normalized (columns/rows length of 1) The inverse of an orthogonal matrix is just its
The
transpose:
transpose:
−1
T
a b c a b c a d h d e f = d e f = b e i h i
h i
c f
j
j
j Representing 3 Rotational DOFs
3x3 Matrix (9 DOFs)
• Rows of matrix define orthogonal axes Euler Angles (3 DOFs)
• Rot x + Rot y + Rot z Axisangle (4 DOFs)
• Axis of rotation + Rotation amount Quaternion (4 DOFs)
• 4 dimensional complex numbers Rotation Matrices
What did we start with?
• 3 rotations (roll, pitch, yaw)
– Three numbers
– Called Euler Angles
• Axisangle
– Four numbers And we end up with a 4x4 transformation matrix
• Where inner 3x3 describes rotation Really, a whole matrix to represent three
numbers? Underconstrained?
9 DOFs must reduce to 3
Rows must be unit length (3 DOFs)
Rows must be orthogonal (3 DOFs)
Drifting matrices is very bad
• Numerical errors results when trying to gradually rotate matrix by
Numerical
adding derivatives
adding
• Resulting matrix may scale / shear
• GramSchmidt algorithm will reorthogonalize your matrix Difficult to interpolate between matrices
• Why would we do this? Euler Angles
(θ x, θ y, θ z) = RzRyRx
• Rotate θx degrees about xaxis
Rotate
• Rotate θy degrees about yaxis
Rotate
• Rotate θz degrees about zaxis
Rotate Axis order is not defined
• (y, z, x), (x, z, y), (z, y, x)…
are all legal
• Pick one Euler Angles
Rotations not uniquely defined
• ex: (z, x, y) = (90, 45, 45) = (45, 0, 45)
takes positive xaxis to (1, 1, 1)
• Cartesian coordinates are independent of one another, but
Cartesian
Euler angles are not
Euler Gimbal Lock
• Term derived from mechanical problem that arises in
Term
gimbal mechanism that supports a compass or a gyro
gimbal A Gimbal
Hardware implementation of Euler angles (used for
Hardware
mounting gyroscopes and globes)
mounting Gimbal Lock Gimbal Lock
Occurs when two axes are
Occurs
aligned
aligned
Second and third rotations
Second
have effect of transforming
earlier rotations
earlier
• ex: Rot x, Rot y, Rot z
– If Rot y = 90 degrees,
If
Rot z == Rot x
Rot Gimbal Lock http://www.anticz.com/eularqua.htm Interpolation
Interpolation between two Euler angles is not
Interpolation
unique
unique
ex: (x, y, z) rotation
• (0, 0, 0) to (180, 0, 0) vs. (0, 0, 0) to (0, 180, 180)
• Interpolation about different axes are not
Interpolation
independent
independent Interpolation Axisangle Notation
Define an axis of rotation (x, y, z) and a rotation
Define
about that axis, θ : R(θ , n)
R(
4 degrees of freedom specify 3 rotational degrees
degrees
of freedom because axis of rotation is
constrained to be a unit vector
constrained Axisangle Rotation
Given
r – Vector in space to rotate
n – Unitlength axis in space about which to rotate
θ – The amount about n to rotate
Solve
r’ – The rotated vector
nr r’ Axisangle Rotation
Step 1
• Compute rk an extended version of the rotation axis, n
• rk = (n ¢ r) n
rk
r r’ Axisangle Rotation
Compute r?
r? = r – (n ¢ r) n r?
r r’ Axisangle Rotation
Compute v, a vector perpendicular to rk and r?
v = rk £ r?
Use v and r? and θ to compute r’
Use v cos(θ) r? + sin(θ) v θ r? Axisangle Notation
rperp = r – (n.r) n
θ V = n x (r – (n.r) n) = n x r
Rr r rpar = (n.r) n
n Rr = Rrpar + Rrperp
= Rrpar + (cos θ) rperp + (sin θ) V
=(n.r) n + cos θ(r – (n.r)n) + (sin θ) n x r
= (cos θ)r + (1 – cos θ) n (n.r) + (sin θ) n x r Axisangle Notation
No easy way to determine how to concatenate
No
many axisangle rotations that result in final
desired axisangle rotation
desired
No simple way to interpolate rotations Quaternion
Remember complex numbers: a + ib
• Where i2 = 1 Invented by Sir William Hamilton (1843)
• Remember Hamiltonian path from Discrete II? Quaternion:
• Q = a + bi + cj + dk
– Where i2 = j2 = k2 = 1 and ij = k and ji = k
• Represented as: q = (s, v) = s + vxi + vyj + vzk
Represented Quaternion
A quaternion is a 4D unit vector q = [x y z w]
• It lies on the unit hypersphere x2 + y2 + z2 + w2 = 1 For rotation about (unit) axis v by angle θ
For
• vector part = (sin θ/2) v = [x y z]
vector
/2)
[x
• scalar part = (cos θ/2)
scalar
/2) =w • (sin(θ/2) vx, sin(θ/2) vy, sin(θ/2) vz, cos (θ/2))
z, cos Only a unit quaternion encodes a rotation  normalize Quaternion
Rotation matrix corresponding to a quaternion:
• [x y z w] = 1 − 2 y 2 − 2 z 2
[x
2 xy + 2 wz
2 xz − 2wy 2 xy − 2 wz 1 − 2 x 2 − 2 z 2
2 yz + 2 wx 2 xz + 2 wy
2 yz − 2wx 1 − 2 x 2 − 2 y 2 Quaternion Multiplication
Quaternion
• q1 * q2 = [v1, w1] * [v2, w2] = [(w1v2+w2v1+ (v1 x v2)), w1w2v1.v2]
• quaternion * quaternion = quaternion
• this satisfies requirements for mathematical group
this
group
• Rotating object twice according to two different quaternions is equivalent
Rotating
to one rotation according to product of two quaternions
to Quaternion Example
Xroll of π
Xroll
• (cos (π/2), sin (π/2) (1, 0, 0)) = (0, (1, 0, 0)) Yroll 0f π
Yroll
• (0, (0, 1, 0)) Zroll of π
Zroll
• (0, (0, 0, 1)) Ry (π ) followed by Rz (π )
• (0, (0, 1, 0) times (0, (0, 0, 1)) = (0, (0, 1, 0) x (0, 0, 1)
= (0, (1, 0, 0)) Quaternion Interpolation
Biggest advantage of quaternions
• Interpolation
• Cannot linearly interpolate between two quaternions
Cannot
because it would speed up in middle
because
• Instead, Spherical Linear Interpolation, slerp()
• Used by modern video games for thirdperson
Used
perspective
perspective
• Why? SLERP
Quaternion is a point on the 4D unit sphere
• interpolating rotations requires a unit quaternion at each step
– another point on the 4D unit sphere • move with constant angular velocity along the great circle between two points
move – A great circle is a section of a sphere that contains a diameter of the sphere
great
(Kern and Bland 1948, p. 87). Any rotation is defined by 2 quaternions, so pick the shortest SLERP
Any
To interpolate more than two points, solve a nonlinear variational
To
constrained optimization
constrained
• Ken Shoemake in SIGGRAPH ’85 (www.acm.org/dl) Quaternion Interpolation
Quaternion (white) vs.
Quaternion
Euler (black)
interpolation
interpolation
Left images are linear
Left
interpolation
interpolation
Right images are cubic
Right
interpolation
interpolation Quaternion Code
http://www.gamasutra.com/features/programming/
19980703/quaternions_01.htm
• Registration required Camera control code
• http://www.xmission.com/~nate/smooth.html
– File, gltb.c
– gltbMatrix and gltbMotion 3D Geometric Primitives Pipeline (for direct illumination)
Rendering
3D
Modeling
Transformation
Lighting Transform into 3D world coordinate system
Illuminate according to lighting and reflectance Viewing
Transformation Transform into 3D camera coordinate system Projection
Transformation Transform into 2D screen coordinate system Clipping
Scan
Conversion
Image Clip primitives outside camera’s view
Draw pixels (includes texturing, hidden surface, ...) Reminder: Homogeneous Coords
What effect does the following matrix have? x ' 1 y ' 0 = z ' 0 w' 0 0
1
0
0 0 x y 0 0 z 0 10w 0
0
1 Conceptually, the fourth coordinate w is a bit like a scale
Conceptually,
factor
factor Homogenous Coordinates
Increasing w makes things smaller
Increasing
We think of homogenous coordinates as defining
We
a projective space
projective
• Increasing w “getting further away”
Increasing Will come in handy for projection matrices Projection Matrix
We talked about geometric transforms, focusing on
We
modeling transforms
modeling
• Ex: translation, rotation, scale, gluLookAt()
Ex:
gluLookAt()
• These are encapsulated in the OpenGL modelview matrix
These
modelview Projection is also represented as a matrix
Next few slides: representing orthographic and
Next
perspective projection with the projection matrix
projection Taxonomy of Projections FVFHP Figure 6.10 Taxonomy of Projections Parallel Projection
Center of projection is at infinity
• Direction of projection (DOP) same for all points View
Plane DOP Angel Figure 5.4 Orthographic Projections
DOP perpendicular to view plane Front Angel Figure 5.5 Top Side Oblique Projections
DOP not perpendicular to view plane
DOP not φ = 45 Cavalier
o
(DOP α = 45 ) φ = 63.4 Cabinet
o
(DOP α = 63.4 )
H&B Figure 12.24 Orthographic Projection
Simple Orthographic
Transformation Original world units are preserved
• Pixel units are preferred Orthographic: Screen Space
Transformation
left =10 m right = 20 m top=20 m
(max pixx, max pixy)
(height in pixels)
bottom=10 m (0, 0)
(width in pixels) Orthographic: Screen Space
Transformation left, right, top, bottom refer to the viewing frustum in
left,
modeling coordinates
modeling
width and height are in pixel units
This matrix scales and translates to accomplish the
This
transition in units
transition ...
View
Full Document
 Spring '08
 BLOOMFIELD,A
 Cartesian Coordinate System, Computer Graphics, Rotation, Rotation matrix, Euler angles, Quaternion, Quaternions and spatial rotation

Click to edit the document details