Finding a Closest Visible Vertex Pair Between Two Polygons 1 ...

14 downloads 2511 Views 235KB Size Report
Finding a Closest Visible Vertex Pair Between Two Polygons. Nancy M. Amato y. Coordinated Science Laboratory and Department of Computer Science.
To appear in

Algorithmica

Finding a Closest Visible Vertex Pair Between Two Polygons Nancy M. Amatoy Coordinated Science Laboratory and Department of Computer Science University of Illinois at Urbana-Champaign 1308 W. Main St. Urbana, IL 61801 email:

[email protected]

Abstract

Given nonintersecting simple polygons and , two vertices 2 and 2 are said to be visible if does not properly intersect or . We present a parallel algorithm for nding a closest pair among all visible pairs ( ), 2 and 2 . The algorithm runs in time (log ) using ( ) processors on a CREW PRAM, where = j j + j j. This algorithm can be implemented serially in ( ) time, which gives a new optimal sequential solution for this problem. P

pq

p; q

O

n

Q

P

p

P

q

Q

Q

p

P

O n

q

Q

n

P

Q

n

1 Introduction

Computing the minimum distance between two nonintersecting simple polygons P and Q is a well studied problem in computational geometry. There are two common variants of this problem: (i) nding a closest pair of boundary points between P and Q, and (ii) nding a closest pair of mutually visible vertices between P and Q, where vertices p 2 P and q 2 Q are visible if pq does not properly intersect P or Q. The former variant is known as the separation problem [DK90], and we will refer to the latter variant as the closest visible vertex or the CVV problem (see Fig. 1). The Euclidean distance between a pair of points realizing the closest visible vertex distance between P and Q is denoted by cvv (P; Q). For convenience, in this paper we will refer to the CVV problem as nding cvv (P; Q), e.g., a solution of cvv (P; Q) will give a pair (p; q ) realizing cvv (P; Q), p 2 P and q 2 Q. Although the separation and the CVV problems appear to be closely related, it seems no bene t for either problem has been gained by this similarity in the past; in fact, the algorithms proposed for these two problems have di ered greatly from one another. Computing the closest visible vertex distance between two polygons P and Q has received much attention. Let jP j + jQj = n. The CVV problem has been addressed sequentially in various cases. When both P and Q are convex, cvv (P; Q) can be computed sequentially in time (n) [MT85, Tou84, CSW85]. If exactly one of P or Q is convex, then cvv (P; Q) can also be computed sequentially in time (n) [CSW85, Wan83]. Several sequential CVV algorithms have been proposed  This paper appeared in preliminary form as [Ama92] y This work was supported in part by an AT&T Bell Laboratories Graduate Fellowship, the Joint Services Electron-

ics Program (U.S. Army, U.S. Navy, U.S. Air Force) under contract N00014-90-J-1270, and NSF Grant CCR-89-22008.

1

P

Q qc

p

c

qs p

s

