Computer Graphics
2D transformations
Overview
• Why transformations?
• Basic transformations:
– translation, rotation, scaling
• Combining transformations
– homogenous coordinates, transform. Matrices
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
Translation
Translate over vector (tx, ty)
x’=x+ tx, y’=y+ ty
or
x
y
P
P+T
T





























y
x
t
t
y
x
y
x
T
P
P
T
P
P'
and
,
'
'
'
with
,
Translation polygon
Translate polygon:
Apply the same operation
on all points.
Works always, for all
transformations of
objects defined as a set
of points.
x
y
T
Rotation
x
y
P
x
y
P’
a
















 















y
x
y
x
y
x
y
y
x
x
P
R
P
RP
P'
and
cos
sin
sin
cos
,
'
'
'
with
,
Or
cos
sin
'
sin
cos
'
:
angle
an
over
Rotate
a
a
a
a
a
a
a
a
a
Rotation around a point Q
x
y
P
x
y
P’
a
Q
PQ
a
a
a
a
cos
sin
'
sin
cos
'
:
origin
around
Rotate
y
x
y
y
x
x
P
P
P
P
P
P




a
a
a
a
a
cos
)
(
sin
)
(
'
sin
)
(
cos
)
(
'
:
angle
an
over
around
Rotate
y
y
x
x
y
y
y
y
x
x
x
x
Q
P
Q
P
Q
P
Q
P
Q
P
Q
P










Q
Scale with factor sx and sy:
x’= sx x, y’= sy y
or
and
0
0
,
'
'
'
with
,




























y
x
s
s
y
x
y
x
P
S
P
SP
P'
Scaling
x
y
P
x
P’
Q’
Q
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)
or
Px’= Fx + sx (Px  Fx),
Py’= Fy + sy (Py  Fy)
x
y
P
x
P’
Q’
Q
F
PF
Transformations
• Translate with V:
T = P + V
• Scale with factor sx = sy =s:
S = sP
• Rotate over angle a:
R’x = cos a Px  sin a Py
R’y = sin a Px + cos a Py
x
y
P
T
S
R
Transformations…
• Messy!
• Transformations with respect to points:
even more messy!
• How to combine transformations?
Homogeneous coordinates 1
• Uniform representation of translation,
rotation, scaling
• Uniforme representation of points and
vectors
• Compact representation of sequence of
transformations
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
)
,
(
'
or
1
1
0
0
1
0
0
1
1
'
'
:
n
Translatio
P
T
P y
x
y
x
t
t
y
x
t
t
y
x
































Translation matrix
)
(
'
or
1
1
0
0
0
cos
sin
0
sin
cos
1
'
'
:
Rotation
P
R
P 
























 











y
x
y
x
Rotation matrix
Scaling matrix
)
,
(
'
or
1
1
0
0
0
0
0
0
1
'
'
:
Scaling
P
S
P y
x
y
x
s
s
y
x
s
s
y
x
































Inverse transformations
)
1
,
1
(
)
,
(
:
Scaling
)
(
)
(
:
Rotation
)
,
(
)
,
(
:
n
Translatio
1
1
-
1
-
y
x
y
x
y
x
y
x
s
s
s
s
t
t
t
t
S
S
R
R
T
T









1
2
1
2
1
2
'
'
'
2
'
'
1
'
M
M
M
MP
P
M
M
P)
(M
M
P
P
M
P
P
M
P






with
:
Combined
ation...
transform
second
...
sformation
first tran
Combining transformations 1
P
T
P
P
P
T
T
P
P
T
P
P
T
P
'
'
'
'
'
'
)
,
(
1
0
0
1
0
0
1
1
0
0
1
0
0
1
1
0
0
1
0
0
1
)
,
(
)
,
(
:
Combined
on
translati
second
)
,
(
slation
first tran
)
,
(
2
1
2
1
2
1
2
1
1
1
2
2
1
1
2
2
2
2
1
1
y
x
x
x
y
y
x
x
y
x
y
x
y
x
y
x
y
x
y
x
t
t
t
t
t
t
t
t
t
t
t
t
t
t
t
t
t
t
t
t








































Combining transformations 2
)
,
(
)
,
(
)
,
(
:
scaling
Composite
)
(
)
(
)
(
:
rotations
Composite
)
,
(
)
,
(
)
,
(
:
ons
translati
Composite
2
1
2
1
1
1
2
2
2
1
1
2
2
1
2
1
1
1
2
2
y
y
x
x
y
x
y
x
y
x
x
x
y
x
y
x
s
s
s
s
s
s
s
s
R
t
t
t
t
t
t
t
t
S
S
S
R
R
T
T
T










Combining transformations 3
back.
Translate
3)
origin;
around
angle
over
Rotate
2)
origin;
with
coincides
such that
Translate
1)
:
point
around
angle
over
Rotate


