Homogeneous coordinates
Download
Report
Transcript Homogeneous coordinates
Transformations
CS 445/645
Introduction to Computer Graphics
David Luebke, Spring 2003
Admin
● Call roll
● Assn 1
■ Remember, due Monday 10 AM (ie, don’t skip class)
■ Several people have turned in already – nice job
David Luebke
2
3/27/2016
Recap: Translations
● For convenience we usually describe objects in
relation to their own coordinate system
● We can translate or move points to a new position
by adding offsets to their coordinates:
x' x tx
y ' y ty
z ' z tz
■ Note that this translates all points uniformly
David Luebke
3
3/27/2016
Recap: Scaling
● Scaling operation:
● Or, in matrix form:
x' ax
y ' by
z ' cz
x ' a 0 0 x
y' 0 b 0 y
z ' 0 0 c z
scaling matrix
David Luebke
4
3/27/2016
Recap: 3-D Rotation
● 3x3 matrix for rotation about the z-axis:
x' cos() sin( ) 0 x
y ' sin( ) cos() 0 y
z ' 0
0
1 z
David Luebke
5
3/27/2016
Recap: 3-D Rotation
● 3x3 matrix for rotation about the y-axis:
x' cos() 0 sin( ) x
y ' 0
1
0
y
z ' sin( ) 0 cos() z
David Luebke
6
3/27/2016
Recap: 3-D Rotation
● 3x3 matrix for rotation about the x-axis:
0
0 x
x' 1
y ' 0 cos() sin( ) y
z ' 0 sin( ) cos() z
David Luebke
7
3/27/2016
Recap:
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
8
3/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
9
3/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
10
3/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
11
3/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
12
3/27/2016
Compositing Matrices
● Remember: 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.
■ This is the rule with column vectors (OpenGL); row
vectors would be the opposite
● So in our case:
p’ = Ry-1 Rx -1 Rz Rx Ry p
David Luebke
13
3/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
orthogonal
● What is an orthogonal matrix?
● What property are we talking about?
David Luebke
14
3/27/2016
Rotation Matrices
● Rotation matrix is 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
15
T
c
a
f b
c
j
d
e
f
h
i
j
3/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
16
3/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
17
3/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
18
0
0
0
1
3/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
19
3/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
20
0 0
0 0
1 0
0 1
3/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
21
0 0
0 0
Sz 0
0 1
3/27/2016
Homogeneous Coordinates
● 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
22
3/27/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
23
0 x
0 y
0 z
1 w
3/27/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
24
0 0 0 x
0 1 0 y
1 0 0 z
0 0 1 w
3/27/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
25
3/27/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
26
3/27/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
27
3/27/2016