Graphics Reference
In-Depth Information
7.3.5 2D Rotation
Figure 7.7 shows a point
P
(
x
,
y
) which is to be rotated by an angle
β
about
the origin to
P
(
x
,y
). It can be seen that
x
=
R
cos(
θ
+
β
)
y
=
R
sin(
θ
+
β
)
(7.38)
therefore
x
=
R
(cos(
θ
)cos(
β
)
−
sin(
θ
) sin(
β
))
y
=
R
(sin(
θ
)cos(
β
) + cos(
θ
) sin(
β
))
x
=
R
x
R
sin(
β
)
y
R
cos(
β
)
−
y
=
R
y
R
sin(
β
)
R
cos(
β
)+
x
x
=
x
cos(
β
)
y
sin(
β
)
y
=
x
sin(
β
)+
y
cos(
β
)
−
(7.39)
or, in matrix form,
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
cos(
β
)
−
sin(
β
)0
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
sin(
β
)
cos(
β
)0
(7.40)
0
0
1
For example, to rotate a point by 90
◦
the matrix becomes
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
0
10
100
001
−
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
Y
y'
P'(x', y')
y
P(x, y)
b
q
x'
x
X
Fig. 7.7.
The point
P
(
x, y
) is rotated through an angle
β
to
P
(
x
,y
).