transformations cs 445/645 introduction to computer graphics david luebke, spring 2003
Post on 18-Jan-2016
227 Views
Preview:
TRANSCRIPT
Transformations
CS 445/645Introduction to Computer Graphics
David Luebke, Spring 2003
David Luebke 2 04/21/23
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 3 04/21/23
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:
■ Note that this translates all points uniformly
z
y
x
t
t
t
z
y
x
z
y
x
'
'
'
David Luebke 4 04/21/23
Recap: Scaling
● Scaling operation:
● Or, in matrix form:
cz
by
ax
z
y
x
'
'
'
z
y
x
c
b
a
z
y
x
00
00
00
'
'
'
scaling matrix
David Luebke 5 04/21/23
Recap: 3-D Rotation
● 3x3 matrix for rotation about the z-axis:
z
y
x
z
y
x
100
0)cos()sin(
0)sin()cos(
'
'
'
David Luebke 6 04/21/23
Recap: 3-D Rotation
● 3x3 matrix for rotation about the y-axis:
z
y
x
z
y
x
)cos(0)sin(
010
)sin(0)cos(
'
'
'
David Luebke 7 04/21/23
Recap: 3-D Rotation
● 3x3 matrix for rotation about the x-axis:
z
y
x
z
y
x
)cos()sin(0
)sin()cos(0
001
'
'
'
David Luebke 8 04/21/23
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 9 04/21/23
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 10 04/21/23
Composing Canonical Rotations
● Why are we slogging through all this tedium?● A: Because you’ll have to do it on the test
David Luebke 11 04/21/23
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 12 04/21/23
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 13 04/21/23
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 14 04/21/23
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 15 04/21/23
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:
jfc
ieb
hda
jih
fed
cba
jih
fed
cbaT1
David Luebke 16 04/21/23
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 17 04/21/23
Homogeneous Coordinates
● Homogeneous coordinates: represent coordinates in 3 dimensions with a 4-vector
(Note that typically w = 1 in object coordinates)
w
z
y
x
wz
wy
wx
zyx
1
/
/
/
),,(
David Luebke 18 04/21/23
Homogeneous Coordinates
● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
● Our transformation matrices are now 4x4:
1000
0)cos()sin(0
0)sin()cos(0
0001
xR
David Luebke 19 04/21/23
Homogeneous Coordinates
● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
● Our transformation matrices are now 4x4:
1000
0)cos(0)sin(
0010
0)sin(0)cos(
yR
David Luebke 20 04/21/23
Homogeneous Coordinates
● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
● Our transformation matrices are now 4x4:
1000
0100
00)cos()sin(
00)sin()cos(
zR
David Luebke 21 04/21/23
Homogeneous Coordinates
● Homogeneous coordinates seem unintuitive, but they make graphics operations much easier
● Our transformation matrices are now 4x4:
1000
000
000
000
z
y
x
S
S
S
S
David Luebke 22 04/21/23
Homogeneous Coordinates
● How can we represent translation as a 4x4 matrix?
● A: Using the rightmost column:
1 0 0
0 1 0
0 0 1
0 0 0 1
x
y
z
T
T
T
T
David Luebke 23 04/21/23
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:
w
z
y
x
w
z
y
x
1000
0)90cos()90sin(0
0)90sin()90cos(0
0001
1000
10100
0010
0001
'
'
'
'
David Luebke 24 04/21/23
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:
w
z
y
x
w
z
y
x
1000
0010
0100
0001
1000
10100
0010
0001
'
'
'
'
David Luebke 25 04/21/23
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:
w
z
y
x
w
z
y
x
1000
10010
0100
0001
'
'
'
'
David Luebke 26 04/21/23
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:
w
y
z
x
w
z
y
x
10
'
'
'
'
David Luebke 27 04/21/23
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 ?
top related