Professional Documents
Culture Documents
Computer Graphics
CS 445 / 645
Lecture 5
Lecture 5
Transformations
Transformations
Lecture 5
Lecture 5
Transformations
Transformations
M.C. Escher Smaller and Smaller (1956)
Modeling Transformations
Specify transformations for objects
Specify transformations for objects
Allows definitions of objects in own coordinate systems Allows definitions of objects in own coordinate systems
Allows use of object definition multiple times in a scene Allows use of object definition multiple times in a scene
Remember how OpenGL provides a transformation Remember how OpenGL provides a transformation
stack because they are so frequently reused stack because they are so frequently reused
Chapter 5 from Hearn and Baker
Chapter 5 from Hearn and Baker
Specify transformations for objects
Specify transformations for objects
Allows definitions of objects in own coordinate systems Allows definitions of objects in own coordinate systems
Allows use of object definition multiple times in a scene Allows use of object definition multiple times in a scene
Remember how OpenGL provides a transformation Remember how OpenGL provides a transformation
stack because they are so frequently reused stack because they are so frequently reused
Chapter 5 from Hearn and Baker
Chapter 5 from Hearn and Baker
H&B Figure 109
Overview
2D Transformations
2D Transformations
Same as 2D Same as 2D
2D Transformations
2D Transformations
Same as 2D Same as 2D
2D Modeling Transformations
Scale
Rotate
Translate
Scale
Translate
x
y
World Coordinates
Modeling
Coordinates
2D Modeling Transformations
x
y
World Coordinates
Modeling
Coordinates
Lets look
at this in
detail
2D Modeling Transformations
x
y
Modeling
Coordinates
Initial location
at (0, 0) with
x- and y-axes
aligned
2D Modeling Transformations
x
y
Modeling
Coordinates
Scale .3, .3
Rotate -90
Translate 5, 3
2D Modeling Transformations
x
y
Modeling
Coordinates
Scale .3, .3
Rotate -90
Translate 5, 3
2D Modeling Transformations
x
y
Modeling
Coordinates
Scale .3, .3
Rotate -90
Translate 5, 3
World Coordinates
Scaling
Scaling Scaling a coordinate means multiplying each of its a coordinate means multiplying each of its
components by a scalar components by a scalar
Uniform scaling Uniform scaling means this scalar is the same for all means this scalar is the same for all
components: components:
Scaling Scaling a coordinate means multiplying each of its a coordinate means multiplying each of its
components by a scalar components by a scalar
Uniform scaling Uniform scaling means this scalar is the same for all means this scalar is the same for all
components: components:
2
Non-uniform scaling Non-uniform scaling: different scalars per component: : different scalars per component:
How can we represent this in matrix form? How can we represent this in matrix form?
Non-uniform scaling Non-uniform scaling: different scalars per component: : different scalars per component:
How can we represent this in matrix form? How can we represent this in matrix form?
Scaling
X 2,
Y 0.5
Scaling
Scaling operation:
Scaling operation:
Or, in matrix form:
Or, in matrix form:
Scaling operation:
Scaling operation:
Or, in matrix form:
Or, in matrix form:
]
]
]
]
]
]
by
ax
y
x
'
'
]
]
]
]
]
]
]
]
]
y
x
b
a
y
x
0
0
'
'
scaling matrix
2-D Rotation
(x, y)
(x, y)
x = x cos( ) - y sin( )
y = x sin( ) + y cos( )
2-D Rotation
x = r cos ( )
y = r sin ( )
x = r cos ( + )
y = r sin ( + )
Trig Identity
x = r cos( ) cos( ) r sin( ) sin( )
y = r sin( ) sin( ) + r cos( ) cos( )
Substitute
x = x cos( ) - y sin( )
y = x sin( ) + y cos( )
(x, y)
(x, y)
2-D Rotation
This is easy to capture in matrix form:
This is easy to capture in matrix form:
Even though sin(
Even though sin(
) and cos(
) and cos(
) are nonlinear
) are nonlinear
functions of
functions of
,
,
) and cos(
) and cos(
) are nonlinear
) are nonlinear
functions of
functions of
,
,
]
]
]
]
]
]
y
x
y
x
cos sin
sin cos
'
'
Basic 2D Transformations
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x * s x = x * s
x x
y = y * s y = y * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
x = x*cos x = x*cos - y*sin - y*sin
y = x*sin y = x*sin + y*cos + y*cos
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x * s x = x * s
x x
y = y * s y = y * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
x = x*cos x = x*cos - y*sin - y*sin
y = x*sin y = x*sin + y*cos + y*cos
Transformations
can be combined
(with simple algebra)
Basic 2D Transformations
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x * s x = x * s
x x
y = y * s y = y * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
x = x*cos x = x*cos - y*sin - y*sin
y = x*sin y = x*sin + y*cos + y*cos
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x * s x = x * s
x x
y = y * s y = y * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
x = x*cos x = x*cos - y*sin - y*sin
y = x*sin y = x*sin + y*cos + y*cos
Basic 2D Transformations
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x x = x * s * s
x x
y = y y = y * s * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
x = x*cos x = x*cos - y*sin - y*sin
y = x*sin y = x*sin + y*cos + y*cos
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x x = x * s * s
x x
y = y y = y * s * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
x = x*cos x = x*cos - y*sin - y*sin
y = x*sin y = x*sin + y*cos + y*cos
x = x*s
x
y = y*s
y
x = x*s
x
y = y*s
y
(x,y)
(x,y)
Basic 2D Transformations
x = (x*s
x
)*cos - (y*s
y
)*sin
y = (x*s
x
)*sin + (y*s
y
)*cos
x = (x*s
x
)*cos - (y*s
y
)*sin
y = (x*s
x
)*sin + (y*s
y
)*cos
(x,y)
Translation: Translation:
x = x + t x = x + t
x x
y = y + t y = y + t
y y
Scale: Scale:
x = x * s x = x * s
x x
y = y * s y = y * s
y y
Shear: Shear:
x = x + h x = x + h
x x
*y *y
y = y + h y = y + h
y y
*x *x
Rotation: Rotation:
Same as 2D Same as 2D
2D Transformations
2D Transformations
Same as 2D Same as 2D
Matrix Representation
Represent 2D transformation by a matrix
Represent 2D transformation by a matrix
Multiply matrix by column vector
Multiply matrix by column vector
]
]
]
]
]
]
y
x
d c
b a
y
x
'
'
]
]
]
d c
b a
dy cx y
by ax x
+
+
'
'
Matrix Representation
Transformations combined by multiplication
Transformations combined by multiplication Transformations combined by multiplication
Transformations combined by multiplication
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
y
x
l k
j i
h g
f e
d c
b a
y
x
'
'
Matrices are a convenient and efficient way
to represent a sequence of transformations!
2x2 Matrices
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
2D Identity?
y y
x x
'
'
]
]
]
]
]
]
]
]
]
y
x
y
x
1 0
0 1
'
'
2D Scale around (0,0)?
y s y
x s x
y
x
* '
* '
]
]
]
]
]
]
]
]
]
y
x
s
s
y
x
y
x
0
0
'
'
2x2 Matrices
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
2D Rotate around (0,0)?
y x y
y x x
* cos * sin '
* sin * cos '
+
]
]
]
]
]
]
]
]
]
y
x
y
x
cos sin
sin cos
'
'
2D Shear?
y x sh y
y sh x x
y
x
+
+
* '
* '
]
]
]
]
]
]
]
]
]
y
x
sh
sh
y
x
y
x
1
1
'
'
2x2 Matrices
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
2D Mirror about Y axis?
y y
x x
'
'
]
]
]
]
]
]
]
]
]
y
x
y
x
1 0
0 1
'
'
2D Mirror over (0,0)?
y y
x x
'
'
]
]
]
]
]
]
]
]
]
y
x
y
x
1 0
0 1
'
'
2x2 Matrices
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
What types of transformations can be
What types of transformations can be
represented with a 2x2 matrix?
represented with a 2x2 matrix?
2D Translation?
y
x
t y y
t x x
+
+
'
'
Only linear 2D transformations
can be represented with a 2x2 matrix
NO!
Linear Transformations
Linear transformations are combinations of Linear transformations are combinations of
Scale, Scale,
Rotation, Rotation,
Mirror Mirror
Properties of linear transformations: Properties of linear transformations:
Satisfies: Satisfies:
Scale, Scale,
Rotation, Rotation,
Mirror Mirror
Properties of linear transformations: Properties of linear transformations:
Satisfies: Satisfies:
]
]
]
]
]
]
y
x
d c
b a
y
x
'
'
Homogeneous Coordinates
Q: How can we represent translation as a 3x3 matrix?
Q: How can we represent translation as a 3x3 matrix? Q: How can we represent translation as a 3x3 matrix?
Q: How can we represent translation as a 3x3 matrix?
y
x
t y y
t x x
+
+
'
'
Homogeneous Coordinates
Homogeneous coordinates Homogeneous coordinates
]
]
]
1
coords s homogeneou
y
x
y
x
Homogeneous coordinates seem unintuitive, but they
make graphics operations much easier
Homogeneous coordinates seem unintuitive, but they
make graphics operations much easier
Homogeneous Coordinates
Q: How can we represent translation as a 3x3 matrix?
Q: How can we represent translation as a 3x3 matrix?
A: Using the rightmost column:
A: Using the rightmost column:
Q: How can we represent translation as a 3x3 matrix?
Q: How can we represent translation as a 3x3 matrix?
A: Using the rightmost column:
A: Using the rightmost column:
]
]
]
]
]
1 0 0
1 0
0 1
y
x
t
t
ranslation T
y
x
t y y
t x x
+
+
'
'
Translation
Example of translation Example of translation
]
]
]
]
]
+
+
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
1 1 1 0 0
1 0
0 1
1
'
'
y
x
y
x
t y
t x
y
x
t
t
y
x
t
x
= 2
t
y
= 1
Homogeneous Coordinates Homogeneous Coordinates
Homogeneous Coordinates
Add a 3rd coordinate to every 2D point Add a 3rd coordinate to every 2D point
(x, y, w) represents a point at location (x/w, y/w) (x, y, w) represents a point at location (x/w, y/w)
(x, y, w) represents a point at location (x/w, y/w) (x, y, w) represents a point at location (x/w, y/w)
]
]
]
]
]
]
]
]
]
]
1 1 0 0
0 cos sin
0 sin cos
1
'
'
y
x
y
x
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
1 1 0 0
1 0
0 1
1
'
'
y
x
t
t
y
x
y
x
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
1 1 0 0
0 1
0 1
1
'
'
y
x
sh
sh
y
x
y
x
Translate
Rotate Shear
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
1 1 0 0
0 0
0 0
1
'
'
y
x
s
s
y
x
y
x
Scale
Affine Transformations
Affine transformations are combinations of Affine transformations are combinations of
Translations Translations
Properties of affine transformations: Properties of affine transformations:
Origin does not necessarily map to origin Origin does not necessarily map to origin
Translations Translations
Properties of affine transformations: Properties of affine transformations:
Origin does not necessarily map to origin Origin does not necessarily map to origin
]
]
]
]
]
]
]
]
w
y
x
f e d
c b a
w
y
x
1 0 0
'
'
Projective Transformations
Projective transformations Projective transformations
Origin does not necessarily map to origin Origin does not necessarily map to origin
Parallel lines do not necessarily remain parallel Parallel lines do not necessarily remain parallel
Origin does not necessarily map to origin Origin does not necessarily map to origin
Parallel lines do not necessarily remain parallel Parallel lines do not necessarily remain parallel
]
]
]
]
]
]
]
]
w
y
x
i h g
f e d
c b a
w
y
x
'
'
'
Overview
2D Transformations
2D Transformations
Same as 2D Same as 2D
2D Transformations
2D Transformations
Same as 2D Same as 2D
Matrix Composition
Transformations can be combined by
Transformations can be combined by
matrix multiplication
matrix multiplication
Transformations can be combined by
Transformations can be combined by
matrix multiplication
matrix multiplication
]
]
]
]
,
`
.
|
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
y
x
sy
sx
ty
tx
w
y
x
1 0 0
0 0
0 0
1 0 0
0 cos sin
0 sin cos
1 0 0
1 0
0 1
'
'
'
p = T(t
x
,t
y
) R( ) S(s
x
,s
y
) p
Matrix Composition
Matrices are a convenient and efficient way to
Matrices are a convenient and efficient way to
represent a sequence of transformations
represent a sequence of transformations
Ex: Ex: Rotate line segment by 45 degrees about endpoint Rotate line segment by 45 degrees about endpoint a a
and lengthen and lengthen
What if we want to rotate
What if we want to rotate
and
and
translate?
translate?
Ex: Ex: Rotate line segment by 45 degrees about endpoint Rotate line segment by 45 degrees about endpoint a a
and lengthen and lengthen
a a
Multiplication Order Wrong Way
Our line is defined by two endpoints Our line is defined by two endpoints
Applying a rotation of 45 degrees, R(45), affects both points Applying a rotation of 45 degrees, R(45), affects both points
We could try to translate both endpoints to return endpoint We could try to translate both endpoints to return endpoint a a to its to its
original position, but by how much? original position, but by how much?
Our line is defined by two endpoints Our line is defined by two endpoints
Applying a rotation of 45 degrees, R(45), affects both points Applying a rotation of 45 degrees, R(45), affects both points
We could try to translate both endpoints to return endpoint We could try to translate both endpoints to return endpoint a a to its to its
original position, but by how much? original position, but by how much?
Wrong Correct
T(-3) R(45) T(3)
R(45)
a
a
a
Multiplication Order - Correct
Isolate endpoint
Isolate endpoint
a
a
from rotation effects
from rotation effects
First translate line so First translate line so a a is at origin: T (-3) is at origin: T (-3)
Then rotate line 45 degrees: R(45) Then rotate line 45 degrees: R(45)
Then translate back so Then translate back so a a is where it was: T(3) is where it was: T(3)
Isolate endpoint
Isolate endpoint
a
a
from rotation effects
from rotation effects
First translate line so First translate line so a a is at origin: T (-3) is at origin: T (-3)
Then rotate line 45 degrees: R(45) Then rotate line 45 degrees: R(45)
Then translate back so Then translate back so a a is where it was: T(3) is where it was: T(3)
a
a
a
a
Will this sequence of operations work? Will this sequence of operations work?
Matrix Composition
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
1
'
'
1 1 0 0
0 1 0
3 0 1
1 0 0
0 ) 45 cos( ) 45 sin(
0 ) 45 sin( ) 45 cos(
1 0 0
0 1 0
3 0 1
y
x
y
x
a
a
a
a
Matrix Composition
After correctly ordering the matrices
After correctly ordering the matrices
Multiply matrices together
Multiply matrices together
What results is one matrix
What results is one matrix
store it (on stack)!
store it (on stack)!
Multiply this matrix by the vector of each vertex
Multiply this matrix by the vector of each vertex
All vertices easily transformed with one matrix
All vertices easily transformed with one matrix
multiply
multiply
After correctly ordering the matrices
After correctly ordering the matrices
Multiply matrices together
Multiply matrices together
What results is one matrix
What results is one matrix
store it (on stack)!
store it (on stack)!
Multiply this matrix by the vector of each vertex
Multiply this matrix by the vector of each vertex
All vertices easily transformed with one matrix
All vertices easily transformed with one matrix
multiply
multiply
Overview
2D Transformations
2D Transformations
Same as 2D Same as 2D
2D Transformations
2D Transformations
Same as 2D Same as 2D
3D Transformations
Same idea as 2D transformations
Same idea as 2D transformations
]
]
]
]
]
]
]
]
]
]
w
z
y
x
p o n m
l k j i
h g f e
d c b a
w
z
y
x
'
'
'
'
Basic 3D Transformations
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
w
z
y
x
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
'
'
'
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
t
t
t
w
z
y
x
z
y
x
1 0 0 0
1 0 0
0 1 0
0 0 1
'
'
'
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
s
s
s
w
z
y
x
z
y
x
1 0 0 0
0 0 0
0 0 0
0 0 0
'
'
'
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
w
z
y
x
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
'
'
'
Identity Scale
Translation Mirror about Y/Z plane
Basic 3D Transformations
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
w
z
y
x
1 0 0 0
0 1 0 0
0 0 cos sin
0 0 sin cos
'
'
'
Rotate around Z axis:
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
w
z
y
x
1 0 0 0
0 cos 0 sin
0 0 1 0
0 sin 0 cos
'
'
'
Rotate around Y axis:
]
]
]
]
]
]
]
]
]
]
]
]
]
]
]
w
z
y
x
w
z
y
x
1 0 0 0
0 cos sin 0
0 sin cos 0
0 0 0 1
'
'
'
Rotate around X axis:
Reverse Rotations
Q: How do you undo a rotation of Q: How do you undo a rotation of
,
, R( R(
)? )?
A: Apply the inverse of the rotation R A: Apply the inverse of the rotation R
-1 -1
( (
) = R(- ) = R(-
) )
How to construct R-1( How to construct R-1(
) = R(- ) = R(-
) )
Inside the rotation matrix: cos( Inside the rotation matrix: cos( ) = cos(- ) = cos(- ) )
The cosine elements of the inverse rotation matrix are unchanged The cosine elements of the inverse rotation matrix are unchanged
The sign of the sine elements will flip The sign of the sine elements will flip
Therefore R Therefore R
-1 -1
( (
) = R(- ) = R(-
) = R ) = R
T T
( (
) )
Q: How do you undo a rotation of Q: How do you undo a rotation of
,
, R( R(
)? )?
A: Apply the inverse of the rotation R A: Apply the inverse of the rotation R
-1 -1
( (
) = R(- ) = R(-
) )
How to construct R-1( How to construct R-1(
) = R(- ) = R(-
) )
Inside the rotation matrix: cos( Inside the rotation matrix: cos( ) = cos(- ) = cos(- ) )
The cosine elements of the inverse rotation matrix are unchanged The cosine elements of the inverse rotation matrix are unchanged
The sign of the sine elements will flip The sign of the sine elements will flip
Therefore R Therefore R
-1 -1
( (
) = R(- ) = R(-
) = R ) = R
T T
( (
) )
Summary
Coordinate systems Coordinate systems