Introduction To Computer Graphics CS 445 / 645: Transformations
Introduction To Computer Graphics CS 445 / 645: Transformations
Computer Graphics
CS 445 / 645
Lecture
Lecture 55
Transformations
Transformations
M.C. Escher – Smaller and Smaller (1956)
Modeling Transformations
Specify
Specify transformations
transformations for
for objects
objects
•• Allows
Allows definitions
definitions of
of objects
objects in
in own
own coordinate
coordinate systems
systems
•• Allows
Allows use
use of
of object
object definition
definition multiple
multiple times
times in
in aa scene
scene
––Remember
Remember how
how OpenGL
OpenGL provides
provides aa transformation
transformation
stack
stack because
because they
they are
are so
so frequently
frequently reused
reused
Chapter
Chapter 55 from
from Hearn
Hearn and
and Baker
Baker
Scale
Rotate
Translate
World Coordinates
2D Modeling Transformations
Modeling
Coordinates
y
Let’s look
at this in
detail…
World Coordinates
2D Modeling Transformations
Modeling
Coordinates
y
Initial location
at (0, 0) with
x- and y-axes
aligned
2D Modeling Transformations
Modeling
Coordinates
y
Scale .3, .3
Rotate -90
Translate 5, 3
2D Modeling Transformations
Modeling
Coordinates
y
Scale .3, .3
Rotate -90
Translate 5, 3
2D Modeling Transformations
Modeling
Coordinates
y
Scale .3, .3
Rotate -90
Translate 5, 3
World Coordinates
Scaling
Scaling
Scaling aa coordinate
coordinate means
means multiplying
multiplying each
each of
of its
its
components
components by by aa scalar
scalar
Uniform
Uniform scaling
scaling means
means this
this scalar
scalar is
is the
the same
same for
for all
all
components:
components:
2
Scaling
Non-uniform
Non-uniform scaling
scaling:: different
different scalars
scalars per
per component:
component:
X 2,
Y 0.5
How
How can
can we
we represent
represent this
this in
in matrix
matrix form?
form?
Scaling
Scaling
Scaling operation:
operation: x ' ax
y ' by
Or,
Or, in
in matrix
matrix form:
x ' a 0 x
y ' 0
form:
b y
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 ( + )
(x’, y’)
Trig Identity…
(x, y) 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()
2-D Rotation
This
This is
is easy
easy to
to capture
capture in
in matrix
matrix form:
form:
a b
c d
Multiply
Multiply matrix
matrix by
by column
column vector
vector
apply
apply transformation
transformation to
to point
point
x' a b x x' ax by
y ' c d y y ' cx dy
Matrix Representation
Transformations
Transformations combined
combined by
by multiplication
multiplication
x' a b e f i j x
y ' c d g h k l y
2D Shear?
x ' x shx * y x ' 1 shx x
y ' shy * x y y ' sh 1 y
y
2x2 Matrices
What
What types
types of
of transformations
transformations cancan be
be
represented
represented with
with aa 2x2
2x2 matrix?
matrix?
2D Mirror about Y axis?
x' x x ' 1 0 x
y' y y ' 0 1 y
Homogeneous
Homogeneous coordinates
coordinates seem
seem unintuitive,
unintuitive, but
but they
they
make
make graphics
graphics operations
operations much
much easier
easier
Homogeneous Coordinates
Q:
Q: How
How can
can we
we represent
represent translation
translation as
as aa 3x3
3x3 matrix?
matrix?
x' x t x
y' y t y
A:
A: Using
Using the
the rightmost
rightmost column:
column:
1 0 tx
Translation 0 1 ty
0 0 1
Translation
Homogeneous
Homogeneous Coordinates
Coordinates
Example
Example of
of translation
translation
x ' 1 0 t x x x t x
y ' 0 1 t y y t
y y
1 0 0 1 1 1
tx = 2
ty = 1
Homogeneous Coordinates
Add
Add aa 3rd
3rd coordinate
coordinate to
to every
every 2D
2D point
point
•• (x,
(x, y,
y, w)
w) represents
represents aa point
point at
at location
location (x/w,
(x/w, y/w)
y/w)
•• (x,
(x, y,
y, 0)
0) represents
represents aa point
point at
at infinity
infinity
•• (0,
(0, 0,
0, 0)
0) is
is not
not allowed
allowed y
2
(2,1,1) or (4,2,2) or (6,3,3)
1
Convenient coordinate 1 2 x
system to
represent many useful
transformations
Basic 2D Transformations
Basic
Basic 2D
2D transformations
transformations as
as 3x3
3x3 matrices
matrices
x ' s x 0 0 x
x ' 1 0 t x x y ' 0 sy 0 y
y ' 0
1 t y y 1 0 0 1 1
1 0 0 1 1
Translate Scale
Rotate Shear
Affine Transformations
Affine
Affine transformations
transformations are
are combinations
combinations of
of …
…
•• Linear
Linear transformations,
transformations, and
and x' a b c x
y ' d e f y
•• Translations
Translations w 0 0 1 w
Properties
Properties of
of affine
affine transformations:
transformations:
•• Origin
Origin does
does not
not necessarily
necessarily map
map to
to origin
origin
•• Lines
Lines map
map to
to lines
lines
•• Parallel
Parallel lines
lines remain
remain parallel
parallel
•• Ratios
Ratios are
are preserved
preserved
•• Closed
Closed under
under composition
composition
Projective Transformations
Projective
Projective transformations
transformations …
…
x' a b c x
•• Affine
Affine transformations,
transformations, and
and y ' d e f y
w' g h i w
•• Projective
Projective warps
warps
Properties
Properties of
of projective
projective transformations:
transformations:
•• Origin
Origin does
does not
not necessarily
necessarily map
map to
to origin
origin
•• Lines
Lines map
map to
to lines
lines
•• Parallel
Parallel lines
lines do
do not
not necessarily
necessarily remain
remain parallel
parallel
•• Ratios
Ratios are
are not
not preserved
preserved
•• Closed
Closed under
under composition
composition
Overview
2D
2D Transformations
Transformations
•• Basic
Basic 2D
2D transformations
transformations
•• Matrix
Matrix representation
representation
•• Matrix
Matrix composition
composition
3D
3D Transformations
Transformations
•• Basic
Basic 3D
3D transformations
transformations
•• Same
Same as
as 2D
2D
Matrix Composition
Transformations
Transformations can
can be
be combined
combined by
by
matrix
matrix multiplication
multiplication
x' 1 0 tx cos sin 0 sx 0 0 x
y ' 0 1 ty sin cos 0 0 sy
0 y
w' 0 0 1 0 0 1 0 0 1 w
p’ = T(tx,ty) R() S(sx,sy) p
Matrix Composition
Matrices
Matrices are
are aa convenient
convenient and
and efficient
efficient way
way to
to
represent
represent aa sequence
sequence of
of transformations
transformations
•• General
General purpose
purpose representation
representation
•• Hardware
Hardware matrix
matrix multiply
multiply
p’ = (T * (R * (S*p) ) )
p’ = (T*R*S) * p
Matrix Composition
Be
Be aware:
aware: order
order of
of transformations
transformations matters
matters
––Matrix
Matrix multiplication
multiplication is
is not
not commutative
commutative
p’ = T * R * S * p
“Global” “Local”
Matrix Composition
What
What ifif we
we want
want to
to rotate
rotate and
and translate?
translate?
•• Ex:
Ex: Rotate
Rotate line
line segment
segment by
by 45
45 degrees
degrees about
about endpoint
endpoint aa
and
and lengthen
lengthen
a a
Multiplication Order – Wrong Way
Our
Our line
line is
is defined
defined by
by two
two endpoints
endpoints
•• Applying
Applying aa rotation
rotation of
of 45
45 degrees,
degrees, R(45),
R(45), affects
affects both
both points
points
•• We
We could
could try
try to
to translate
translate both
both endpoints
endpoints to
to return
return endpoint
endpoint aa to
to its
its
original
original position,
position, but
but by
by how
how much?
much?
a
a a
Wrong Correct
R(45) T(-3) R(45) T(3)
Multiplication Order - Correct
Isolate
Isolate endpoint
endpoint aa from
from rotation
rotation effects
effects a
•• First
First translate
translate line
line so
so aa is
is at
at origin:
origin: TT (-3)
(-3)
a
•• Then
Then rotate
rotate line
line 45
45 degrees:
degrees: R(45)
R(45)
a
•• Then
Then translate
translate back
back so
so aa is
is where
where itit was:
was: T(3)
T(3)
a
Matrix Composition
Will
Will this
this sequence
sequence of
of operations
operations work?
work?
1 0 3 cos(45) sin(45) 0 1 0 3 a x a' x
0 1 0 sin(45) cos(45) 0 0 1 0 a a '
y y
0 0 1 0 0 1 0 0 1 1 1
Matrix Composition
After
After correctly
correctly ordering
ordering the
the matrices
matrices
Multiply
Multiply matrices
matrices together
together
What
What results
results is
is one
one matrix
matrix –– store
store itit (on
(on stack)!
stack)!
Multiply
Multiply this
this matrix
matrix by
by the
the vector
vector of
of each
each vertex
vertex
All
All vertices
vertices easily
easily transformed
transformed with
with one
one matrix
matrix
multiply
multiply
Overview
2D
2D Transformations
Transformations
•• Basic
Basic 2D
2D transformations
transformations
•• Matrix
Matrix representation
representation
•• Matrix
Matrix composition
composition
3D
3D Transformations
Transformations
•• Basic
Basic 3D
3D transformations
transformations
•• Same
Same as
as 2D
2D
3D Transformations
Same
Same idea
idea as
as 2D
2D transformations
transformations
•• Homogeneous
Homogeneous coordinates:
coordinates: (x,y,z,w)
(x,y,z,w)
•• 4x4
4x4 transformation
transformation matrices
matrices
x' a b c d x
y' e f g h y
z' i j k l z
w' m n o p w
Basic 3D Transformations
x ' s x 0 0 0 x
x ' 1 0 0 0 x y ' 0
y ' 0 1 0 0 y sy 0 0 y
z ' 0 0 1 0 z z' 0 0 sz 0 z
w 0 0 0 1 w
w 0 0 0 1 w
Identity Scale
x ' 1 0 0 t x x
y ' 0 x ' 1 0 0 0 x
1 0 t y y y ' 0 1 0 0 y
z ' 0 0 1 tz z z ' 0 0 1 0 z
w 0 0 0 1 w
w 0 0 0 1 w
Translation Mirror about Y/Z plane
Basic 3D Transformations
x' cos sin 0 0 x
Rotate around Z axis: y ' sin cos 0 0 y
z' 0 0 1 0 z
w 0 0 0 1 w
x' 1 0 0 0 x
Rotate around X axis: y ' 0 cos sin 0 y
z ' 0 sin cos 0 z
w 0 0 0 1 w
Reverse Rotations
Q:
Q: How
How do
do you
you undo
undo aa rotation of
rotation of R()?
R( )?
A:
A: Apply
Apply the
the inverse
inverse of
of the
the rotation… R-1-1(()) == R(-
rotation… R R(-))
How
How to
to construct R-1()) == R(-
construct R-1( R(-))
•• Inside
Inside the
the rotation
rotation matrix: cos()) == cos(-
matrix: cos( cos(-))
–– The
The cosine
cosine elements
elements of
of the
the inverse
inverse rotation
rotation matrix
matrix are
are unchanged
unchanged
•• The
The sign
sign of
of the
the sine
sine elements
elements will
will flip
flip
Therefore… R-1-1(()) == R(-
Therefore… R R(-)) == R
RTT(())
Summary
Coordinate
Coordinate systems
systems
•• World
World vs.
vs. modeling
modeling coordinates
coordinates
2-D
2-D and
and 3-D
3-D transformations
transformations
•• Trigonometry
Trigonometry and
and geometry
geometry
•• Matrix
Matrix representations
representations
•• Linear
Linear vs.
vs. affine
affine transformations
transformations
Matrix
Matrix operations
operations
•• Matrix
Matrix composition
composition