presentation source

Download Report

Transcript presentation source

CS 551 / 645:
Introductory Computer Graphics
David Luebke
[email protected]
http://www.cs.virginia.edu/~cs551
David Luebke
4/8/2016
Recap: Rigid-Body Transforms


Goal: object coordinatesworld coordinates
Rigid-body transforms
– Translation
– Rotation
– Scale
David Luebke
4/8/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
4/8/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
4/8/2016
Recap: 2-D Rotation
(x’, y’)
(x, y)

David Luebke
 x' cos  sin   x 
 y '   sin  cos   y 
  
 
4/8/2016
Recap: 3-D Rotation

Easy to calculate rotations about canonical
axes:
 x' cos()  sin( ) 0  x 






Rz   y '   sin( ) cos() 0  y 
 z '   0
0
1  z 
David Luebke
4/8/2016
Recap: 3-D Rotation

Easy to calculate rotations about canonical
axes:
 x'  cos() 0 sin( )   x 






Ry   y '   0
1
0   y
 z '   sin( ) 0 cos()  z 
David Luebke
4/8/2016
Recap: 3-D Rotation

Easy to calculate rotations about canonical
axes:
0
0  x
 x' 1






Rx   y '  0 cos()  sin( )  y 
 z '  0 sin( ) cos()   z 
David Luebke
4/8/2016
Recap: General 3-D Rotation


Problem: rotate about an arbitrary axis of
rotation A
Approach: express as composition of
canonical rotations
David Luebke
4/8/2016
Recap: General 3-D Rotation

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
4/8/2016
Recap: 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 
Write transformations from right to left
– First matrix to affect vector immediately to left of
vector, then next, and so on.
David Luebke
4/8/2016
Recap: Compositing Matrices


So a rotation about an arbitrary vector:
p’ = Ry-1 Rx  -1 Rz Rx  Ry p
RA = Ry-1 Rx  -1 Rz Rx  Ry
 p’ = RA p
Pure rotation matrices are orthogonal, thus
their inverse is their transpose
– In fact, they’re orthonormal: vectors sum to 1
– This simplifies finding Ry-1 , etc.
David Luebke
4/8/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
4/8/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
4/8/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
4/8/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
4/8/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
4/8/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
4/8/2016
Translation Matrices


How can we represent translation as a
4x4 matrix?
A: Using the rightmost column:
1
0
T
0

0
David Luebke
0 0 Tx 
1 0 Ty 
0 1 Tz 

0 0 1
4/8/2016
Translation Matrices


Now that we can represent translation as a
matrix, we can composite it with other
transformations
Ex: rotate 90° about X, then 10 units down Z:
 x'  1
 y '  0
 
 z '  0
  
 w' 0
David Luebke
0 0 0  1
0
0
1 0 0  0 cos(90)  sin( 90)
0 1 10 0 sin( 90) cos(90)

0 0 1  0
0
0
0  x 
0  y 
0  z 
 
1   w
4/8/2016
Translation Matrices


Now that we can represent translation as a
matrix, we can composite it with other
transformations
Ex: rotate 90° about X, then 10 units down Z:
 x'  1
 y '  0
 
 z '  0
  
 w' 0
David Luebke
0 0 0  1
1 0 0  0
0 1 10 0

0 0 1  0
0 0 0  x 
0  1 0  y 
1 0 0  z 
 
0 0 1   w
4/8/2016
Translation Matrices


Now that we can represent translation as a
matrix, we can composite it with other
transformations
Ex: rotate 90° about X, then 10 units down Z:
 x'  1
 y '  0
 
 z '  0
  
 w' 0
David Luebke
0 0 0  x 
0  1 0   y 
1 0 10  z 
 
0 0 1   w
4/8/2016
Translation Matrices


Now that we can represent translation as a
matrix, we can composite it with other
transformations
Ex: rotate 90° about X, then 10 units down Z:
 x'   x 
 y'   z 
 

 z '   y  10
  

 w'  w 
David Luebke
4/8/2016
Transformation Commutativity


Is matrix multiplication, in general,
commutative? Does AB = BA?
What about rotation, scaling, and translation
matrices?
– Does RxRy = RyRx?
– Does RAS = SRA ?
– Does RAT = TRA ?
David Luebke
4/8/2016
More On Homogeneous Coords

What effect does the following matrix have?
 x'  1
 y '  0
 
 z '  0
  
 w' 0

0  x 



0  y 
0  z 
 
0 0 10  w
0 0
1 0
0 1
Conceptually, the fourth coordinate w is a bit
like a scale factor
David Luebke
4/8/2016
Homogenous Coordinates


In particular, increasing w makes things
smaller
We think of homogenous coordinates as
defining a projective space
– Increasing w  “getting further away”
– Points with w =  are, in this sense, projected on
the plane at infinity


Will come in handy for projection matrices
For deeper math intution, take projective
geometry someday
David Luebke
4/8/2016