782 Chapter 13 Computational Geometry Topics
The strip insertion pseudocode is
void Insert(Strip S, float y0, float y1, int i, int classify)
{
// binary search for strip containing y0, assumes S0 = [min, max)
S0 = Locate(S, y0);
if (y0 > S0.min) {
// y0 interior to strip, split to N = [min, y0), S0 = [y0, max)
N = new Strip(y0, max, S0.CopyOfTTree());
S0.min = y0;
S0.InsertBefore(N); // insert N before S0 in search tree
}
// binary search for strip containing y1, assumes strip is min <=y<max
S1 = Locate(S, y1);
if (y1 > S1.min) {
// y1 interior to strip, split to S1 = [min, y1), N = [y1, max)
N = new Strip(y1, max, S1.CopyOfTTree());
S1.max = y1;
S1.InsertAfter(N); // insert N after S1 in search tree
}
// add a trapezoid to each strip spanned by edge
for (L = S0; L <= S1; L++)
Insert(L.ttree, (L.min + L.max) / 2, i, classify);
}
The trapezoid insertion pseudocode is
void Insert(Trapezoid T, float mid, int i, int classify)
{
// Locate correct place to insert new trapezoid by comparing x-values
// along the mid line passing through the trapezoids.
T0 = LocateMid(T, i);
// Split T0 = {min,max} to N = {min,i} and T0 = {i,max}
N = new Trapezoid(T0.min, i, classify);
T0.min = i;
T0.classify = -classify;
T0.InsertBefore(N); // insert N before T0 in search tree
}
The pseudocode supports construction of the point-in-polygon query data struc-
ture. To support triangulation, trapezoids that are vertically adjacent must be merged.