Figure 1: The separation of P and Q is realized by the pair (ps ; qs), and the closest visible vertex distance is realized by the pair (pc ; qc ). when neither P nor Q is convex: Wang and Chan [WC86] have given an algorithm for computing cvv(P; Q) in time O(n log n), Aggarwal et al. [AMSS89] proposed an optimal (n) algorithm for this problem, and recently Hershberger and Suri [HS93] have given a general technique which can be used to solve several problems dealing with shortest paths in simple polygons, including the CVV problem, in O(n) time. In parallel, the CVV problem has been addressed for the case in which neither polygon is convex by Hsu et al. [HCL92]. Their O(log n) time and O(n) processor algorithm is patterned after the sequential algorithm of Aggarwal et al.. The model of parallel computation used by Hsu et al. is the CREW PRAM, which is a shared memory machine that supports concurrent reads from (but not writes to) a common shared memory location in unit time; for details of the various PRAM models consult [KR90]. In this paper we study the problem of determining cvv (P; Q) in the most general case, i.e., when P and Q are any two nonintersecting simple polygons. We describe a parallel algorithm for computing cvv (P; Q) that runs in time O(log n) using O(n) processors on a CREW PRAM. Although it is not work-optimal, our algorithm is time-optimal, as shown by Atallah and Goodrich [AG88]. Actually, they show that any parallel algorithm for the separation problem requires (log n) time on an exclusive write PRAM (i.e., an EREW or a CREW PRAM) with a polynomial number of processors; however, their argument can easily be applied to the CVV problem as well. Our CVV algorithm consists of two phases: (i) rst the problem of computing cvv (P; Q) is decomposed into a collection of linearly separable subproblems, and then (ii) the subproblems are solved independently, and the subproblem realizing cvv (P; Q) is identi ed. The sequential algorithms of Wang and Chan [WC86], and Aggarwal et al. [AMSS89], and the parallel algorithm of Hsu et al. [HCL92] all have this same general strategy. We give a new decomposition technique that is much simpler than the corresponding methods used in the above mentioned CVV algorithms [WC86, AMSS89, HCL92]. Our solution of the linearly separable subproblems is a modi cation of the sequential technique of Aggarwal et al., which includes some new ideas and some concepts rst introduced in the sequential algorithm of Wang and Chan. However, we must modify the technique of Aggarwal et al. for solving the subproblems since, as is discussed in Section 3.2, the technique, as presented in [AMSS89], does not always correctly determine cvv (P 0; Q0); since this portion of the parallel algorithm of Hsu et al. is a direct parallelization of the method of Aggarwal et al., their algorithm su ers this shortcoming as well. A sequential version of our parallel algorithm can be implemented in (n) time, which gives a new optimal sequential algorithm for the general version of the CVV problem. An advantage of this 2

algorithm over the optimal sequential algorithm of Aggarwal et al. is that the decomposition phase is much simpler. In particular, the decomposition proceeds in our algorithm by performing some simple modi cations to a shortest path in a simple polygon, whereas the algorithm of Aggarwal et al. uses the complicated window tree data structure [Sur87]. Due to its generality, the sequential CVV algorithm resulting from the new technique of Hershberger and Suri [HS93] is somewhat more complicated than our sequential algorithm; brie y, whereas we need only a single shortest path in a certain simple polygon, their technique builds (during preprocessing) a powerful data structure that implicitly contains every shortest path between two sets of vertices in the simple polygon. Another feature of our CVV algorithm is that we have shown that the same general strategy can be used to solve the separation problem as well, i.e., there is no underlying geometric reason that past algorithms for the CVV and separation problems have di ered so greatly from one another. In particular, we show in [Ama93] that the CVV algorithm presented here can be modi ed to nd the separation of two simple polygons; the parallel separation algorithm uses O(log n) time and O(n) processors on a CREW PRAM, and its sequential version runs (n) time. This improves over the best previous sequential time bound of O(n log n) which was based on generalized Voronoi diagrams [Kir79, For87, Yap87]. The parallel complexity of the separation problem had not been previously studied except in the special case in which both polygons are convex [AG88, DK87]; however, a solution of the general case can be found in O(log2 n) time using O(n) processors on a CREW PRAM since generalized Voronoi diagrams can be computed within these resource bounds [GO Y93].

