You are on page 1of 52

Introduction to

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

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D transformations

Same as 2D Same as 2D
2D Transformations
2D Transformations

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D 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

,
,

x is a linear combination of x and y x is a linear combination of x and y

y is a linear combination of x and y y is a linear combination of x and y


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

,
,

x is a linear combination of x and y x is a linear combination of x and y

y is a linear combination of x and y y is a linear combination of x and y


( ) ( )
( ) ( )
]
]
]

]
]
]

]
]
]

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:

x = x* x = x*cos cos - y* - y*sin sin

y = x* y = x*sin sin + y* + y*cos 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* x = x*cos cos - y* - y*sin sin

y = x* y = x*sin sin + y* + y*cos cos


Basic 2D Transformations
Translation: Translation:
x = x x = x + t + t
x x
y = y y = y + t + 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 x = x + t + t
x x
y = y y = y + t + 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
x = ((x*s
x
)*cos - (y*s
y
)*sin ) + t
x
y = ((x*s
x
)*sin + (y*s
y
)*cos ) + t
y
x = ((x*s
x
)*cos - (y*s
y
)*sin ) + t
x
y = ((x*s
x
)*sin + (y*s
y
)*cos ) + t
y
(x,y)
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
x = ((x*s
x
)*cos - (y*s
y
)*sin ) + t
x
y = ((x*s
x
)*sin + (y*s
y
)*cos ) + t
y
x = ((x*s
x
)*cos - (y*s
y
)*sin ) + t
x
y = ((x*s
x
)*sin + (y*s
y
)*cos ) + t
y
Overview
2D Transformations
2D Transformations

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D transformations

Same as 2D Same as 2D
2D Transformations
2D Transformations

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D 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

apply transformation to point


apply transformation to point
Represent 2D transformation by a matrix
Represent 2D transformation by a matrix
Multiply matrix by column vector
Multiply matrix by column vector

apply transformation to point


apply transformation to point
]
]
]

]
]
]

]
]
]

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,

Shear, and Shear, and

Mirror Mirror
Properties of linear transformations: Properties of linear transformations:

Satisfies: Satisfies:

Origin maps to origin Origin maps to origin

Lines map to lines Lines map to lines

Parallel lines remain parallel Parallel lines remain parallel

Ratios are preserved Ratios are preserved

Closed under composition Closed under composition


Linear transformations are combinations of Linear transformations are combinations of

Scale, Scale,

Rotation, Rotation,

Shear, and Shear, and

Mirror Mirror
Properties of linear transformations: Properties of linear transformations:

Satisfies: Satisfies:

Origin maps to origin Origin maps to origin

Lines map to lines Lines map to lines

Parallel lines remain parallel Parallel lines remain parallel

Ratios are preserved Ratios are preserved

Closed under composition Closed under composition


) ( ) ( ) (
2 2 1 1 2 2 1 1
p p p p T s T s s s T + +
]
]
]

]
]
]

]
]
]

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

represent coordinates in 2 represent coordinates in 2


dimensions with a 3-vector dimensions with a 3-vector
Homogeneous coordinates Homogeneous coordinates

represent coordinates in 2 represent coordinates in 2


dimensions with a 3-vector dimensions with a 3-vector
]
]
]
]
]


]
]
]

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

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, 0) represents a point at infinity (x, y, 0) represents a point at infinity

(0, 0, 0) is not allowed (0, 0, 0) is not allowed


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, 0) represents a point at infinity (x, y, 0) represents a point at infinity

(0, 0, 0) is not allowed (0, 0, 0) is not allowed


Convenient coordinate
system to
represent many useful
transformations
1 2
1
2
(2,1,1) or (4,2,2) or (6,3,3)
x
y
Basic 2D Transformations
Basic 2D transformations as 3x3 matrices
Basic 2D transformations as 3x3 matrices Basic 2D transformations as 3x3 matrices
Basic 2D transformations as 3x3 matrices
]
]
]
]
]

]
]
]
]
]

]
]
]
]
]

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

Linear transformations, and Linear transformations, and

Translations Translations
Properties of affine transformations: Properties of affine transformations:

