Download presentation source

Download Report

Transcript Download presentation source

CS 551 / 645:
Introductory Computer Graphics
David Luebke
[email protected]
http://www.cs.virginia.edu/~cs551
David Luebke
7/27/2016
Administrivia


Five late days, not three
Compile assignment 4 on sgi-1.unixlab
David Luebke
7/27/2016
Recap: Rigid-Body Transforms


Goal: object coordinatesworld coordinates
Rigid-body transforms
– Preserve basic shape of object
– Includes rotation, translation, and scale

We represent points as column vectors:
 x


( x, y , z )   y 
 z 
David Luebke
7/27/2016
Recap: Translation


Translate: move all points on an object
uniformly by (tx, ty, tz)
In other words, add a vector t to every point:
 x'  x  tx 
 y '   y   ty 
     
 z '   z  tz 
David Luebke
7/27/2016
Recap: Scaling


Scaling a coordinate means multiplying each
of its components by a scalar
Uniform scaling means this scalar is the
same for all components:
2
David Luebke
7/27/2016
Recap: Scaling

Non-uniform scaling: multiply coordinates by
scalars sx, sy, sz :
X  2,
Y  0.5
David Luebke
7/27/2016
Recap: Scaling

Scaling can be represented in matrix form:
 x'  Sx 0 0   x 
 y '   0 Sy 0   y 
  
 
 z '   0 0 Sz   z 
scaling matrix
David Luebke
7/27/2016
2-D Rotation
(x’, y’)
(x, y)

David Luebke
x’ = x cos() - y sin()
y’ = x sin() + y cos()
(Draw it)
7/27/2016
2-D Rotation

This is easy to capture in matrix form:
 x' cos  sin   x 
 y '   sin  cos   y 
  
 

3-D is more complicated
– Need to specify an axis of rotation
– Simple cases: rotation about X, Y, Z axes
David Luebke
7/27/2016
3-D Rotation

What does the 3-D rotation matrix look like
for a rotation about the Z-axis?
– Build it coordinate-by-coordinate
 x' cos()  sin( ) 0  x 
 y '   sin( ) cos() 0  y 
  
 
 z '   0
0
1  z 
David Luebke
7/27/2016
3-D Rotation

What does the 3-D rotation matrix look like
for a rotation about the Y-axis?
– Build it coordinate-by-coordinate
 x'  cos() 0 sin( )   x 
 y '   0



1
0
y
  
 
 z '   sin( ) 0 cos()  z 
David Luebke
7/27/2016
3-D Rotation

What does the 3-D rotation matrix look like
for a rotation about the X-axis?
– Build it coordinate-by-coordinate
0
0  x
 x' 1
 y '  0 cos()  sin( )  y 
  
 
 z '  0 sin( ) cos()   z 
David Luebke
7/27/2016
3-D Rotation


General rotations in 3-D require rotating
about an arbitrary axis of rotation
Deriving the rotation matrix for such a
rotation directly is difficult
– But possible, see McMillan’s lectures

Standard approach: express general rotation
as composition of canonical rotations
– Rotations about X, Y, Z
David Luebke
7/27/2016
Composing Canonical Rotations

Goal: rotate about arbitrary vector A by 
– Idea: we know how to rotate about X,Y,Z
So, rotate about Y by  until A lies in the YZ plane
Then rotate about X by  until A coincides with +Z
Then rotate about Z by 
Then reverse the rotation about X (by -)
Then reverse the rotation about Y (by -)
David Luebke
7/27/2016
Composing Canonical Rotations

First: rotating about Y by  until A lies in YZ
– Draw it…

How exactly do we calculate ?
– Project A onto XZ plane
– Find angle  to X:
 = -(90° - ) =  - 90 °


Second: rotating about X by  until A lies on Z
How do we calculate ?
David Luebke
7/27/2016
Composing Canonical Rotations


Why are we slogging through all this tedium?
A: Because you’ll have to do it on the test
David Luebke
7/27/2016
3-D Rotation Matrices





