Graphics Reference
In-Depth Information
Thus the point (1, 0) becomes (0, 1). If we rotate by 360
◦
the matrix becomes
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
100
010
001
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
Such a matrix has a null effect and is called an
identity matrix
.
To rotate a point (
x
,
y
) about an arbitrary point (
p
x
,p
y
) we first subtract
(
p
x
,p
y
) from the coordinates (
x
,
y
) respectively. This enables us to perform
the rotation about the origin. Second, we perform the rotation, and third, we
add (
p
x
,p
y
) to compensate for the original subtraction. Here are the steps:
1
Subtract (
p
x
,p
y
):
x
1
=(
x
−
p
x
)
y
1
=(
y
−
p
y
)
2
Rotate
β
about the origin:
x
2
=(
x
−
p
x
)cos(
β
)
−
(
y
−
p
y
) sin(
β
)
y
2
=(
x
−
p
x
) sin(
β
)+(
y
−
p
y
)cos(
β
)
3Add
p
x
,p
y
):
x
=(
x
−
p
x
)cos(
β
)
−
(
y
−
p
y
) sin(
β
)+
p
x
y
=(
x
−
p
x
) sin(
β
)+(
y
−
p
y
)cos(
β
)+
p
y
Simplifying,
x
=
x
cos(
β
)
cos(
β
)) +
p
y
sin(
β
)
y
=
x
sin(
β
)+
y
cos(
β
)+
p
y
(1
−
cos(
β
))
− p
x
sin(
β
)
−
y
sin(
β
)+
p
x
(1
−
(7.41)
and, in matrix form,
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
cos(
β
)
−
sin(
β
)
p
x
(1
−
cos(
β
)) +
p
y
sin(
β
)
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
sin(
β
)
cos(
β
)
p
y
(1
−
cos(
β
))
−
p
x
sin(
β
)
(7.42)
0
0
1
If we now consider rotating a point 90
◦
about the point (1, 1) the matrix
operation becomes
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
0
12
100
001
−
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
A simple test is to substitute the point (2, 1) for (
x
,
y
): it is transformed
correctly to (1, 2).