You are on page 1of 10

Worst-Case Optimal Algorithms For Constructing Visibility Polygons With Holes

Subhash Suri Joseph 0 'Roerke

Department of Electrical Engineering & Computer Science The Johns Hopkins University Baltimore, MD 21218

1, I n t r o d u e t l o n EIGindy and Avis [EA] considered the problem of determining the visibility polygon from a point inside a polygon. Their algorithm runs in optimal O(n ) time and space, where n is the number of the vertices of the given polygon. Later their result was generalized to visibility polygons from an edge by EIGindy [Eli, and Lee and Lin ILLI. Both independently discovered O(nlogn) algorithms for this problem. Very recently Guibas e|. ai. the

Throughout the paper, we consider the slightly more general problem of computing visibility polygons in presence of a set of line segments S ~ (sl, a~ ........ s~ ) instead of a polygon with holes, where two line segments st, s j E $ do not intersect except perhaps at their endpoints. Our results hold for this problem as well. Notice that in this more general setting "visibility polygons" may be unbounded regions. Our paper is organized as follows. Section 2 presents the algorithm for point visibility polygon, and a proof of the lower bound. Worst-case lower bounds for computing the visibility polygon from a line segment are established in Section 3. Section 4 presents algorithms for various visibility problems from a line segment. Finally, Section {~ concludes with a discussion of several related results. 2. T h e g e n e r a l P o i n t Visibility P r o b l e m In this section, we outline an algorithm to compute a point visibility polygon amidst line segments in time O(nlogn), and prove this to be optimal in the worst case. The basic idea behind the algorithm is as follows. Let z be the point from which the visibility polygon is to be computed, and d be any half-ray with z as an endpoint. Let st, s ~ .... , s t be an ordered list of segments of $ intersecting d such that if s/ intersects d at zj then, in the ordered list, i < j 2>

[GH] have

proposed an optimal 0 ( n ) time algorithm.

None of these algorithms work for polygons with holes. In this paper we consider the problem of computing visibility polygon.q inside a polygon P that may have holes. Our first result is an algorithm for computing the visibility polygon from a given point inside P . The algorithm runs in 0 (nlogn) time, which is proved to be optimal by reduction from the problem of sorting n positive integers (Aaano st. al, [AA] have obtained this result independently). Next we consider the problem of determining the visibility polygon from a line segment. As our main result, we establish a worst-ease lower bound of N(n 4) for explicitly computing the boundary of the visibility polygon from a line segment in the presence of other line segments, and design an optimal algorithm to construct the boundary. We also present an 0 (n 2) time and space algorithm if the visibility polygon can be represented as a union of several polygons. The latter algorithm is also proved to be optimal in the worst case.

l<_i,j<_k, where I zzi [ denotes the distance from z to z i. Clearly, ex


[zzs I <

I zzj ],

Permission to copy without fee all or part of this material is granted provided that the copies are not made or distributed for direct commercial advantage, the ACM copyright notice and the title of the publication and its date appear, and notice is given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific permission.

is on the boundary of V (z). The algorithm rotates the half-ray d around z and outputs the sequence of segments that intersect d first. The algorithm is, roughly speaking, an angular plane sweep, and can be implemented in time O (niogn) in a straightforward manner. The optimality of the algorithm is established by the fol-

1986 ACM 0-89791-194-6/86/0600/0014

$00.75 14

lowing construction. We prove an fi(nl0gn ) lower bound on the computation of point visibility inside a polygon with holes by reduction from the problem of sorting n integers,

V(e).

We show two configurations of O ( n ) line seg-

ments that force fi(n 4) vertices on the boundary of V ( e ). Both configurations follow the same main idea: two rows of closely spaced collinear segments are placed parallel to e , one above the other. Imagine that e is a fluorescent tube of light. Then i2(n ) rays of light emerge from the gaps between the segments of first row, and fi(n2) rays emerge from the gaps of second row. These f~(n 'a) rays then intersect in fl(n 4) points in the region above the second row. We begin the description of these configurations by allowing point gaps between the segments so that the light emerges in "ideal" rays from the second row of gaps. Later in the section we enlarge the gaps so that the rays become finite conical beams, resulting in nondegenerate visibility polygons of C~(n4) vertices. first configuration, called the only The

(zl,z 2...... z~ ). Let zma z and zmi u be the largest and the
smallest numbers among z l , zs, ..... , z~, and let A__.~ z , n 4 f z ross. We create an instance of point visibility problem as follows. The outermost polygon is a rectangle whose vertices are located at ( z m i ~ l , - A / 2 ) , (zm,ffi+l, A/2) and ( z m i ~ l , A/2). zi, 1_~i _ n , tices (zm,f+l,-A/2), With each number

we associate a rectangular hole with ver-

(z,,-~), ( z i + c , - e ) , ( z i + e , e) sad (zi, e), where

e-----0.1, for example. Figure 1 illustrates the construction ror n = 4 .

/
I

A
/ /

Integer Configuration, uses


but requires a number-

/i / /

j, / //

/, 1 /

integer

coordinates,

///'
._I b,
x3

/ I

,;/-" .--,X2 xI

theoretical argument to establish the bound on number of distinct intersections. The second configuration, called the bound

.
x4

Rational Configuration, permits a more direct lowerproof, but uses rational coordinates. Both

configurations establish the same geometric fact, but their algorithmic implications depend on the precise model of computation. Despite this dependence, both lead to the same i2(n 4) lower bound on any algorithm for constructing V ( c ). 3.1: I n t e g e r C o n f i g u r a t i o n

Let the segment e have coordinates ((-n -1/2,0), (2n +1/2,0)} for its two endpoints. Our firstset of segments H lieson the line y = 1. Each seg-

Figure I: Lower bound proof for Point Visibility.


The point from which the visibility polygon is to be computed is set to be the lower left corner of the outer rectangle: z = ( z , ~ i ~ l , - A / 2 ) . fifth vertex of the boundary of It can be easily shown that the lower left corner of each hole occurs at every

ment h# is an open segment from ai to bs, where a i ----(i,1) and bi = ( i + l , 1) f o r 0 < i < n - 1 . Finally, two more open segments h_ I and h~ with the coordinates {(-n-I, 1), (0, 1)} and {(n, 1), (2n +1, 1)), respectively, are included. An identical set of segments

H' is constructed at the line y = 2. Finally, we enclose


this set of segments in a rectangular polygon P whose corners have the coordinates

V(z ) in order of increas-

ing values of z s 's. It is therefore easy to extract the sorted order of z , ' s from an algorithm that outputs the boundary of V ( z ) as a sorted list of vertices. Since sorting n integers is known to require rithm must spend 3. Worst-Case

{(-n -2, -1), (2n +2, -1), (2n +2, n +2), (-n -2, n +2)}.
N o w let S be the union of H , H', P and e.

i~(nlogn ) time in

the general algebraic decision tree model, any such algo-

Let gi (resp. g/') denote the point gap between two consecutive segments hi_I and h i (resp. hi'_ I and h i' ). Let G and

~(niogn ) time in the worst-case.


Lower Bounds For Visibility

G' denote the set of gaps for H and H' respectively. It should be clear that every pair of gaps
g i E G and gs' E G ' ,

Polygon F r o m A L i n e S e g m e n t
In this section, we establish a worst-case lower bound of 12(n 4) for constructing the visibility polygon from a given line segment e amidst n other line segments. We denote the visibility polygon from e by

O~i,j~_n, determines a maximal

line segment with one endpoint on e and the other on a side of P , and which does not intersect any other segment. We will call such a maximal line segment a "ray" (in slight abuse of standard terminology). There are

15

~(n ~) rays

altogether. Figure 2 shows the construction for n ----4; the outer polygon P is not shown. Let pt be the intersection of the half space // ~> 2 and the region bounded by P . It is clear that the visibility from c

q~
((-T - 3 , -1), (2n -I-3, -1), (2n + 3 , n ), ( - ~ --3, n

))

within P ' is restricted to rays only. Therefore, an intersection point of two rays in P ' is a vertex on the boundary of V(e ). If we can show that the t'~(n ~) rays intersect in ~(n4) distinct points in P ' , the bound will follow immediately. However, the intersection counting argument is a bit involved because many rays are parallel, and many intersection points have more than two rays passing through them. We will postpone this proof until Section 3.4, and proceed to describe another configuration for which a lower bound of t~(n 4) is more readily demonstrated. 3.2, R a t i o n a l C o n f i g u r a t i o n Our second configuration uses open segments of rational lengths. The main idea behind this construction is to arrange the gaps so that t'I(n 2) rays can be conceptually bundled into t~(n ) bundles, each containing t'~(n ) rays, such that t~(n ~) bundle-to-bundle intersections are all distinct, and each generates t~(n 2) distinct ray intersections. In this way, the problem of counting multiple intersections is avoided. We will first describe this configuration and then prove the lower bound of t'~(n 4) on the number of distinct intersection points. The segment e has endpoints (-~-I, 0),

Figure 3 shows this construction for n -----I0; only certain rays of interest are drawn to minimize cluttering. Using the notation introduced in Section 3.1, the set of gaps between the consecutive segments of H can be split into two sets G + and G.~ with G + having strictly positive X-coordinates for each gap. A gap g l E G + has X coordinate of the form n--~--~- , and a gap g i E G _ has X-coordinate of the from - ~ + n ; note that the point
n

(0, 1) is a gap in G~. The set of gaps for H ' consists of points whose X-coordinates have integer values between
n 0 and ~ - . We will call this set G' . For convenience, we

will refer to a gap by its X-coordinate whenever there is no possibility of confusion Let P ' be the intersection of the half space y >_ 2 and the region enclosed by P . It should be clear that the visibility from s in P ' is restricted to rays determined by two gaps, one in either G or G + and the other in G' . An intersection point of two rays is a vertex on the boundary of V(e ) Our primary concern now is to show that fl(n ~) rays constructed in this way intersect at f~(n 4) distinct points in pt. 3.3s Proof Of Lower Bound For Rational

Configuration In order to prove the bound on the number of intersections, we will consider only the region of pt that lies between two vertical lines CL and Cn , where C/, denotes the line z = 0, and CS denotes the line n z ~ ~ . We call this region P ' ' LetRs be the set of n all rays determined by gap i of G ' , 0 < i < ~ , and gap n n - - : of G ~ where i < j ~ n . Similarly, let L~ be the J set of all rays determined by gap i of G' , 1 < i < 2 '
n n n

(2n +I, 0). The first set of segments H is arranged along the line y ~ I, and is composed of two parts: one lying to the right of the origin, H, and the other lying to the left of the origin, H_. Each segment hl EH+ is an n open segment (a,, bs), where a~--~ ( n - - i - , 1) and n, bi = ( n - ~ - ~ 1), 0 < i < n Each segment hiGH_ is 1) and

n + ni an open segment (al, bi ), where al = ( - ~


n n

bi ---- (-~- + - ~ - ~ , 1), for l < i < n . H_ has two additional segments with coordinates { ( - ? and {(-2, 1), ( - 2 ' 1))

and gap - ~ +--rjof G_, -~ -i < j _< n. Note that these


definitions , 1), ( - ~ +1, 1)}, and H + has two segments with coordinates {(n-1, 1), (n, 1)~ and {(n, 1), (2n +2, 1)). The second set of segments H ' is arranged at y ~ 2, and consists of open segments
(a,,

imply that I R, [ = (n - i ), and 11 [Li I -~ ( ~ +i). Next we will show that if riER ~

(resp. rs ELi) and rj ERj (resp. rj ELi ), i ~ j , are two rays, then rs and rj do not intersect inside P " . If

~,),

0~ t < ~,

where

ai = (i, 2)

and

b, = ( i + l , 2). H'

is completed by adding two more 2), (0, 2))

i = j , then it is clear that r~ and rj intersect at the gap point (i, 2) only. Hence we will concentrate on the case i ~ j . We prove the claim for Ri; an identical reasoning works for Li.
n

open segments with coordinates { ( - ? - 2 ,

and {(2' 2), (2n +2, 2)}. Finally, this set is enclosed inside a rectangular polygon P with corners

L e m m a lz

Let rsER i and r j E R / , 1 ~ i ~ 3 < _ ~

, he

two rays. Then, r i and rj do not intersect each other

16

y=2 y=l 0
CL ]

4
CR

y=O
Figure ~: Integer Configuration for n =4.

y=2

y=l
5 \ @ 6.66
Figure 8: Rational Configuration for n -~I0.

C L I
A= y ~'X-A'-ymin,L - -J ~ ~ 1

CR

~
n n

Figure 4: Proof of Lemma 1.

E
0

n 2

17

inside P ' ' . Proof." First, note that P is chosen suitably tall to

r i EL i .

But this implies that the rays r i E R i and

r~ER l also intersect at z i = z i, which contradicts the claim of Lemmx I. Hence, there are C;(n 4) distinct intersection points between the f~(n 2) rays determined by the segments of our Rational Configuration. This completes our discussion on the Rational Configuration. &4s Proof Of Lower Bound For Integer

ensure t h a t both r~ and r i intersect C/. inside P ' ' , say at #, and Pi respectively. Without loss of generality, we assume i < j and show that Pi < Pj. It suffices to prove the lemms for two consecutive indices, namely, i and j----i +1. Let ri max (rj n~a) be the ray of R i (R i ) with maximum (reap. minimum) slope as measured clockwise about i (reap. j ) . Let ri mix intersect C t at pi raM, and let r/nln intersect CL
ft

Configuration

We now show that, despite multiplicities, the


number of distinct intersections in the Integer Configuration is f/(n4). Let p be a point of intersection above p ----2 of at least three rays. Then p is the apex of at least two triangles based on the bottom row, as illustrated in Figure 5.

at

p ntu.

We show

that

y rnax = p/rain. It is clear that rl n~x is determined by gap i of G ' and gap n - - ~ - ~ - of G+, and rj ntn is deterand gap n of G ~ Figure 4

mined by gap j of G ' angles A A B D AE AB And,

illustrates this situation. By considering the similar triand A A E G , we obtain EG BD by

,i.e.,
considering

pjntn
pi n~u - I

n i +1 similar

(1)
triangles

the

A A ' B C and A A ' E F , we obtain


B

A' E

EF

A ' B =-ff~

Pi n=x , i . e . , -y i n -~ _ I

n-i+l i

n
=

2 )

"~-1(

It follows from (1) and (2) that p nffix= iljmln. Since any other ray of R, intersects CL below p UmX and any other ray of R i intersects C'~ above p1n/n, it follows that no ray of R, intersects with s ray of R j in

i
i

-\

P' '.

Q.E.D. Figure 5: Counting intersections. A similar reasoning holds for L. 's. The locations Let b i u d o I be the widths of the left triangle at the

of the gaps were chosen specifically to ensure t h a t yinmx _ pjn/n. Now we can establish a lower bound on the number of distinct intersections between L i ' s and R j ' s in P ' ' . Every ray in L i intersects with every ray

bottom and top rows respectively, and let b I and a I be the corresponding widths for the triangle t h a t includes the left triangle; again see Figure 5. Then we must have
b~
U2

of

R), i < j < g

(see Fig. 3). Since I L, I = ('~ + i)

bI -~-or b ~ =
U 1

bin 2
al

Since a p a ~ b x , b ~ are all

and

I Ri I - - - - ( n - j ) , the lower bound on number of

intersections is
--.a_ 1 2

integers, a I must divide blu ~. Suppose first that a 1 and b l are relatively prime. Then ax must divide aw and the larger triangle is just an integer multiple scale

s(n)=

,~tlL,
-I 2 B

I'(IR,+ll
. n -I i

+ IR,+tl + . . . I R , / ~ - l l )

version of the smaller. Suppose second that a i and b x are not relatively prime. Let a 1----ca l' with a t' and b l' relatively and b l = cb t' , prime. Then divides a ~ Let

= ,~,(T +' )'i ~+, (" -.I ),


which is ~(n4).

(3)
b2~

b l ~ a2 which implies that a~' al I ,

a ~ = d a zI . Substitution yields b ~ d b

l: Thus a i and

It is easy to show that all intersection points reported in (3) are distinct. For a contra~liction assume that two intersection points :~x and =2 are the same, where z i is the intersection of rays r IER, and r i' GLj and ~ is the intersection point of rays r ~ R l and

b ~ are not relatively prime. Thus both triangles are integer multiple scale versions of yet a smaller triangle of widthsul' and b ~ .

18

The conclusion of this analysis is that all multiple intersections can he obtained as scale multiples of a leftmost, thinnest triangle with relatively prime a and b widths: leftmost because we are treating the scaling as expanding towards the right, and thinnest in that a and b are relatively prime. Thus the number of distinct intersections is equal to the number of leftmoet, thinnest triangles. We now proceed to count these triangles. Let a triangle he determined by a left line through (b 1,1) and (a 1,2) on the bottom and top rows, and a right line through (b2,1) and (a~,2), and let

( 3 n2CX+ o (1))----- nCn 2) (see ICrl, PP- 108). This


s~/4 easily implies that b ~ / 4 ~ ( b )~f~(ne). Using these summation limits, and replacing rain (b, n -b ) and (n -b ) in equation (4) hy their lower bounds of -~- yields
n .

s(n) > ()() ~/4


Therefore $ ( n ) = f ~ ( n 4).

s~/4

~(b) = ~(n4).

This concludes our discussion of the Integer Configuration. We now modify the open segments used in the above two constructions to closed segments, and obtain non-degenerate V(c)'s with the same lower bounds. This requires computing a sufficiently small rational number e such that modifying the point gaps of our original constructions into e-gaps, which enlarges the rays to beams, does not merge distinct intersection points. It is shown in the full version of this paper that a bound of e<O(n-X4) suffices for the integer configuration, and e < O ( n "el) suffices for the rational conguration. The implication is that the coordinates need only polynomial accuracy as a function of n . The main result of this section can be summarized as follows. T h e o r e m 1: There exist configurations of n line seg-

b ~ b ~ - b 1 and a--a~-a t [note the notation here is


different from above]. Let n be the number of gaps in each row, numbered from 1 to n . The number of choices for each of these quantities is as follows: b: b may t~ke any value from 2 to n . b -~I cannot result in an intersection above y -~2.
b I may range from 1 to n - b .
/

b t:

We will partition

this range from 1 to rain(b, n-b ), and the remainder. b2: a: b~is fixed at bt+b once b is set. If a > b, then the triangle does not result in an intersection point above #----2; thus
a <b.

Moreover, a must be relatively prime to b, otherwise the triangle is not thinnest. al: a I can range from 1 to n - 1 when b l < b , angle would not be leftmcet. When b t < b hut (and

only from 1 to a when b 1~ b, otherwise the trinote that mln ( b, n -b ) <_ b ), the situation is simpler; we will partition this range into two parts, from I to n - b , and the remainder. a2: a~-~ a t + a cannot be greater than n , and since a < b , it must be less than al+b. Within the range a t ~ l , . . . , n - b , the latter limit applies, and in the remainder the former limit~gpplies. To simplify the calculations, we will ignore the ranges of b I and a I that interact with the boundaries of the rows. Thus b t will range from 1 to rain ( b, n-b ) and a t will range from 1 to n - b . Therefore the quantity we obtain, S (n), is s lower hound on the number of leftmost and thinnest triangles. Concatenating the four choices above yields the following formula~

ments and a specified segment v such that the visibility polygon V(e ) has f~(n ) vertices on its boundary. Although the lower bound configurations described in Sections 3.1 and 3.2 establish that V ( e ) contains fi(n ) edges on its boundary, many of them are collinear. Therefore, fi(n 4) computation may not be required if the boundary need not be reported explicitly. However, in both the configurations there are f~(n 2) distinct rays that lie along the boundary of V(e ). Consequently, any algorithm designed to compute V(c ) must consider each of these fl(n ~) rays. T h e o r e m 2: Any algorithm that computes the region of the plane visible from g specified segment e in the presence of n other line segments must spend fi(n 2) time in the worst case. 4. A l g o r i t h m s for Vlslbility P o l y g o n F r o m A Line Segment Let S -----(st, s ~ ...... an, ab) be the given set of

S(n) =

~. rain (b, n-b ) ~(b ) (n-b)

(4)

where ~ b ) is the number of numbers lees than b and relatively prime to b . We now show that this sum is
Jt

segments, where the visibility polygon is to be computed from ab. Let P ~- (vl, v~ ...... vN, a, b) be the set of endpoints of segments of S, where N ~ 2 n . We a~ume that no three points of P are collinear. The visibility polygon from ab is denoted by V(ab ).

n(. 4).
It is known that tE ~b )

19

Our algorithm uses the straight line visibility graph G between the endpoints of segments in S as the underlying data structure. The vertex set of G is P , and two vertices vl and v/ are connected by an edge if segment vl v) does not intersect any segment of S. The following lemma shows that the edges of G when extended in both directions until they hit a segment of S are sufficient to construct VIab ). We omit the simple proof of this lemma. L e m m a 2: of P. Let z be a point on the boundary of

Algorithm-A: Trianoulor Reoions Of VisibiLity From ab


1. I'or each vertex v EP 2. 3. 4. 5.
6.

do begin

Let L ( v ) = ( e 1, e 2...... et ); { e i = z, z / , z, Ea6 } for i = 1 t o k do b e g l n if z i is closer to v than v~ t h e n If v# lies to the right of e, t h e n


Zi+l

7.
8. 9.
10.

*-- ei+lNSi ; pt Output the triangle Az,' vzi+ x

i r

else %i ~'- segment with ui as an endpoint;


tt

V (ab). Then z lies on a line determined by two vertices


11. Consider extending each edge of G at both ends until it hits a segment of S. For an edge v, vj, let s i and o~ be the segments hit, respectively, at zl and z j , where z, is closer to u, than uj. A segment at co is implicitly assumed to ensure that each edge of G when extended intersects with segments of S . Let E v be the set of all edges of G extended with one endpoint on ob. Ifv, E{a, b } then the segment vi vi is extended only in one direction, i.e., vi-v j. Now, we can formally state a corollary of L e m m a 2. Corollary 1: The set of edges E -~ E v U S sufficesfor 12. 13. 14. 15.
16,

Xi.p1
else

ei.t.lASvi;

Output the triangle LXv,vz,+'1 ;


if vi lies to the left of el t h e n
sp Zi+ 1 t *'ei+lr'l# i ; s t

Output the triangle ASs' vzi+ ] ;


e n d {for i = 1 to k }

17. e n d {for each vertex} We now proceed to prove the correctness of

Algorithm-A. Consider rotating each edge ei about v


counterclockwise. If the rotation is realizable such that ei maintains its contacts both with ab and 8i, the entire region swept by e, during the rotg.tion must be visible from ab. Since we consider rotating the edge ej about the vertex v, it does not m~tter on which side of ei the segment containing v lies. Therefore there are only four cases to be considered depending upon the locations of v and v. along the segment ei. Figures 6a through 6c illustrate the three cases handled respectively by lines 5, g and 13 of AIgorlthm-A. The fourth case shown in Fig. 6d does not give rise to a visible triangle and the algorithm treats it correctly by not producing the corresponding triangle, Notice t h a t the cases involving v E { a , b } or v, E{o, b } nre hnndled correctly by the algorithm. This argument establishes the following claim-. Lemms $: A triangular region output by

computing the boundary of the polygon V(ab ). Throughout the remaining discussion,we consider the extended visibilitygraph Go, whose edge set is E v and whose vertex set consists of the endpoints of edges i n E v. Let L (v ) be the list of O ( N ) e d g e s o f E v t h a t pass through v, sorted around v counterclockwise. Let L ( v ) = (e x, e 2..... , st). The edge e~ is-determined by the vertices v and v,, and its two endpoints are denoted by z, and z i' respectively, where one endpoint z i lies on ob and the other endpoint zi' to z/. If an edge e, E L I v ) lies on a segment can be rotated si' E S . We assume that the edge e, is directed from z~ infinitesimally counterclockwise about ~ while maintaining its contact with ob and si, we output a triangular region bounded by e~, e~+~ and s~. This triangle is con~idered "rooted" at v. A simple argument will show that this triangle is entirely visible from a~. In addition, we show that the union of all such triangular regions is, in fact, V (oh). We defer the proof of these claims, s.nd proceed with the description of an algorithm for onstructi~:g these triangular regions.

Algorithm-.4 is entirely visible from ab.


With the aid of Lemma 3, we can now show that the union of all triangles output by Algorithm-A is in fnct

v(ob ).

- L e r n m s 4s Let T i ~ U ~ . i / , where ~ i i is a triangle


J

rooted
t

a t ~iEP U T , ffi Vlob). Proof:

output

by A ~ o d l h m - A .

Then,

20

x
I

_Si

Xi+l Vi

Si+I

~
,v \ \

/.
+1
o
I

/i"'
x+
I

(6b)

b
Si

,~-----( I ) \ \ _ b
I

Xil

Xi

--

//

xi

~'~

12)"~..:, v
i/V'
~

"/

,-,"/--triangle output

previously
v

(8c)
r 0

, ,"

/
,

./.." \'\ " k \,___


"~vi \ ( I ) ~ \
k \ b O xi b
(6d)

Figure 6: Proof of Correctness for Algorithm -B.

(i) ii) iii)

Triangles output in Fig. 6a, 6b and 6c are shown shaded. The counterclockwise rotation may be blocked by a vertex either in position (1) or (2). A counterclockwise rotation is impossible in Fig. 6d. SX .
l

Sx
- -

Xl
"1"

I t t

,
t

i
'
t

x~/
i\/
Z2 _i. iII
~
v

, t

il '| Y Yl
Figure 7:

i .=
v

b
4.

Yl

Proof of L e m m a

z must lie in the visibility triangle rooted at z I with one side coilinear with ZlZ 2.

21

L e m m a 5z G, can be computed in

O(n 2)

time and

space. Follows immediately from Lemma 3. Combining Theorem 2 with Lemmas 4 and 5, we obtain the following result. claim by contradiction.
!

[.iT, ___ V(ab ):


i

We

prove the

Let

z6V(ub)beany

point such that x ~ L I T ' " L e t y 6 a b

T h e o r e m 4z The visibility polygon V(ub ) can be computed in O(n ~) time if output as a union of 0 ( , s) triangular regions. This time complexity is optimal in the worst-case. Next we consider the problem of computing the boundary of the visibility polygon 4.2.

be any point that is visible from z . Imagine "swinging~ the segment zy counterclockwise about z until it hits some vertex

zlEP.

Let y,Eab and ZlESffi be the two

points at which segment z 1z extended in both directions intersects the segments of $ , where sz E S . Now, consider rotating the segment y ,z 1 clockwise about z 1 such that YlZl maintains its contact with ab and 8,. Let zs be the first vertex of P contacted by this rotating segment z~y,. There are two cases to be considered, depending upon the relative positions of z~ and zs (see Fig. 7). Notice that the case z , 6 { a , b } is possible and does not require separate treatment. It is easily seen that in either case z lies in the triangle rooted at z~ with one side collinear with the segment z ,zs. But since this triangle belongs to ~..JT,, the assumption that z ~ ~.JT, is contradicted.

V(ab ). V(ab )

Computing the boundary of

We show that V(ab ) can be output as a polygon in O(nSlogn +k) time and O ( n 2 + k) space, where

Q.E.D..

k = O (n4). W e already have the region visiblefrom ub in the form of 0 (n 2) trianglesoutput by Algorithm-A, and we want to determine the boundary of this region. W e make use of a data structure introduced by Chazelle, called a hammock [Ch], to compute Ml the intersections of the 0 (n s) triangles output by Algorithm-A. Since each triangle is bounded by three segments, the number of intersections is 0 (n4). W e set up the planar graph induced by these triangles,and then traverse the faces of the graph to decide whether a face is visiblefrom ab or is a hole in the visibilitypolygon V(ab). The idea is very similar to that used by McKenna for hidden surface removal [M]. The details are given in the full version of this paper [SO]. The conclusion is the following theorem.
T h e o r e m Sz The boundary of V(ab ) can be computed in O(n2logn +k) time and O(n2+k) space, where k = O (n4). The time and space complexity are optimal in the worst-case.

4.1. T i m e C o m p l e x i t y o f A i g o r l t h m o A For a vertex v, 6 P , the number of visibility edges incident on it are at most 0 (N)=O(n). The size of EL (vi ) is, therefore, O (n 2). Since Algorithm-A visits each vertex once, and considers each edge incident on it at most once, the worst-case time taken by

Algorithm-A

is

O(nS).

Hence, we only have to show can be computed in O ( n 2)

that L ( v i ) for each vi E P

time. We observe that a minor modification of W e h r s algorithm [We] suffices for our purpose. Wehl maintains a data structure R that maps each vertex 5. Discussion Several other related visibility problems can also be solved in worst-case near optimal time by using the triangular regions of visibility output by Algorithm-A. Given a polygon with holes and an edge source of light, we can report all connected pieces of the boundary that are illuminated. We intersect 0 ( , s) triangles output by

vi to an

edge

s,, where ei is the first edge intersected by a half-ray starting from vi in the current direction d (of angular sweep). R is updated each time the direction d coincides with one of the (5) directions determined by vertices of P . Let v / v / be a visibility edge. Let the direct be dj. Let R i be the state of Let v~ map extended must Then vj vj
r

AIoorithm-.4

with the boundary to obtain illuminated

tion determined by vj vj

the data structure when direction is d/. onto the segment s/ in R / .

segments. Sorting these segments along the boundary sutfices to compute the illuminated maximal connected pieces of the boundary in total 0 (n21ogn) time. This is nearly optimal since there can be t~(, 2) disjoint pieces; an edge of the polygon aligned with line the Rational Configuration illuminated segments. has

intersect, s i first, say at z / . The other segment intersected by vi ,J/ extended, say s / zj z / at z / , is determined We by R when d has advanced by 1800 . The segment is the extended edge determined by v / v / . summarize in a lemma.

CL

or CR in disjoint

f/(n 2)

22

Similarly, given a point zEs, with si specified, we can locate a point y on the illuminating edge that is visible from ~ in O(loon) time after an O(n2ioon) time and 0 (n ~) space preprocessing. The results of this paper are summarized in the following table.

Japan 113 (1985). ILL] D. T. Lee and A. Lin. "Computing Visibility Polygon from an Edge," Technical Report, Department of Electrical Engineering and Computer Science, Northwestern University, (Jan. 1084). [MI M. McKenna. *'Worst-Case Optimal Hidden Surface Removal", Technical Report, The Johns Hopkins University, (March, 1986). S. Suri and J. O'Rourke. "Worst-Cage Optimal Algorithms For Constructing Visibility Polygons With Holes," Technical Report, The Johns Hopkins University, (August 1985).

Problem Point visibility Edge visib, w. boundary Edge visib, w/o. boundary Visible parts of segments Aeknowledgements

Lower Bound

Algorithm

fl(nlogn )
fI(n 4) fI(n ~)

0 (nloen )
0 (n 4) O (n 2)

ISO]

fi(n ~)

0 (n ~logn )

It is a pleasure to thank Michael McKenna for useful suggestions. The research for this paper was partially supported by NSF grant DCR-83-51468, and grants from Martin-Marietta, GM, and IBM.
6. References

[We] Emo Welzh "Constructing The Visibility Graph For n Line Segments In O (n 2) Time," Information Processino Letters, Volume 20, Number 4, 10 May, 1985.

IAA] T. Asano, T. Asano, L. Guibas, J. Hershberger H. Imai. "Visibility Polygon Search and Euclidean Shortest Paths," Pro. ~Oth FOCS, 1985, pp. 1~5-164. [Ch] B. Chazelle, "Intersecting Is Easier Than Sorti n g , ~ 16 t~ $TOC (1984), pp. 125,134.

[CG] B. Chazelle and L. J. Guibas. "Visibility and Intersection Problems in Plane Geometry," Sympo#ium o n Computational Geometry, pp. 135-146 (1985).

lEAI H. El Gindy and D. Avis. "A Linear Algorithm for Computing the Visibility Polygon from a Point, ~ Journal of Algorithms, ~, pp. 186-197 (1981). JEll H. El Gindy. "An Efficient Algorithm for Computing the Weak Visibility Polygon from an Edge in Simple Polygons,~ Technical Report, School of Computer Science, McGill University, (Jan. 1984). E. Grceswald. Topics From The Theory Of Numbers, Macmillan, New York, 1966.

[Gr]

[GH[ L. Guibas, J. Hersberger, D. Leven, M. Sharir, R. Tarjan, "Linear Time Algorithms for Visibility and Shortest Path Problems inside Simple Polygons," these Proceedings, June 1988. [IA] H. Imai, T. Asano & T. Asano. "Visibility of Disjoint Polygons," Technical Report, Dept. of Math. Engineering and Instrumentation Physics, Faculty of Enginnering, University of Tokyo, Tokyo,

23

You might also like