Graphics Reference
In-Depth Information
Transformation
y
Suppose we want to find a 3
3 matrix transformation that rotates the entire plane
30
◦
counterclockwise around the point
P
=(
2, 4
)
, as shown in Figure 10.14. As
you'll recall, WPF expresses this transformation via code like this:
×
(2, 4)
x
<RotateTransform Angle="-30" CenterX="2" CenterY="4"/>
An implementer of WPF then must create a matrix like the one we're about to
build.
Here are two approaches.
First, we know how to rotate about the origin by 30
◦
; we can use the transfor-
mation
T
1
from the start of the chapter. So we can do our desired transformation
in three steps (see Figure 10.15).
y
(2, 4)
1. Move the point
(
2, 4
)
to the origin.
2. Rotate by 30
◦
.
3. Move the origin back to
(
2, 4
)
.
x
The matrix that moves the point
(
2, 4
)
to the origin is
⎡
⎤
−
10
2
Figure 10.14: We'd like to rotate
the entire plane by
30
◦
counter-
clockwise about the point P
⎣
⎦
.
01
4
00 1
−
(10.74)
=
(
2, 4
)
.
The one that moves it back is similar, except that the 2 and 4 are not negated. And
the rotation matrix (expressed in our new 3
×
3 format) is
⎡
⎤
cos
30
◦
−
sin
30
◦
0
⎣
⎦
.
sin
30
◦
cos
30
◦
0
(10.75)
0
0
1
The matrix representing the entire sequence of transformations is therefore
⎡
⎤
⎡
⎤
⎡
⎤
cos
30
◦
−
sin
30
◦
102
014
001
0
10
−
2
⎣
⎦
⎣
⎦
⎣
⎦
.
sin
30
◦
cos
30
◦
0
01
4
00 1
−
(10.76)
0
0
1
Inline Exercise 10.18:
(a) Explain why this is the correct order in which to
multiply the transformations to get the desired result.
(b) Verify that the point
(
2, 4
)
is indeed left unmoved by multiplying
241
T
by the sequence of matrices above.
The second approach is again more automatic: We find three points whose
target locations we know, just as we did with the windowing transformation above.
We' l l use
P
=(
2, 4
)
,
Q
=(
3, 4
)
(the point one unit to the right of
P
), and
R
=
(
2, 5
)
(the point one unit above
P
). We know that we want
P
sent to
P
,
Q
sent to
(
2
+cos
30
◦
,4
+sin
30
◦
)
, and
R
sent to
(
2
sin
30
◦
,4
+cos
30
◦
)
. (Draw a picture
to convince yourself that these are correct). The matrix that achieves this is just
−