You are on page 1of 47

CAP4730: Computational

Structures in Computer Graphics

2D Transformations

2D Transformations

World Coordinates
Translate
Rotate
Scale
Viewport Transforms
Putting it all together

Transformations
Rigid Body Transformations - transformations that do
not change the object.
Translate
If you translate a rectangle, it is still a rectangle
Scale
If you scale a rectangle, it is still a rectangle
Rotate
If you rotate a rectangle, it is still a rectangle

Vertices
We have always represented vertices as
(x,y)
An alternate method is:
x
( x, y )
y

Example:

2.1
(2.1,4.8)
4.8

Matrix * Vector
x' a b x
y ' c d y


x' ax by
y ' cx dy
1 0
I

0
1

x' a b c x
y ' d e f y


z ' g h i z
x' ax by cz
y ' dx ey fz
z ' gx hy iz
1 0 0

I 0 1 0
0 0 1

Matrix * Matrix
a b
x y
A
,B

c
d
z
w

ax bz ay bw
A* B

cx

dz
cy

dw

a b 1 0
?
0 1
c
d

Does A*B = B*A?


What does the identity do?

Practice
2 3
2
A
,X

1 5
3
AX ?
2 3
0.5 1
A
,B

1
5
3
2
.
5

A* B ?
A* I ?

Translation
Translation - repositioning an object along a
straight-line path (the translation
distances) from one coordinate location to
another.
(x,y)
(tx,ty)
(x,y)

Translation
Given:

We want:

Matrix form:

P ( x, y )
T (t x , t y )
x' x t x
y' y t y

P (3.7,4.1)
T (7.1,8.2)
x ' 3 . 7 7 .1
y ' 4 .1 8 .2

x' 3.7 7.1


x' x t x y ' 4.1 8.2

y ' y t
y x ' 3 .4
P' P T
y ' 4 .1

Translation Examples
P=(2,4), T=(-1,14), P=(?,?)
P=(8.6,-1), T=(0.4,-0.2), P=(?,?)
P=(0,0), T=(1,0), P=(?,?)

Which one is it?


(x,y)

(tx,ty)
(x,y)

(tx,ty)
(x,y)

Recall
A point is a position specified with
coordinate values in some reference frame.
We usually label a point in this reference
point as the origin.
All points in the reference frame are given
with respect to the origin.

Applying to Triangles

(tx,ty)

What do we have here?


You know how to:

Scale
Scale - Alters the size of an object.
Scales about a fixed point
(x,y)
(x,y)

Scale
Given:

We want:

Matrix

P ( x, y )
S (sx , s y )

P (1.4,2.2)
S (3,3)

x' s x x

x' 3 *1.4
y ' 3 * 2.2

y' s y y

x' s x
y ' 0
form:
P' S P

x' 3 0 1.4
y ' 0 3 2.2
0 x

s y y x' 4.2
y ' 6.6

Non-Uniform/Differential Scalin
(x,y)

(x,y)

S=(1,2)

Rotation
Rotation - repositions an object along a
circular path.
Rotation requires an and a pivot point

Rotation
P ( x, y )
R ( )
x r cos
y r sin
x' r cos( )
y ' r cos( )

x' r cos cos r sin sin


y ' r cos sin r sin cos
x' x cos y sin
y ' x sin y cos
x' cos
y ' sin

P' R P

sin x
cos y

Example
P=(4,4)
=45 degrees

What is the difference? Revisited


V(-0.6,0) V(0,-0.6) V(0.6,0.6)

Translate (1.2,0.3)

Translate (1.2,0.3)

V(0.6,0.3) V(1.2,-0.3) V(1.8,0.9)

V(0,0.6) V(0.3,0.9) V(0,1.2)

V(0,0.6) V(0.3,0.9) V(0,1.2)

Rotations
V(-0.6,0) V(0,-0.6) V(0.6,0.6)
Rotate -30 degrees
V(0,0.6) V(0.3,0.9) V(0,1.2)

Combining Transformations
Q: How do we
specify each
transformation?

Specifying 2D Transformations
Translation
T(tx, ty)
Translation distances

Scale
S(sx,sy)
Scale factors

Rotation
R()
Rotation angle

