Point in Polygon

11.2.1 Point in Polygon

The basic idea behind our first parallel algorithm is illustrated in Fig. 11.2. Assume that a vertical line is drawn through point p. Next, the intersection points between this

line and the edges of Q are found. If the number of such intersection points above p is odd, then p is inside Q; otherwise it is outside Q. This test can be performed

11.2 Test for point inclusion inside polygon.

Figure

11.2 An Inclusion Problem 281

sequentially in steps for a polygon with n edges, and this is clearly optimal since steps are needed to read the input. We can implement this test on a tree-connected SIMD computer as follows. Since Q has n edges, the tree consists of n processors

P,, ... , P,. The processors are

numbered beginning from the root and proceeding, level by level, from left to right. Thus the root is

and so on. Each processor stores an edge of Q given by the Cartesian coordinates of its two endpoints. Initially the root reads the and y coordinates of p, namely,

its children

and

and broadcasts them to all the other processors. When a processor

receives the coordinates of p, it determines whether (i) a vertical line through p (call it

intersects the edge of Q it stores (call it and (ii) the intersection point is located above p.

If these two conditions hold, the processor produces a 1 as output. Otherwise it produces a

The processors' outputs are now added, and if the sum is odd, is declared to be inside Q. The algorithm is given in what follows as procedure POINT IN POLYGON. It is assumed that each processor

already contains Two additional variables

serve in computing the total number of intersections above p. At the end of the procedure

and

in

produces an answer equal to 1 if p is inside Q and equal to otherwise.

procedure POINT IN POLYGON

intersects above p

then else end if

to Step

+ 1) - 2 j 1 do

1 do in parallel (2.1)

receives

s) from its parent

(2.2) if

intersects above p

sends (x,,

+ s) to and

to

end for end for.

Step 3: for j =

to

1 do in parallel

receives

s) from its parent

(3.2) if

intersects above p

end for.

Computational Geometry Chap. 11

Step 4: for i = 1 to

+ 1) - 1 do

in parallel

end for end for.

Step if a, is odd

answer

else answer

end if.

Analysis. The procedure consists of two stages: the descent stage (steps 1 where all the intersection tests are performed, and the ascent stage (steps 4 and 5), where the total number of intersections above p is computed. It takes a constant number of operations to test whether a straight line and a straight-line segment

intersect. Given that the tree has n processors, both the descent and ascent stages take

n) time. Since

= n,

n), which is not optimal.

Example 11.1

The edges of the polygon in Fig. 1 1 . 2 are stored in a tree-connected computer with seven processors, as shown in Fig. 11.3. For the input point p of Fig. 1 1 . 2 , only processors

P,, and produce a 1 as output, and the root declares p to be inside Q. Three points are worth noting:

1. Several points can be tested for inclusion in a polygon Q by pipelining procedure POINT IN POLYGON. Indeed, once a processor has performed its test (and sent to its

child the partial total the number intersections above p) it is free to receive the next point. It is with this pipelining in mind that the procedure was designed, so that partial totals never stay in a given processor

Figure

11.3 Testing point inclusion using procedure POINT IN POLYGON.

11.2 An Inclusion Problem 283 but are constantly moving either downward or upward. The period is therefore

constant.

2. The procedure can be easily modified to handle the case where there are more (or fewer) processors than polygon edges.

3. It is possible to modify the procedure to achieve optimal cost. The idea is to use processors each storing log n edges of Q. It takes

n)) time to broadcast the coordinates of p to all processors. Each processor now performs the intersection test for all logn edges it stores and adds up the number of

intersections above p in n) time. The total number of intersections above p is computed in

time. The overall running time is as before. However, the period is no longer constant.