Graphics Reference
In-Depth Information
by tuples like
(
3, 6
)
, while vectors are denoted by 2
1 matrices in square brack-
ets. In
software
(see Chapter 12), it's helpful to also make vectors and points
have different
types
. In an object-oriented language, we would define the classes
Point
and
Vector
. The first would contain an
AddToVector
operation, but not an
AddToPoint
operation; the second would have both (with results of types
Vector
and
Point
, respectively). Such a distinction allows the compiler to save us from
mistakes in our mathematical treatment of points and vectors.
If we, for a moment, use
E
2
×
to denote the set of points, but
R
2
to denote
vectors, then we have defined
difference
:
E
2
E
2
R
2
:(
P
,
Q
)
×
→
→
P
−
Q
, and
(7.47)
sum
:
E
2
R
2
E
2
:(
P
,
v
)
×
→
→
P
+
v
.
(7.48)
(Note that
E
2
E
2
is the Cartesian product of
E
2
with itself, i.e., the set of all
pairs of points.) These definitions generalize in a natural way to
R
n
and
E
n
.In
general, using these operations, we can define an
affine combination of points.
Even though we said we could not add points, we saw earlier that computing the
midpoint between
P
and
Q
could be expressed nicely if we allowed ourselves to
write things like
×
1
2
P
+
1
2
Q
.
(7.49)
We'll now make sense of that. The expression
α
P
+
β
Q
,
(7.50)
which we call an
affine combination
of
P
and
Q
, will be defined only when
α
=
1. If we pretend for a moment that all sorts of arithmetic on points is well
defined, then we can add
+
β
β
P
and subtract it, to get
α
P
+
β
Q
=
α
P
+
β
P
+
β
−β
Q
P
(7.51)
=(
α
+
β
)
P
+
β
(
Q
−
P
)
(7.52)
=
P
+
β
(
Q
−
P
)
.
(7.53)
With this cavalier bit of algebra as motivation, we
define
α
P
+
β
Q
to mean
P
+
β
(
Q
−
P
)
,
(7.54)
which makes sense because
Q
P
)
is as well;
this vector can be added to the point
P
to get a new point. This definition naturally
generalizes to an affine combination of more than two points; for instance,
−
P
is a vector, and hence
β
(
Q
−
α
P
+
β
Q
+
γ
R
, where
α
+
β
+
γ
=
1,
P
+
β
(
Q
−
P
)+
γ
(
R
−
P
)
.
(7.55)
We'll frequently encounter such affine combinations of points, especially
when we discuss splines in Chapter 22. Mann et al. [MLD97] make a case
for treating all of graphics in terms of such “affine geometry,” and abandon-
ing coordinates to the degree possible. In fact, it makes sense to include an
AffineCombination
method for
Points
, to avoid errors or code that can be baf-
fling. Listing 7.1 shows a possible implementation.