Combining Transformations
Using translate, rotation, and scale, how do
we get:

Combining Transformations
Note there are two ways to combine rotation
and translation. Why?

Lets look at the equations


P ( x, y )
T (t x , t y )

x" x t x cos y t y ' sin

y" x t x sin y t y ' cos

P' P T

P' R P
P" P 'T

P' ' R P'

x' x cos y sin

x' x t x

y ' x sin y cos


x" x cos y sin t x

R( )

y' y t y
x" x' cos y ' sin
y" x' sin y ' cos

y" x sin y cos t y

Combining them
We must do each step in turn. First we
rotate the points, then we translate, etc.
Since we can represent the transformations
by matrices, why dont we just combine
them?
P' P T
P' R P
P' S P

2x2 -> 3x3 Matrices


We can combine transformations by
expanding from 2x2 to 3x3 matrices.
1 0 t x
x t x
T t x , t y 0 1 t y
y t y 0 0 1

s x 0 0
s
0
x

S s x , s y

0
s
0

y

0
s
y

0 0 1

cos
R
sin

cos
sin
sin

cos
0

sin
cos
0

0
0
1

Homogenous Coordinates
We need to do something to the vertices
By increasing the dimensionality of the
problem we can transform the addition
component of Translation into
multiplication.
xh
6

h
2
4
6
xh

x
3 14
y h 4
P yh y Ex. 2, Ex. 14 7
7
h 2
2

y h

1
2 2
h
h
2

Homogenous Coordinates
Homogenous Coordinates - term used in
mathematics to refer to the effect of this
representation on Cartesian equations. Converting
a pt(x,y) and f(x,y)=0 -> (xh,yh,h) then in
homogenous equations mean (v*xh,v*yh,v*h) can
be factored out.
What you should get: By expressing the
transformations with homogenous equations and
coordinates, all transformations can be expressed
as matrix multiplications.

Final Transformations Compare Equations


x' 1 0 t x x
x ' t x x

T t x , t y y ' 0 1 t y y
y ' t y y 1 0 0 1 1


P T t x , t y P P T t x , t y P
x' s x
x' s x 0 x
S s x , s y
y ' 0

y ' 0 s y y 1 0

P S s x , s y P P S s x , s y P

0
sy
0

x' cos
x' cos sin x
R
y ' sin

y ' sin cos y 1 0



P R P P R P

0 x
0 y
1 1
sin
cos
0

0 x
0 y
1 1

Combining Transformations
P' A P, P" B P' P" A B P
P(3,4), T (0.4641,2), R(60)
x' 1 0 t x x
y ' 0 1 t y
y

1 0 0 1 1
x" cos sin
y" sin cos

1 0
0
x" cos sin
y" sin cos

1 0
0

0 x '
0 y '
1 1
0 1 0 t x x'
0 0 1 t y y '
1 0 0 1 1

x" cos sin t x cos t y sin x


y" sin cos t sin t cos y
x
y


1 0
1
0
1
x" 1 0 t x cos sin 0 x
y" 0 1 t sin cos 0 y
y


1 0 0 1 0
0
1 1
x" cos sin t x x
y" sin cos t y
y

1 0
0
1 1

How would we get:

How would we get:

Coordinate Systems
Object Coordinates
World Coordinates
Eye Coordinates

Object Coordinates

World Coordinates

Screen Coordinates

Coordinate Hierarchy
Screen Coordinates

Transformation
World->Screen

World Coordinates

Transformation
Object #1 ->
World

Transformation
Object #2 ->
World

Transformation
Object #3 ->
World

Object #1
Object Coordinates

Object #2
Object Coordinates

Object #3
Object Coordinates

Lets reexamine assignment 2b

Transformation Hierarchies
For example:

Transformation Hierarchies
Lets examine:

Transformation Hierarchies
What is a better way?

Transformation Hierarchies
What is a better way?

Transformation Hierarchies
We can have transformations be
in relation to each other

World Coordinates

Transformation
Green -> World

Green
Object's Coordinates

Transformation
Red -> Green

Red
Object Coordinates

Transformation
Blue -> Red

Blue
Object Coordinates

More Complex Models

You might also like