Graphics Reference
In-Depth Information
The algebraic approach in deriving the above transforms is relatively easy.
However, it is also possible to use matrices to derive compound transforma-
tions, such as a reflection relative to an arbitrary line and scaling and rotation
relative to an arbitrary point. These transformations are called
a
ne
, as paral-
lel lines remain parallel after being transformed. One cannot always guarantee
that angles and lengths are preserved, as the scaling transformation can alter
these when different
x
and
y
scaling factors are used. For completeness, we
will repeat these transformations from a matrix perspective.
7.3.6 2D Scaling
The strategy we used to scale a point (
x
,
y
) relative to some arbitrary point
(
p
x
,p
y
) was to first, translate (
p
y
); second, perform the scaling; and
third, translate (
p
x
,p
y
). These three transforms can be represented in matrix
form as follows:
⎡
−
p
x
,
−
⎤
⎡
⎤
x
y
1
x
y
1
⎣
⎦
= [translate(
p
x
,p
y
)]
⎣
⎦
·
[scale(
s
x
,s
y
)]
·
[translate(
−
p
x
,
−
p
y
)]
·
which expands to
⎡
⎤
⎡
⎤
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
10
p
x
01
p
y
00 1
s
x
00
0
s
y
0
001
10
−
p
x
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
·
⎣
⎦
·
⎣
⎦
01
p
y
00 1
−
(7.43)
Note the sequence of the transforms, as this often causes confusion. The first
transform acting on the point (
x
,
y
, 1) is translate (
p
y
), followed by
scale (
s
x
,s
y
), followed by translate (
p
x
,p
y
). If they are placed in any other
sequence, you will discover, like Gauss, that transforms are not commutative!
We can now concatenate these matrices into a single matrix by multiplying
them together. This can be done in any sequence, so long as we preserve the
original order. Let's start with scale (
s
x
,s
y
) and translate (
−
p
x
,
−
−
p
x
,
−
p
y
). This
produces
⎡
⎤
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
10
p
x
01
p
y
00 1
s
x
0
−
s
x
p
x
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
·
⎣
⎦
0
s
y
−
s
y
p
y
00
1
and finally
⎡
⎤
⎡
⎤
⎡
⎤
x
y
1
s
x
0
p
x
(1
−
s
x
)
x
y
1
⎣
⎦
=
⎣
⎦
·
⎣
⎦
0
s
y
p
y
(1
−
s
y
)
(7.44)
00
1
which is the same as the previous transform (7.27).