Professional Documents
Culture Documents
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)
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
Or
P' RP, with
x'
cos
P ' , R
y'
sin
P
x
sin
x
and P
cos
y
12
y
P
P
PQ
Q
Rotation
Rotate individual
Vertices
14
Scaling
Schale with factor sx and sy:
y
P
x= sx x, y= sy y
P
or
0
x
and P
s y
y
15
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
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
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
1)
2)
3)
28
2) P R( )P
'
3) P ''' T( Rx ,R y )P ''
R
1)
2)
3)
29
1)
2)
3)
30
sin
Rx (1 cos ) R y sin
cos
0
R y (1 cos ) Rx sin P
1)
2)
3)
31
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
1)
2)
3)
35
1)
2)
3)
36
'''
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
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
T
x
40
y Ay B y T y
1 0
0
1
y
v
, or
u
v
T
x
1
41
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
P' 0 1 0 P
0 0 1
44
P' 0 1 0 P
0 0 1
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