So an arbitrary rotation about A composites
several canonical rotations together
We can express each rotation as a matrix
Compositing transforms == multiplying
matrices
Thus we can express the final rotation as the
product of canonical rotation matrices
Thus we can express the final rotation with a
single matrix!
David Luebke
7/27/2016
Compositing Matrices
So we have the following matrices:
p: The point to be rotated about A by 
Ry : Rotate about Y by 
Rx  : Rotate about X by 
Rz : Rotate about Z by 
Rx  -1: Undo rotation about X by 
Ry-1 : Undo rotation about Y by 
 In what order should we multiply them?

David Luebke
7/27/2016
Compositing Matrices

Short answer: the transformations, in order,
are written from right to left
– In other words, the first matrix to affect the vector
goes next to the vector, the second next to the
first, etc.
So in our case:
p’ = Ry-1 Rx  -1 Rz Rx  Ry p

David Luebke
7/27/2016
Rotation Matrices


Notice these two matrices:
Rx  : Rotate about X by 
Rx  -1: Undo rotation about X by 
How can we calculate Rx  -1?
David Luebke
7/27/2016
Rotation Matrices


Notice these two matrices:
Rx  : Rotate about X by 
Rx  -1: Undo rotation about X by 
How can we calculate Rx  -1?
– Obvious answer: calculate Rx (-)
– Clever answer: exploit fact that rotation matrices
are orthonormal
David Luebke
7/27/2016
Rotation Matrices


Notice these two matrices:
Rx  : Rotate about X by 
Rx  -1: Undo rotation about X by 
How can we calculate Rx  -1?
– Obvious answer: calculate Rx (-)
– Clever answer: exploit fact that rotation matrices
are orthonormal


What is an orthonormal matrix?
What property are we talking about?
David Luebke
7/27/2016
Rotation Matrices

Orthonormal matrix:
– orthogonal (columns/rows linearly independent)
– Columns/rows sum to 1

The inverse of an orthogonal matrix is just its
transpose:
a b
d e

 h i
David Luebke
1
c
a b


f   d e
 h i
j 
T
c
a


f   b
 c
j 
d
e
f
h

i
j 
7/27/2016
Translation Matrices?



We can composite scale matrices just as we
did rotation matrices
But how to represent translation as a matrix?
Answer: with homogeneous coordinates
David Luebke
7/27/2016
Homogeneous Coordinates

Homogeneous coordinates: represent
coordinates in 3 dimensions with a 4-vector
 x / w  x 
 y / w  y 
 
( x, y , z )  
 z / w  z 

  
 1   w
(Note that typically w = 1 in object coordinates)
David Luebke
7/27/2016
Homogeneous Coordinates


Homogeneous coordinates seem unintuitive,
but they make graphics operations much
easier
Our transformation matrices are now 4x4:
0
0
1
0 cos()  sin( )
Rx  
0 sin( ) cos()

0
0
0
David Luebke
0
0
0

1
7/27/2016
Homogeneous Coordinates


Homogeneous coordinates seem unintuitive,
but they make graphics operations much
easier
Our transformation matrices are now 4x4:
 cos()
 0
Ry  
 sin( )

 0
David Luebke
0 sin( ) 0
1
0
0
0 cos() 0

0
0
1
7/27/2016
Homogeneous Coordinates


Homogeneous coordinates seem unintuitive,
but they make graphics operations much
easier
Our transformation matrices are now 4x4:
cos()  sin( )
 sin( ) cos()
Rz  
 0
0

0
 0
David Luebke
0 0
0 0
1 0

0 1
7/27/2016
Homogeneous Coordinates


Homogeneous coordinates seem unintuitive,
but they make graphics operations much
easier
Our transformation matrices are now 4x4:
 Sx 0
 0 Sy
S
0 0

0 0
David Luebke
0 0
0 0
Sz 0 

0 1
7/27/2016
Homogeneous Coordinates


How can we represent translation as a
4x4 matrix?
A: Using the rightmost column:
0
0
T
0

0
David Luebke
0 0 Tx 
0 0 Ty 
0 0 Tz 

0 0 1
7/27/2016