Graphics Reference
In-Depth Information
Listing 7.1: Code in C# for creating an affine combination of points, with a
special case for two points.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public Point AffineCombination(double[] weights, Point[] Points)
{
Debug.assert(weights.length == Points.length);
Debug.assert(
sum of weights
==
1. 0
);
Debug.assert(weights.length > 0);
Point Q = Points[0];
for(inti=1;i<weights.length; i++) {
Q = Q + weights[i]
*
(Points[i] - Points[0]);
}
return Q;
}
public Point AffineCombination(Point P, double wP,
Point Q, double wQ)
{
Debug.assert( (wP + wQ) == 1.0);
Point R = P;
R=R+wQ
*
(Q - P);
return R;
}
The product of two matrices
A
and
B
is defined only when the number of columns
of
A
matches the number of rows of
B.
If
A
is
n
×
k
and
B
is
k
×
p
, then the
product
AB
is an
n
p
matrix. If we let the
i
th row of
A
be the transpose of the
vector
r
i
, and the
j
th column of
B
be the vector
c
i
, then the
ij
th entry of
AB
is just
r
i
·
×
c
j
. The following picture may help you remember this:
p
⎡
⎛
⎞
⎤
⎫
⎬
.
.
.
⎣
⎝
⎠
c
j
⎦
·
k
⎭
⎧
⎨
⎩
⎡
⎤
⎡
⎤
↓
(7.56)
.
.
⎣
⎦
⎣
⎦
.
→
r
i
·
c
j
n
r
i
k
Thus, we see that the dot product of the vectors
v
and
w
is just the matrix product
v
T
w
:
w
=
v
T
w
=
w
T
v
.
v
·
(7.57)
This leads to an interpretation of the product of the matrix
A
(with rows
a
i
)
and a vector
v
:If
w
=
Av
, then the
i
th entry of
w
tells “how much
v
looks like
a
i
” (in the sense described when we discussed Equation 7.38).