JOURNAL
OF PARALLEL
AND DISTRIBUTED
COMPUTING
9, 1 I- 14 ( 1990)
A Parallel Algorithm for the Visibility Problem from a Point PAOLA BERTOLAZZI AND SILVIO SALZA Istituto di Analisi dei Sistemi e hformatica
de1 CNR, Viale Manzoni 30, I-00185 Rome, Italy AND
CONCETTINA GUERRA * Department of Computer Sciences, Purdue University, West Lafayette, Indiana 47907
is given. The algorithm achieves 0 (log n) time on a meshof-trees with 0 (n ‘) processors. In this paper we present an optimal parallel algorithm for the visibility from a point, which takes 0 (log n) time on the
The problem of the visibilityfrom apoint is defined as follows: given a set 8 of n nonintersecting line segments and a point x, determine the region of the plane that is visible from x. A simpler instance of this problem is the visibility from a point inside a simple polygon. In this paper we present an optimal parallel algorithm for determining the visibility from a point. The algorithm is based on a divide-and-conquer strategy and has time complexity O( log n) on a PRAM with 0 (n) processors. o 1990
CREW PRAM (Concurrent Read Exclusive Write Parallel RAM) computational model with O(n) processors. The
same bounds have been independently obtained in [ 41 using a different technique. Our algorithm is based on a parallel divide-and-conquer strategy first employed by Valiant [lo] and then used in computational geometry by Atallah et al. [ 1,5, 111. The strategy consists of dividing a problem of size n into G subproblems of equal size which are recursively solved in parallel. It is well known that such a strategy leads to an 0 (log n) parallel algorithm if the step of combining the results of the subproblems can be performed in 0 (log n) time. By exploiting geometrical properties of the visibility problem, we show how to combine the subproblems in 0 (log n) time with 0 (n) processors. The paper is organized as follows. In Section 2, after some definitions, we give a result which forms the basis for the algorithm. In Section 3 we present the algorithm for solving the visibility problem from a point.
Academic Press, Inc.
1. INTRODUCTION
Given a set S of n line segments and a point x on the plane, the visibility problem from x is to determine the region consisting of all the points y visible from x, i.e., such that the segment xy does not intersect any segment of 8. This problem is the generalization of the well-known visibility problem inside a simple polygon, which is defined as follows: given a simple polygon P having n vertices and a point x inside P, find the visibility polygon V( P, x) consisting of all the points y of P that are visible from x. Visibility problems have a number of applications in graphics, vision, robotics, etc. The visibility from a point is solvable by a sequential algorithm in O( n log n) time [ 91. A linear sequential algorithm for the visibility inside a simple polygon is presented in [ 61. An 0 (n log h) time algorithm for a polygon with h holes is proposed in [ 2 ] . There have been also a number of parallel algorithms proposed. In [ 31, an O(n) systolic algorithm is presented for the visibility within a polygon with holes. In [ 81 an algorithm for the visibility problem among n vertical segments
2. DEFINITIONS
AND PRELIMINARY
RESULTS
We consider a set S of n nonintersecting segments on the planes,, . . . , S,,, where each S; is identified by its endpoints {vZi,2)2i+l),fori=0 ,..., n - 1. Let x and y be two points of the plane. The point y is said to be visible from x (w.r.t. 8) if the segment xy does not intersect any of the segments OfS. We consider a polar coordinate system with origin in x. The polar angle 6Jincreases clockwise. We say that a point p is to the left (to the right) of another point q if the angular coordinate of p is smaller (greater) than that of q. We also
* This work was done while C. Guerra was visiting IASI under Grants 104354 and 2 12342 of the Progetto Finalizzato Materiali e Dispositivi per I’Elettronica a Stato Solid0 of CNR. 11
0743-73 I5/90 $3.00 Copyright 0 1990 by Academic Press, Inc. All rights of reproduction in any form reserved.
12
BERTOLAZZI,
SALZA.
assume, without loss of generality, that the endpoints of the n segments have distinct angular coordinates. The locus of points of the plane that are visible from x w.r.t. to 8 is the visibility region of x. The visibility region can be described by a sequence of points wo, . . . , w,,-, with increasing angular coordinate, which we will call the visibility chain and denote as @. Since the visibility region can be unbounded, we include in the chain points at infinity to delimit unbounded visible wedges of the plane. It is easily seen that a point w of the visibility chain is either: (i) a visible endpoint of a segment Si; or (ii) the intersection of a segment Si and a ray from X through a visible endpoint of another segment Sj; or (iii) the point at infinity of a ray from x through a visible endpoint of a segment S, when the ray does not intersect any other segment. To better characterize points of type (ii) let us consider for every visible endpoint v the first segment H of S hit by the ray p emanating from v in the direction XV. We call such segment the hit segment of D. Its intersection with p is a point of type (ii). If the ray p does not intersect any segment of 8 then the hit segment will be indicated by H*. In Fig. 1, a visibility region and its visibility chain @ are shown. From the above observations it follows that determining the visibility chain @ is equivalent to determining, for each endpoint of a segment, if it is visible from x w.r.t. 8, and, if so, its hit segment. In fact, once this information is available, the points of types (ii) and (iii) are found by simply intersecting each ray through a visible endpoint with its hit segment. We call visible endpoint set of S and denote by Y the set of the endpoints of the segments in 8 that are visible from x w.r.t. 8. We now give some properties that allow us to find the visible endpoint set efficiently. To do this we need some additional notation. Given two rays pa and pa from x with po-
FIG. 1. The visibility region.
AND GUERRA
lar angles (Yand 0, a! < p, they define a wedge W( a, ,8) (or W, for short) in the plane having pa and ps as left and right boundaries, respectively. We say that a segment Si is internal to W if at least one of its endpoints lies in W, and that Sj is a crossing segment for W if it has a nonnull intersection with W but neither endpoint is in it. Given a wedge W, the visibility region of x in W is the locus of the points of the plane that lie in W and are visible from x w.r.t. the set of all the segments of S that are internal to W. This region is described by its visibility chain C?( W) . The set of points of type (i) of e(W) is called the visible endpoint set of W and denoted as Y(W). When the width of the wedge is the round angle, all the segments are considered and hence the visibility region in the wedge becomes the visibility region of x. Now let W (a!, /3) and W’( (Y’,p’) be two wedges such that W’ 2 W, i.e., (Y’6 (Y< p < p’. Consider the set & c S of all the segments of S that are internal to W’ and are crossing segments for W and suppose that 6’ is not empty. We call the lowest crossing segment for W in W’ the segment of G that has the intersections with the boundaries of W with the lowest radial coordinate. The following lemmas hold. LEMMA 1. Given two wedges W and W’, such that W’ 2 W, an endpoint v of a segment S in the visible endpoint set of W is also in the visible endpoint set of W’ if and only if either there is no crossing segment for W in W’ or v is visiblefromx w.r.t. the lowest crossingsegmentfor W in W’.
Proof Necessity. The necessity trivially derives from the definition of visible endpoint set in the wedge. Suficiency. If no segment of W’ is a crossing segment for W then v belongs to the visible endpoint set of W’. Hence, suppose that there exists at least a crossing segment for W in W’ and let Z be the lowest crossing segment. Suppose now that v is visible w.r.t Z but does not belong to the visible endpoint set Y( W’). In this case there must be a segment Y of S internal to W’such that v is not visible w.r.t. Y. Such a segment cannot be internal to W because v is in the visible endpoint set Y ( W) and, therefore, is a crossing segment for W in W’. Now consider the intersections z and y between the radius from x through v and the segments Z and Y, respectively. Clearly, y < z. This leads to a contradiction because, as two segments cannot intersect, Y has intersections with the boundaries of W with radial coordinates less than those of Z, and so Y should be the lowest crossing segment. n Now let v be a visible endpoint in W. We define the hit segment of v in W as the segment internal to W with the lowest intersection with the ray p from v in the direction xv. The intersection is always an internal point of the hit segment, as we have assumed that no two endpoints can have the same angular coordinate.
PARALLEL
ALGORITHM
FOR VISIBILITY
FROM A POINT
13
LEMMA 2. Given two wedgesW and W’, suchthat W’ Fig. 2). Moreover, the hit segment of each element of 2 W, and a visibleendpointv in W, the hit segmentof v in Y ( W ) must be updated according to Lemma 2. W’ is eitherthehit segmentof v in W or the lowestcrossing The details of the combining step follow. segmentfor W in W’. ProcedureCOMBINE Proof If there is no crossing segment for W in W’ then Step 1. For every wedge Wi determine the two sets Bi obviously the hit segment H of v in W is also the hit segment = { Ri,j} and &i = { Li,, > of the segments having, respecin W’. Otherwise, let Z be the lowest crossing segment and
z its intersection with the ray p. Also, let y be the intersection of p and H. If z < y then the hit segment of v becomes z. w 3. DETERMINING
THE
VISIBILITY
CHAIN
We now present the procedure VCS for determining visibility chain 6’.
the
ProcedureVCS Stepa. Given n endpoints belonging to a wedge W, sort them by increasing angular coordinate, and partition the wedge in fi wedges WI. . . WG, in such a way that each wedge W, contains at most 6 endpoints. Step b. Recursively find in parallel the visible endpoint set ?I ( W,) for each wedge W;. Moreover, for each point v E 1/ (Wi) find the hit segment H of v in Wi. Stepc. Find the visible endpoint set of W from the visible endpoint sets of all the Wi and update, for each element of ‘V(W), the hit segment. This strategy leads to an 0 (log n) parallel algorithm, if Stepc can be performed in 0 (log n) time. This is due to the fact that the total time for solving a problem of size n is given by the recurrence relation
T(n)= T(fi)+logn, which has an 0 (log n) solution. The base of the recursion is trivial and consists of finding the visible endpoint set for a wedge containing a constant number of endpoints, and, for each element of the visible endpoint set, the hit segment in the wedge. The crucial part of the procedure is Stepc, i.e., combining, at each level of the recursion, the visible endpoint sets of the fi contiguous wedges Wi to obtain the visible endpoint set of W and update the hit segments of the elements ofV(W). To this end, to determine V(W), according to Lemma 1, it is sufficient to check, for each wedge Wi and for each endpoint v E 1/ ( Wi), if u is visible w.r.t. the lowest crossing segment for Wj in W. This is done in parallel for each W,, by first finding, for every wedge Wk P Wi, the lowest crossing segment for Wi in W with one endpoint in Wk and then computing the lowest among all such segments (in bold in
tively, the right and the left endpoints in Wi and crossing at least one of the other wedges. Let 0,,, and dRLj be the polar angles of the right endpoint of Li,j and of the left endpoint of Ri,j, respectively. Step2. Sort the segments in & i by increasing angular coordinate of the right endpoint and the segments in Ri by decreasing angular coordinate of the left endpoint. Then relabel the segments in Xi and & i according to this ordering. Step3. For every segment Li,j in the ordered set -Ci find, among all the segments Li,hwith h > j, if any, the segment 44i.j that has the intersection with the right boundary of Wi with minimum radial coordinate. Note that for any wedge W, to the right of Wi and with the right boundary forming an an& BL,,,-, < PI G OL,,,, Mi,j is the lowest crossing segment with an endpoint in Wi. Similarly, for every segment Ri,jE 3, find, among all the Ri,ksuch that k > j, if any, the segment Qi,, with the lowest intersection with the left boundary of W, . Step4. For each wedge Wi find the lowest crossin segment with an endpoint in any of the remaining $ n - 1 wedges, if any. To do this, for each wedge Wk to the left of Wi, search the set h: k for the first segment L,, crossing W/T i.e., with eLkh > /3i. According to Step3, the corresponding segment Mi,h is the lowest segment crossing Wi and with left endpoint in Wk. Similarly, for each wedge Wk to the right of Wj, find the lowest segment Qk,h crossing Wi with right endpoint in Wk. Note that both the endpoints of a segment may be in W and hence a segment may be considered twice. However, it is easy to see that this does not affect the correctness of the algorithm.
FIG. 2. The lowest crossing segment.
14
BERTOLAZZI,
SALZA,
Step 5. For each Wi determine the lowest crossing edge for Wj in W. This is done by taking the lowest of all the Mk,, and Qk,h, which we shall call Zi. Step 6. For every visible vertex in Wj determine if it belongs to the visible endpoint set of W by checking its visibility from X w.r.t. Zi. Step 7. For each endpoint u in Wi which is visible also in W determine the intersection z between the ray p from x through v and Zi and the intersection y between p and H. If z < y then the new hit segment for u is Zi. Note that if H = H* then obviously z < y so that Z, becomes the new hit segment of 2)in W.
The correctness of the algorithm directly follows from Lemmas 1 and 2. We show now that the procedure COMBINE finds the visible set of W in time 0 (log(n)) with O(n) processors. In fact Step 1 requires constant time with a processor assigned to every vertex:In Step 2, the two sets Lci and %i, containing at most fi elements, can be sorted in 0 (log n) time with G processors assigned to each wedge. Also, Step 3 is executed in parallel for all the wedges. In each wedge Wi, it essentially consists of finding, for each segment L;,j in the ordered set 6 1, the segment Li,k with k > j, with minimum intersection with Wi. This can be performed with a prefix computation which, for fi elements, requires O(log n time with Is’n processors, as shown in [7]. In Step 4, $ n processors are assigned to each wedge Wi: each processor performs a logarithmic search in the ordered set Lk (or Y&) of a distinct wedge Wk. Then in Step 5 all the 6 processors of each wedge find in parallel the lowest crossing segment. Finally, Steps 6 and 7 take constant time with a processor assigned to each vertex. 4. CONCLUSIONS
We have presented a parallel algorithm for the visibility problem from a point. The algorithm has a very simple recursive structure. This is due to the geometric properties expressed by Lemmas 1 and 2, which allow one to extend the visibility in a wedge considering only visibility w.r.t. the lowest crossing segment. The algorithm is optimal for the case of nonintersecting segments. However, its restriction to the case of a simple polygon is not. It remains an open question whether it is possible to obtain logarithmic time using 0( n/log n) processors for the latter problem. For our algorithm such a reduction in the number of processors is not possible because of the presence of sort operations. Received August 9, 1988; revised January 3. 1989
AND GUERRA REFERENCES
1. Aggarwal, A., Chazelle, B., Guibas, L., O’Dunlaing, C., and Yap, C. Parallel computational geometry. Proc. 26th FOCS, IEEE Computer Society, 1985, pp. 468-477. 2. Asano, T. An efficient algorithm for finding the visibility polygon for a polygonal region with holes. Trans. IECE-Japan E-68 ( 1985), 557559. 3. Asano, T., and Umeo, H. Systolic algorithms for computing the visibility polygon and triangulation of a polygonal region. Parallel Comput. 6,2 (Feb. 1988), 209-216. 4. Atallah, M., Cole, R., and Goodrich, M. T. Cascading divide-and-conquer: A technique for designing parallel algorithms. Proc. 28th FOGS, IEEE Computer Society, 1987, pp. 15 I-160. 5. Atallah, M., and Goodrich, M. T. Efficient solutions to some geometric problems. J. Parallel Distrib. Comput. 3,4 (Dec. 1986), 492-507. 6. Gindy, H. E., and Avis, D. A linear algorithm for computing the visibility polygon from a point. J. Algoriorithms2,2 (June 198 1), 186-197. 7. Ladner, R. E., and Fischer, M. J. Parallel prefixcomputation. J. Assoc. Cumput. Mach. 27,4 (Oct. 1980), 831-838. 8. Lodi, E., and Pagli, L. A VLSI algorithm for a visibility problem. In Bertolazzi, P., and Luccio, F. (Eds.). VLSI: Algorithms and Architectures. North-Holland, Amsterdam, 1985, pp. 125-136. 9. Sharir, M.. and Schorr, A. On shortest paths in polyhedral spaces. SIAMJ. Comput. 15, 1 (Feb. 1986), 193-215. 10. Valiant, L. G. Parallelism on comparison problems. SIAM J. Comput. 4,3 (Sept. 1975), 348-355. I 1. Wang, C. A., and Tsin, Y. H. An 0( log n) time parallel algorithm for triangulating a set of points in the plane. Inform. Process. Left. 25, 1 (Apr. 1987), 55-60. PAOLA BERTOLAZZI received the Ph.D. degree in electrical engineering from the University of Rome in 1974. She was with the Dipartimento di Informatica e Sistemistica ofthe University of Rome from 1976 to 1979. She is currently a senior researcher at the Istituto di Analisi dei Sistemi ed Informatica del Consiglio Nazionale delle Ricerche. Her main research interest is in the design and analysis of sequential and parallel algorithms for different classes of problems (graph problems, geometric problems). She is also working on design methodologies for systolic architectures. SILVIO SALZA received the Ph.D. degree in electrical engineering from the University of Rome in 1972. He is a senior researcher at the Istituto di Analisi dei Sistemi ed Informatica de1 Consigho Nazionale delle Ricerche, where he has been since 1974. In 1979 he visited the IBM T. J. Watson Research Center in Yorktown Heights, New York, for one year. His main research interests are in the design and evaluation of parallel architectures and algorithms. Currently he is also working on performance models of database systems with a particular emphasis on specialized architectures for database processing. CONCETTINA GUERRA received the Ph.D. degree in mathematics from the University of Naples in 1972. She is currently an associate professor in the Department of Mathematics at the University of Rome, on leave from the Department of Computer Science of Purdue University where she has been an assistant professor since 1984. In 1983 she was a visiting scientist of the Department ofcomputer Science at Carnegie-Mellon University. Her research interests include parallel computation, computer vision, and image processing.