R
R
Rotation around a point 1
R
1) 2) 3)
'
'
'
'
'
'
'
'
'
)P
T(
P
)P
R(
P
)P
T(
P
R
y
x
y
x
,R
R
R
,
R





3)
2)
1)
:
point
around
angle
over
Rotate


Rotation around a point 2
R
1) 2) 3)
)P
)T(
)R(
T(
)P
)R(
T(
)P
T(
P
)P
)T(
R(
)P
R(
P
)P
T(
P
'
'
'
'
'
'
'
'
'
'
y
x
y
x
y
x
y
x
y
x
y
x
R
,
R
,R
R
,R
R
,R
R
R
,
R
R
,
R
















3)
2)
1)
Rotation around point 3
R
1) 2) 3)
P
P
)P
)T(
)R(
T(
P
'
'
'
'
'
'



















1
0
0
sin
)
cos
1
(
cos
sin
sin
)
cos
1
(
sin
cos
or
3)
-
1









x
y
y
x
y
x
y
x
R
R
R
R
R
,
R
,R
R
Rotation around point 4
R
1) 2) 3)
again.
back
Translate
3)
origin;
w.r.t.
Schale
2)
origin;
with
coincides
such that
Translate
1)
:
point
w.r.t.
and
factors
with
Scale
F
F
x
x s
s
Scaling w.r.t. point 1
F
1) 2) 3)
'
'
'
'
'
'
'
'
'
)P
T(
P
)P
S(
P
)P
T(
P
F
y
x
y
x
y
x
,F
F
s
s
F
,
F





3)
,
2)
1)
:
point
w.r.t.
Schale
Scaling w.r.t.point 2
F
1) 2) 3)
P
P
)P
T(
)S
T(
P
'
'
'
'
'
'
















1
0
0
)
1
(
0
)
1
(
0
or
)
,
(
3)
-
1
y
y
y
x
x
x
y
x
y
x
y
x
s
F
s
s
F
s
F
,
F
s
s
,F
F
Scaling w.r.t.point 3
F
1) 2) 3)
Order of transformations 1
x
y
x
y
x’
y’
x
x )
T(2,3)R(30
'
'  x
x )
R(30)T(2,3
'
' 
Matrix multiplication does not commute.
The order of transformations makes a difference!
Rotation, translation… Translation, rotation…
Order of transformations 2
• Pre-multiplication:
P’ = M n M n-1…M 2 M 1 P
Transformation M n in global coordinates
• Post-multiplication:
P’ = M 1 M 2…M n-1 M n P
Transformation M n in local coordinates: the
coordinate system after application of
M 1 M 2…M n-1
Order of transformations 3
OpenGL: glRotate, glScale, etc.:
• Post-multiplication of current
transformation matrix
• Always transformation in local coordinates
• Global coordinate version: read in reverse
order
Order of transformations 4
x
x )
R(30)T(2,3
'
'  glTranslate(…);
glRotate(…);
x
y
Local trafo
interpretation
Local transformations:
x
y
Global transformations:
Global trafo
interpretation
Matrices in general
rotation and scaling
translation
Direct construction of matrix
x
y
A
B
T
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.
 
1
1
0
0
1
or
,
1
1
or
,
'























































v
u
T
B
A
T
B
A
y
x
v
u
y
x
v
u
y
y
y
x
x
x
T
B
A
T
B
A
P
Direct construction of matrix
x
y
A
B
T
If you know the target frame:
Construct matrix directly.
Other 2D transformations
• Reflection
• Shear
Can also be combined
P
P'












1
0
0
0
1
0
0
0
1
Reflection over axis
Reflext over x-axis:
x’= x, y’= y
or
x
y
P
R
P'
P
P'
)
180
(
as
Same
1
0
0
0
1
0
0
0
1














Reflect over origin
Reflect over origin:
x’= x, y’=  y
or
x
y

tan
with
1
0
0
0
1
0
0
1












f
f
P
P'
Shear
Shear the y-as:
x’=x+f, y’=y
or
x
y

2D transformations summarized
- Transformations: modelling, viewing,
animation;
- Several kinds of transformations;
- Homogeneous coordinates;
- Combine transformations using matrix
multiplication.

Computer Graphics transformations