Origin does not necessarily map to origin Origin does not necessarily map to origin

Lines map to lines Lines map to lines

Parallel lines remain parallel Parallel lines remain parallel

Ratios are preserved Ratios are preserved

Closed under composition Closed under composition


Affine transformations are combinations of Affine transformations are combinations of

Linear transformations, and Linear transformations, and

Translations Translations
Properties of affine transformations: Properties of affine transformations:

Origin does not necessarily map to origin Origin does not necessarily map to origin

Lines map to lines Lines map to lines

Parallel lines remain parallel Parallel lines remain parallel

Ratios are preserved Ratios are preserved

Closed under composition Closed under composition


]
]
]
]

]
]
]
]

]
]
]
]

w
y
x
f e d
c b a
w
y
x
1 0 0
'
'
Projective Transformations
Projective transformations Projective transformations

Affine transformations, and Affine transformations, and

Projective warps Projective warps


Properties of projective transformations: Properties of projective transformations:

Origin does not necessarily map to origin Origin does not necessarily map to origin

Lines map to lines Lines map to lines

Parallel lines do not necessarily remain parallel Parallel lines do not necessarily remain parallel

Ratios are not preserved Ratios are not preserved

Closed under composition Closed under composition


Projective transformations Projective transformations

Affine transformations, and Affine transformations, and

Projective warps Projective warps


Properties of projective transformations: Properties of projective transformations:

Origin does not necessarily map to origin Origin does not necessarily map to origin

Lines map to lines Lines map to lines

Parallel lines do not necessarily remain parallel Parallel lines do not necessarily remain parallel

Ratios are not preserved Ratios are not preserved

Closed under composition Closed under composition


]
]
]
]

]
]
]
]

]
]
]
]

w
y
x
i h g
f e d
c b a
w
y
x
'
'
'
Overview
2D Transformations
2D Transformations

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D transformations

Same as 2D Same as 2D
2D Transformations
2D Transformations

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D 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

General purpose representation General purpose representation

Hardware matrix multiply Hardware matrix multiply


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

General purpose representation General purpose representation

Hardware matrix multiply Hardware matrix multiply


p = (T * (R * (S*p) ) )
p = (T*R*S) * p
Matrix Composition
Be aware: order of transformations matters
Be aware: order of transformations matters

Matrix multiplication is not commutative Matrix multiplication is not commutative


Be aware: order of transformations matters
Be aware: order of transformations matters

Matrix multiplication is not commutative Matrix multiplication is not commutative


p = T * R * S * p
Global Local
Matrix Composition
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
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

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D transformations

Same as 2D Same as 2D
2D Transformations
2D Transformations

Basic 2D transformations Basic 2D transformations

Matrix representation Matrix representation

Matrix composition Matrix composition


3D Transformations
3D Transformations

Basic 3D transformations Basic 3D transformations

Same as 2D Same as 2D
3D Transformations
Same idea as 2D transformations
Same idea as 2D transformations

Homogeneous coordinates: (x,y,z,w) Homogeneous coordinates: (x,y,z,w)

4x4 transformation matrices 4x4 transformation matrices


Same idea as 2D transformations
Same idea as 2D transformations

Homogeneous coordinates: (x,y,z,w) Homogeneous coordinates: (x,y,z,w)

4x4 transformation matrices 4x4 transformation matrices


]
]
]
]
]

]
]
]
]
]

]
]
]
]
]

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

World vs. modeling coordinates World vs. modeling coordinates


2-D and 3-D transformations 2-D and 3-D transformations

Trigonometry and geometry Trigonometry and geometry

Matrix representations Matrix representations

Linear vs. affine transformations Linear vs. affine transformations


Matrix operations Matrix operations

Matrix composition Matrix composition


Coordinate systems Coordinate systems

World vs. modeling coordinates World vs. modeling coordinates


2-D and 3-D transformations 2-D and 3-D transformations

Trigonometry and geometry Trigonometry and geometry

Matrix representations Matrix representations

Linear vs. affine transformations Linear vs. affine transformations


Matrix operations Matrix operations

Matrix composition Matrix composition

You might also like