0% found this document useful (0 votes)
106 views

COMPUTER GRAPHICS 2D Transformations

2  s1 sin 2  0  s1 s2 sin cos s2 cos 2  s2 sin 2  0 0 0 0 1 0 0 0 1   P    1) 2D transformations include translation, rotation, scaling, and shear. They change the position, size, orientation, and shape of 2
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)
106 views

COMPUTER GRAPHICS 2D Transformations

2  s1 sin 2  0  s1 s2 sin cos s2 cos 2  s2 sin 2  0 0 0 0 1 0 0 0 1   P    1) 2D transformations include translation, rotation, scaling, and shear. They change the position, size, orientation, and shape of 2
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/ 47

Computer Graphics

2D transformations
y

y
x

2D Transformation
Given a 2D object, transformation is to change the
objects

Position (translation)
Size (scaling)
Orientation (rotation)
Shapes (shear)

Apply a sequence of matrix multiplication to the


object vertices
2

Point representation
We can use a column vector (a 2x1 matrix) to
represent a 2D point
x
y
A general form of linear transformation can be
written as:
x = ax + by + c
OR
y = dx + ey + f

X
Y =
1

a
d
0

b
e
0

c
f
1

x
y
1

Transformations
instantiation
world
train

animation

viewing
image

wheel
modelling
4

Why transformation?
Model of objects
world coordinates: km, mm, etc.
Hierarchical models::
human = torso + arm + arm + head + leg + leg
arm = upperarm + lowerarm + hand

Viewing
zoom in, move drawing, etc.

Animation
5

Translation
Translate over vector (tx, ty)
x=x+ tx, y=y+ ty
or
P' P T, with

y
T

P+T

P
x

tx
x'
x
P ' , P and T
y'
y
ty
6

Translation
How to translate an object with multiple
vertices?

Translate individual
vertices

Translation polygon
Translate polygon:
Apply the same operation
on all points.
Works always, for all
transformations of
objects defined as a set
of points.

y
T
x

Rotation
(x,y) -> Rotate about the origin by
(x, y)
How to compute (x, y) ?

(x,y)

(x,y)

x = r cos () y = r sin ()
x = r cos () y = r sin ()
9

Rotation
(x,y)

x = r cos () y = r sin ()
x = r cos () y = r sin ()
x = r cos ()
= r cos() cos() r sin() sin()

(x,y)

= x cos() y sin()
y = r sin ()
= r sin() cos() + r cos()sin()
= y cos() + x sin()
10

Rotation
(x,y)

x = x cos() y sin()
y = y cos() + x sin()

(x,y)

Matrix form?
x
y

cos()
sin()

-sin()
cos()

x
y

11

Rotation
Rotate over an angle :
x' x cos y sin

y
P

y ' x sin y cos

Or
P' RP, with
x'
cos
P ' , R
y'
sin

P
x

sin

x
and P
cos
y
12

Rotation around a point Q


Rotate around origin :
Px ' Px cos Py sin
Py ' Px sin Py cos

y
P
P
PQ
Q

Rotate around Q over an angle :


Px ' Qx ( Px Qx ) cos ( Py Q y ) sin

Py ' Q y ( Px Qx ) sin ( Py Q y ) cos


13

Rotation

How to rotate an object with multiple


vertices?

Rotate individual
Vertices

14

Scaling
Schale with factor sx and sy:

y
P

x= sx x, y= sy y
P

or

P' SP, with


sx
x'
P ' , S
0
y'

0
x
and P
s y
y
15

Scaling with respect to a point F


Scale with factors sx and sy:

Px= sx Px, Py= syPy


With respect to F:
Px Fx = sx (Px Fx),
Py Fy = sy (Py Fy)

P
PF
F

Q
Q
x

or
Px= Fx + sx (Px Fx),
Py= Fy + sy (Py Fy)
16

Transformations
Translate with V:
T = P+ V

Schale with factor sx = sy =s:


S = sP

Rotate over angle

S
T

R
P

Rx = cos Px sin Py
Ry = sin Px + cos Py
17

Transformations
Messy!
Transformations with respect to points:
even more messy!
How to combine transformations?

18

Homogeneous coordinates 1
Uniform representation of translation,
rotation, scaling
Uniform representation of points and
vectors
Compact representation of sequence of
transformations

19

Homogeneous coordinates 2
Add extra coordinate:
P = (px , py , ph) or
x = (x, y, h)
Cartesian coordinates: divide by h
x = (x/h, y/h)
Points: h = 1 (for the time being), vectors: h = 0
The point (x,y) needs to be represented as
(x,y,1) --> this is called Homogeneous
coordinates!
20

Translation matrix
Translation :
x' 1 0 t x

y' 0 1 t y
1 0 0 1

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

x

y
1

21

Rotation matrix
Rotation :
x' cos

y ' sin
1 0

or
P ' R ( )P

sin
cos
0

0
1

x

y
1

22

Scaling matrix
Scaling :
x' s x

y' 0
1 0

or

0
sy
0

0
1

x

y
1

P ' S( s x , s y ) P

23

Inverse transformations
Translation :
T -1 (t x , t y ) T(t x ,t y )
Rotation :
R -1 ( ) R ( )
Scaling :
1 1
S ( s x , s y ) S( , )
sx s y
1

