13.1 Binary Space-Partitioning Trees in 2D 677
} else {
SubPos = Edge(E.V(0), I);
SubNeg = Edge(I, E.V(1));
}
return CROSSES;
} else if (d0>0ord1>0){
// edge on positive side of line
return POSITIVE;
} else if (d0<0ord1<0){
// edge on negative side of line
return NEGATIVE;
} else {
// edge is contained by the line
return COINCIDENT;
}
}
Because of floating-point round-off errors, it is possible that d
0
d
1
< 0, but t is
nearly zero (or one) and may as well be treated as zero (or one). An implementation
of
Classify should include such handling to avoid the situation where two edges meet
at a vertex; the first edge is used for the splitting line, and numerically the second edge
appears to be crossing the line, thereby causing a split when there should be none.
Example Figure 13.3 shows an inverted L-shaped polygon that has 10 vertices and 10 edges.
Theverticesareindexedfrom0to9.Theedgesare9, 0 and i, i + 1 for 0 ≤ i ≤ 8.
We construct the BSP tree an edge at a time. At each step the splitting line is shown
as dotted, the positive side region is shown in white, and the negative side region is
shown in gray.
The first edge to be processed is 9, 0. Figure 13.4 shows the partitioning of the
plane by a dotted line containing the edge and the root node (r)ofthetree.Theedge
9, 0is part of that node (the edge defines the splitting line) and the positive (p) and
negative (n) edges created by the splitting. In this case, all remaining edges are on the
negative side of the line.
The next edge to be processed is 0, 1. Figure 13.5 shows the state of the BSP tree
after the edge is processed.
The next edge to be processed is 1, 2. Figure 13.6 shows the state of the BSP tree
after the edge is processed. The edge forces a split of both 4, 5 and 8, 9, causing
the introduction of new vertices labeled as 10 and 11 in the figure.
The next edge to be processed is 10, 5. Figure 13.7 shows the state of the BSP tree
after the edge is processed. The edge forces a split of 7, 8, causing the introduction
of the new vertex labeled as 12 in the figure.
The next edge to be processed is 5, 6. Figure 13.8 shows the state of the BSP tree
after the edge is processed. No new vertices are introduced by this step.