Graphics Programs Reference
In-Depth Information
Step 2: Create the boundary matrix
Rather than getting bogged down with the specifics of the code in creating the bound-
ary matrix, let's discuss what the code is doing. The general equation for each plane is
given by
b1*x + b2*y + b3*z + b4 = 0
The createBoundaryMatrix function calculates the values for b1, b2, b3, b4 for each
plane and stores them in the boundary matrix b in the following way. Two vectors v1
and v2 are created using three points on each plane where point 2 is between point 1
and point 3 as shown in Figure 9.15.
By performing a certain type of mathematical calculation called the cross product, we
can take the cross product of v1 x v2 to get a normal vector N that is perpendicular to
the plane. If the coordinates have been entered in a counterclockwise direction, then
the vector will be pointing up rather than down.
The coordinates of the normal vector provides b1, b2, and b3. By using the coordinates
of point 1 in the plane equation, we can determine b4. The values b1, b2, b3, and b4
for each plane in the object are stored in the boundary matrix.
N
v2
v1
Figure 9.15 Construction of a normal vector to a plane
Step 3: Test the boundary matrix
The function testBoundaryMatrix tests to see whether the normal vector for each
plane is pointing in the right direction by performing another type of calculation called
the dot product. By taking the dot product of the normal vector and a vector to the
center point, we can determine whether that value is positive or negative. If the test
is negative, then the values in the boundary matrix for that plane are made negative.
Search WWH ::




Custom Search