24

Combining transformations 1
P' M1P

first transformation...

P '' M 2 P '

second transformation...

Combined :
''

P M 2 (M 1P)
M 2M 1P
MP with M M 2 M 1
25

Combining transformations 2
P ' T(t1x , t1 y )P

first translation

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

second translation

Combined :
P '' T(t 2 x , t 2 y )T(t1x , t1 y )P
1 0 t 2 x 1 0 t1x

0 1 t 2 y 0 1 t1 y P
0 0 1 0 0 1

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

1 0 t1x t 2 x

0 1 t1 y t 2 y P
0 0

26

Combining transformations 3
Composite translations :
T(t 2 x , t 2 y )T(t1x , t1 y ) T(t1x t 2 x , t1x t 2 y )
Composite rotations :
R ( 2 ) R (1 ) R (1 2 )
Composite scaling :
S( s2 x , s2 y )S( s1x , s1 y ) S( s1x s2 x , s1 y s2 y )
27

Rotation around a point 1


Rotate over angle around point R :
1) Translate such that R coincides with origin;
2) Rotate over angle around origin;
3) Translate back.
R

1)

2)

3)
28

Rotation around a point 2


Rotate over angle around point R :
1) P ' T( Rx , R y )P
''

2) P R( )P

'

3) P ''' T( Rx ,R y )P ''
R

1)

2)

3)
29

Rotation around point 3


1) P ' T( Rx , R y )P
2) P '' R( )P ' R( )T( Rx , R y )P
3) P ''' T( Rx ,R y )P ''
T( Rx ,R y )R( )P '
T( Rx ,R y )R( )T( Rx , R y )P

1)

2)

3)
30

Rotation around point 4


1 - 3) P ''' T( Rx ,R y )R( )T( Rx , R y )P
or
cos
'''
P sin
0

sin

Rx (1 cos ) R y sin

cos
0

R y (1 cos ) Rx sin P

1)

2)

3)
31

Scaling w.r.t. point 1


Scale with factors s x and s x w.r.t. point F :
1) Translate such that F coincides with origin;
2) Schale w.r.t. origin;
3) Translate back again.
F

1)

2)

3)
32

Scaling w.r.t.point 2
Schale w.r.t. point F :
1) P ' T( Fx , Fy )P
2) P '' S( s x , s y )P '
3) P ''' T( Fx ,Fy )P ''
F

1)

2)

3)
33

Scaling w.r.t.point 3
1 - 3) P ''' T( Fx ,Fy )S( s x , s y )T( Fx , Fy )P
or
sx
'''
P 0
0

0
sy
0

Fx (1 s x )

Fy (1 s y ) P

1)

2)

3)
34

Scale in other directions 1


Scale with factors s1 and s2 w.r.t. rotated frame :
1) Rotate such that frame coincides with standard xy - frame;
2) Scale w.r.t. origin;
3) Rotate back again.

1)

2)

3)
35

Scale in other directions 2


Scale in other direction :
1) P ' R( )P
2) P '' S( s1 , s2 )P '
3) P ''' R( )P ''

1)

2)

3)
36

Scale in other directions 3


1 - 3) P ''' R( )S( s1 , s2 )R( )P
or
s1 cos 2 s2 sin 2

'''
P ( s2 s1 ) cos sin

1)

2)

( s2 s1 ) cos sin
s1 sin 2 s2 cos 2
0

0
0 P

3)
37

Order of transformations 1
Rotation, translation

Translation, rotation
y

y
x

Matrix
multiplication
does
not
commute.
x
' ' R(30)T(2,3)x
x' ' T(2,3)R(30)x
The order of transformations makes a difference!
38

Matrices in general
P ' MP , or

rotation and scaling


translation

x' rs xx rs xy trs x x


y ' rs yx rs yy trs y y , or

1
0 1 1
0
x' rs xx x rs xy y trs x
y ' rs yx x rs yy y trs y
39

Direct construction of matrix


If you know the target frame:
Construct matrix directly.

Define shape in nice local


u,v coordinates, use matrix
transformation to put it
in x,y space.

T
x

40

Direct construction of matrix


If you know the target frame:
Construct matrix directly.
P ' Au Bv T , or
x
u


y A B T v
1
1


x Ax Bx Tx

y Ay B y T y
1 0

0
1

y
v

, or
u

v

T
x

1

41

Rigid body transformation


only rotation

P ' MP , of
x rxx

y ryx
1 0

rxx

ryx

rxy
ryy
0

trx

try
1

translation

u

v
1

rxy
: orthonormal submatrix
ryy

rxx
rxy
and B
, | A | 1, | B | 1, A B 0
A

ryx
ryy

y
u

B
T

A
x

42

Other 2D transformations
Reflection
Shear
Can also be combined

43

Reflection over axis


Reflext over x-axis:
x= x, y= y
or
1 0 0

P' 0 1 0 P
0 0 1

44

Reflect over origin


Reflect over origin:
x= x, y= y
or
1 0 0

P' 0 1 0 P
0 0 1

Same as P' R (180)P


45

Shear
Shear the y-as:
x=x+fy, y=y
or
1 f 0

P' 0 1 0 P
0 0 1

with f tan
46

Thank You

47

You might also like