6. 2D Transformations in Computer Graphics
In computer graphics, the 3 transformations are
1. Translation
2. Rotation
• About the origin
• About the fixed (pivot) point
3. Scaling
12. Consider rotation about the origin by degrees:
The radius r stays the same, angle increases by
Rotation about the origin
Original point P(x,y)
x = r cos
y = r sin
P
P’
Rotated point P’(x’,y’)
x’ = r cos ( + )
y ‘= r sin ( + )
13. Rotation about the origin
Original point p(x,y)
x = r cos
y = r sin
p
p’
Rotated point p’(x’,y’)
x’ = r cos ( + )
y ‘= r sin ( + )
WKT
sin(A+B) = sinA cosB + cosA sinB
cos(A+B) = cosA cosB – sinA sinB
Substituting for x’ and y’
x’ = r cos ( + )
x’ = x cos - y sin
y ‘= r sin ( + )
y’ = x sin + y cos
x’ cos -sin x
y’ sin cos y
=
14. Rotation about the origin
x’ = x cos - y sin
y’ = x sin + y cos
x’ cos -sin x
y’ sin cos y
=
Homogeneous co-ordinate System
x’ cos -sin 0 x
y’ sin cos 0 y
1 0 0 1 1
=
15. Transformat
ion
Equation Homogeneous Equation
Translation x’ = x + dx
y’ = y + dy
x‘ = 1 0 dx
y’ 0 1 dy
1 0 0 1
Rotation
x’ = cos -sin x
y’ sin cos y
=
Scaling x‘ = Sx 0 x
y’ 0 Sy y
=
x
y
1
x’
y’
1
x
y
1
cos -sin 0
sin cos 0
0 0 1
x’
y’
1
Sx 0 0
0 Sy 0
0 0 1
x
y
1
2D Transformations
17. 100 200 300
100
200
300
400
0
1
2
3
4
6 7
5 8
Pivot : 100,100
(m,n)
1. Translate to origin -----> T -x, -y
Rotation about an arbitrary point (m,n)
2. Rotate through -----> R
3. Translate back to the arbitrary point ------> T x,y
18. Rotation about an arbitrary point (m,n)
1. Translate to origin -----> T -x, -y
2. Rotate through -----> R
3. Translate back to the arbitrary point ------> T x, y
Result C =
1 0 -m
0 1 -n
0 0 1
1 0 m
0 1 n
0 0 1
cos -sin 0
sin cos 0
0 0 1
T x,y
R T-x,-y
19. Rotation about an arbitrary point (m,n)
Result C =
1 0 -m
0 1 -n
0 0 1
1 0 m
0 1 n
0 0 1
cos -sin 0
sin cos 0
0 0 1
T x,y
R T-x,-y
1 0 -m
0 1 -n
0 0 1
cos -sin m
sin cos n
0 0 1
T x,y X R T-x,-y
cos -sin -xcos + ysin + x
sin cos -xsin - y cos + y
0 0 1
T x,y X R X T-x,-y