2 Nonintersecting Simple Polygons In this section we decompose the problem of computing cvv (P; Q) into a collection of restricted subproblems. The decomposition is based on a sequence of line segments separating P and Q, and the subproblems are of the following form: compute cvv (P 0; Q0), where P 0 and Q0 are linearly separable subchains of P and Q, respectively. Although similar decomposition takes place in the parallel algorithm of Hsu et al. [HCL92], and in the sequential algorithms of Wang and Chan [WC86] and Aggarwal et al. [AMSS89], the methods used in these algorithms to nd an appropriate set of separating line segments and to construct the subproblems are quite involved. The parallel algorithm of Hsu et al. introduces data structures called merging trees which are combined with other complicated calculations; they rst present a complex O(log2 n) time and O(n) processor divide-and-conquer decomposition method, and then they use a technique built upon merging tree data structures (requiring such operations as splitting a single merging tree into a sequence of merging trees) to reduce the time complexity to O(log n). The sequential decomposition technique of Aggarwal et al. is built upon the window tree data structure [Sur87], (parallelization of this technique would require the nontrivial parallelization of the window tree data structure). The decomposition step of the sequential algorithm of Wang and Chan requires O(n log n) time (this technique uses an inherently sequential greedy scanning process). In contrast, the decomposition technique proposed here is very simple: the sequence of separating line segments is constructed by modifying a shortest path in a simple polygon that lies between P and Q, and once this set of separating line segments is found the de nition of the subproblems is almost immediate. There are two general situations that we distinguish: the containing case, when CH (P [ Q) is identical to CH (Q) or CH (P ), and the non-containing case (see Fig. 2). Note that in the non3

p

qt

t

l

t

Q

q

P

Q

l

l

Q 2

q

b

1

l

2

l

l

l

1

l

p

P

P

l

0

er

el

4

3

l

l

4

3

5

l

0

p

b

l

b

(a)

(b)

Figure 2: The (a) non-containing, and (b) containing cases. containing case we can reduce the problem of computing cvv (P; Q) to that of computing cvv (P 0; Q0), where P 0 and Q0 are the facing portions of P and Q between the two common supporting lines to CH (P ) and CH (Q). Another feature of our decomposition technique is that it allows the containing and the non-containing cases to be treated identically after the sequence of separating line segments is found, whereas the CVV algorithms of Wang and Chan, Aggarwal et al., and Hsu et al. all treat the containing and non-containing cases di erently. The decomposition technique is outlined in Algorithm 2.1.

Algorithm 2.1 DECOMPOSE(P; Q) Step 1. Find a sequence of line segments separating P and Q. (a) Construct a simple polygon R that lies between P and Q. In the non-containing case (see Fig. 2(a)), nd the two common supporting lines lt and lb to CH (P ) and CH (Q); R is formed from P 0 and Q0 and the segments qb pb and qtpt of lb and lt, respectively, between P and Q. In the containing case we assume without loss of generality that CH (P [ Q) = CH (Q) (see Fig. 2(b)). In this case, R is formed from the portion of the plane that lies between P and Q by adding a segment between two visible vertices p 2 P and q 2 Q; this segment is viewed as two edges of R. (If CH (P [ Q) = CH (Q) but P is not contained within Q, then we also include an edge of CH (Q) in R.) (b) Find a shortest path in R. In the non-containing (containing) case, nd the shortest path in R between pb and pt (the two instances of p). (See coarse dotted line in Fig. 2.) (c) Extend the segments of the shortest path to the boundary of R. Let SP (P; Q) = (l0sp, l1sp , : : :, lksp,1) denote the resulting sequence of segments. 4

Q

+

q i+1

P

l i+1

Q

i

p+ = t i i

+

q i

+

q i-1

Pi b i

+

p i-1

l

i l i-1

Figure 3: The subchains Pi and Qi associated with li. (d) Remove redundant segments from the shortest path. Identify the subset S (P; Q) = (l0; l1; : : :; lm,1) of SP (P; Q) that satis es: (i) l0 = l0sp , and (ii) li is the maximal (indexed) segment in SP (P; Q) that intersects li,1 , for i increasing, 0 < i < m  k. In the containing case, all arithmetic is modulo m and we require lm,1 \ l0 6= ;. (See ne dotted line segments in Fig. 2.) We now give some useful de nitions. A vertical orientation is associated with each segment li 2 S (P; Q) so that the bottom (top) endpoint bi (ti ) of li is the endpoint closest to li,1 (li+1 ). It is a simple matter to verify that each li 2 S (P; Q) intersects both P and Q, either at an endpoint or at some interior point of li ; let p+i and qi+ denote the highest points of intersection of li with P + = qb , p+ = pt, and Q, respectively. For convenience, in the non-containing case let p+,1 = pb , q,1 m + and qm = qt . The subchain of P beginning at pi and ending at pj , in a clockwise scan of P , is denoted by Ppi ;pj (pi and pj may be any points on the boundary of P ); the subchain Qqi;qj is de ned analogously with counterclockwise replacing clockwise. Step 2. Construct the subproblems. For each segment li 2 S (P; Q) we de ne a subproblem cvv(Pi; Qi), where Pi and Qi are subchains of P and Q, respectively, separated by li. The subchains Pi, 80  i < m, are de ned as follows; subchains Qi are de ned analogously. (See Fig. 3.) (a) The initial assignment of subchains to li.

8 < P + + if ti 2 P or i = m , 1 Pi = : Ppi+,1;pi+ otherwise pi,1 ;pi+1

(b) Prune the initial subchains, if necessary. If ti 2 P , and li+1 is not perpendicularly visible from p+i = ti (i.e., the perpendicular segment from p+i to li+1 intersects P ), then we prune Pi as follows. Assume li+1 is horizontal, and let px be the rightmost vertex of Pp+i ;p+i+1 . Delete all vertices of Pi above bi+1 that lie to the left of px. We rst examine the complexity of DECOMPOSE, and then we prove its correctness. 5

2.1 Complexity of DECOMPOSE Let n = jP j+jQj. Computing the set of separating line segments S (P; Q) in Step 1 of DECOMPOSE can be accomplished in O(log n) time using O(n) processors on a CREW PRAM. The classi cation of containing or non-containing requires that we compute the convex hulls of P , Q, and P [ Q, and then test whether CH (P [ Q) is identical to CH (P ) or CH (Q); the former can be accomplished in O(log n) time using O(n= log n) processors on an EREW PRAM [Che90, DK90], and the latter can be done in constant time using O(n) processors. In the non-containing case the simple polygon R is completed by segments belonging to the two common supporting lines of CH (P ) and CH (Q) (see Fig. 2(a)); these supporting lines can be found by the O(log n) sequential technique of Dobkin and Kirkpatrick [DK90] when merging CH (P ) and CH (Q) to form CH (P [ Q). The construction of R in the containing case is nearly as simple. Assume CH (P [ Q) = CH (Q), let p 2 P be the vertex of P with largest y -coordinate, and let E be the subset of the edges of Q [ CH (Q) that are intersected by the horizontal line through p. Find the closest edges to p in E , from both the left and the right; denote these edges by el and er , respectively (see Fig. 2(b)). Let q be the vertex of the subchain of Q (closest to p) between el and er with smallest y -coordinate; clearly p and q are visible and thus the segment pq can be used to form R. All of the above computations can be carried out by standard parallel techniques in O(log n) time using O(n= log n) processors on an EREW PRAM [KR90]. If CH (P [ Q) = CH (Q), but P is not contained in Q, then the edge of CH (Q) needed to separate R from the unbounded region can be found by a list ranking process within these same resource bounds. The shortest path in Step 1(b) can be computed in O(log n) time using O(n= log n) processors by the technique of Goodrich et al. [GSG90]; this technique requires that R be triangulated which can be done in O(log n) time using O(n) processors [Goo89]. The extension of the endpoints of the shortest path in Step 1(c) can be done by ray shooting queries (i.e., given a simple polygon R and a query ray r, what is the rst edge of R that is hit by r); the technique of Goodrich et al. [GSG90] answers such queries in O(log n) time with a single processor. The removal of the redundant segments from SP (P; Q) in Step 1(d) can be performed by a list ranking process in O(log n) time using O(n= log n) processors. The construction of the subproblems in Step 2 is straightforward once S (P; Q) is found. Each subproblem can be de ned in O(1) time, and, if necessary, the pruning of the subchains can be accomplished in O(log n) time with O(n) processors using ray shooting queries [GSG90]. Thus, Step 2 requires O(log n) time and O(n) processors. A CREW PRAM is needed for Steps 1 and 2 since the ray query data structure may be involved in O(n) simultaneous queries, i.e., concurrent accesses. We will show in Section 2.2 that cvv (P; Q) = min0i