0% found this document useful (0 votes)
67 views24 pages

Cgsem 4 PPT 3

This document discusses 2D transformations using matrix math. It begins by introducing matrix representations of transformations like translation, rotation, and scaling. It notes that we can represent any transformation as a 3x3 matrix using homogeneous coordinates. This allows us to represent combinations of transformations using single matrix multiplications. The document provides examples of matrix representations for common transformations and composite transformations. It concludes by discussing how we can optimize matrix multiplication for 2D graphics.

Uploaded by

Subash Rajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views24 pages

Cgsem 4 PPT 3

This document discusses 2D transformations using matrix math. It begins by introducing matrix representations of transformations like translation, rotation, and scaling. It notes that we can represent any transformation as a 3x3 matrix using homogeneous coordinates. This allows us to represent combinations of transformations using single matrix multiplications. The document provides examples of matrix representations for common transformations and composite transformations. It concludes by discussing how we can optimize matrix multiplication for 2D graphics.

Uploaded by

Subash Rajesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 24

2D Transformations

Matrix math
Is there a difference between possible representations?
a b e ae bf
c d f ce df

ce df

a c
ae bf

b d

be df

a b
ae cf

c d

Pick a convention
Well use the column-vector representation for a point.
Which implies that we use pre-multiplication of the
transformation it appears before the point to be
transformed in the equation.

A B x Ax By
C D y Cx Dy

Translation
A translation moves all points in
an object along the same
straight-line path to new
positions.
The path is represented by a
vector, called the translation
or shift vector.
We can write the components:
p'x = px + tx
p'y = py + ty
or in matrix form:
P' = P + T
4

Rotation
A rotation repositions all
points in an object along a
circular path in the plane
centered at the pivot point.
First, well assume the pivot is
at the origin.

We can write the components:


p'x = px cos py sin
p'y = px sin + py cos
or in matrix form:
P' = R P
5

More rotation
Another convention, well take to be counterclockwise, as in
our example.
R, the rotation matrix, looks like:

cos
R
sin
( x, y ) (5,1)

90

sin
cos
cos
sin

sin

x x cos y sin

cos y x sin y cos


5 cos 90 1 sin 90

5 sin 90 1 cos 90
5 0 11

5 1 1 0
1

Scaling
Scaling alters the size of an
object. Scales are about the
the origin.
Scale factors between 0 and 1
shrink objects. Scale factors
greater than 1 enlarge objects.
We can write the components:
p'x = sx px
p'y = sy py
or in matrix form:
P' = S P
The scale factors need not be the
same in each direction.
7

More scaling
We write a scale matrix as:

sx
S
0

0
s y

Scaling also translates objects; away from the origin if the


scale factor is greater than 1, or towards the origin if the
scale factor is less than 1.
What does scaling by 1 do?
What is that matrix called?
What does scaling by a negative value do?

Combining transformations
We have a general transformation of a point:
P' = M P + A
When we scale or rotate, we set M, and A is the additive
identity.
When we translate, we set A, and M is the multiplicative
identity.
To combine multiple transformations, we must explicitly
compute each transformed point.
Itd be nicer if we could use the same matrix operation all the
time. But wed have to combine multiplication and addition
into a single operation.
9

A less than obvious solution


Lets move our problem into 3D.
Let point (x, y) in 2D be represented by
point (x, y, 1) in the new space.

Scaling our new point by any value a


puts us somewhere along a
particular line: (ax, ay, a).
We can always map back to the
original 2D point by dividing by the
last coordinate.
The fact that all the points along each
line can be mapped back to the
same point in 2D gives this
coordinate system its name
homogeneous coordinates.

(x,y,1)
(0,0,0)

w=1

x,y

10

So what?
Well, now we can wedge some addition into our multiplicative
matrix.
Our point now has three coordinates. So our matrix is needs
to be 3x3.
We want a matrix which gives us:

x x t x
y y t y

11

Now what?
x 1 x 0 y t x 1
y 0 x 1 y t y 1
1 0 x 0 y 1 1

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


1 0 0 1 1

12

And?
Rotations:

x cos
y sin

1 0

sin
cos
0

0
1

x
y
1

Scales:

x s x
y 0

1 0

0
sy
0

0
0
1

x
y
1

13

What of it?
We can represent any of our three transformations as a single
matrix.
No special cases when transforming a point matrix vector.
Composite transformations matrix matrix.

Composite transformations:
Rotate about an arbitrary point translate, rotate, translate
Scale about an arbitrary point translate, scale, translate
Change coordinate systems translate, rotate, scale

14

Is matrix multiplication associative?


a b e

c d g

f
h

j ae bg
l ce dg

af bh i

cf dh k

aei bgi afk bhk

cei dgi cfk dhk


a b e
c d g

f i

h k

j
l

a b ei fk

c d gi hk

j
l
aej bgj afl bhl
cej dgj cfl dhl

ej fl
gj hl

aei afk bgi bhk

cei cfk dgi dhk

aej afl bgj bhl


cej cfl dgj dhl

15

Is matrix multiplication commutative?

f ae bg

h ce dg

af bh
cf dh

a b ea fc

h c d ga hc

eb fd

a b e
c d g


e
g

gb hd

16

Order of operations
So, it does matter. Lets look at an example:

17

Useful compositions
Rotate about a pivot point:
T(pivot) R( ) T(pivot) P

Scale about a fixed point:


T(fixed) S(scale) T(fixed) P

General scaling directions:


R( ) S(scale) R( ) P

18

Other transformations
Reflection:
x-axis

y-axis

1 0 0
0 1 0

0 0 1

1 0 0
0 1 0

0 0 1

19

Other transformations
Reflection:
origin
1 0 0
0 1 0

0 0 1

line x=y
0 1 0
1 0 0

0 0 1

20

Other transformations
Shear:
x-direction
1 shx
0 1

0 0

0
0
1

y-direction
1
sh
y
0

0 0

1 0
0 1

21

Coordinate system transformations


We often need to transform points from one coordinate
system to another:
1. We might model an object in non-Cartesian space (polar)
2. Objects may be described in their own local system
3. Other reasons: textures, display, etc

22

Matrix multiplication
So we can do a lot with one basic operation.
Wed better make this operation as fast as possible.
Lets start with the form of the matrix:

a b
M 1 d e
0 0

c
f
1

Why havent we used the bottom row of the matrix?

23

Matrix multiplication
Since we dont use the bottom row of the 2D transformation
matrix, we could have a special transform composition
operation:

a b
M 1 d e
0 0
a b
M 1 M 2 d e
0 0

c
f
1

c g
f j
1 0

g
M 2 j
0

h i
k l
0 1

h i ag bj ah bk
k l dg ej dh ek
0 1
0
0

ai bl c
di el f

1
24

You might also like