This page intentionally left blank
iii
VISIBILITY ALGORITHMS IN THE PLANE
A human observer can effortlessly identif...
279 downloads
1137 Views
2MB Size
Report
This content was uploaded by our users and we assume good faith they have the permission to share this book. If you own the copyright to this book and it is wrongfully on our website, we offer a simple DMCA procedure to remove your content from our site. Start by pressing the button below!
Report copyright / DMCA form
This page intentionally left blank
iii
VISIBILITY ALGORITHMS IN THE PLANE
A human observer can effortlessly identify visible portions of geometric objects present in the environment. However, computations of visible portions of objects from a viewpoint involving thousands of objects is a time-consuming task even for high-speed computers. To solve such visibility problems, efficient algorithms have been designed. This book presents some of these visibility algorithms in two dimensions. Specifically, basic algorithms for point visibility, weak visibility, shortest paths, visibility graphs, link paths, and visibility queries are all discussed. Several geometric properties are also established through lemmas and theorems. With over 300 figures and hundreds of exercises, this book is ideal for graduate students and researchers in the field of computational geometry. It will also be useful as a reference for researchers working in algorithms, robotics, computer graphics, and geometric graph theory, and some algorithms from the book can be used in a first course in computational geometry. S u b i r K u m a r G h o s h is a professor of computer science at the Tata Institute of Fundamental Research, Mumbai, India and is a fellow of the Indian Academy of Sciences. He is the author of around 40 papers in the fields of computational geometry and graph theory and has worked as a visiting scientist in many reputed universities and research institutes around the world.
i
iii
VISIBILITY ALGORITHMS IN THE PLANE SUBIR KUMAR GHOSH School of Computer Science, Tata Institute of Fundamental Research, Mumbai 400005, India
iii
CAMBRIDGE UNIVERSITY PRESS
Cambridge, New York, Melbourne, Madrid, Cape Town, Singapore, São Paulo Cambridge University Press The Edinburgh Building, Cambridge CB2 8RU, UK Published in the United States of America by Cambridge University Press, New York www.cambridge.org Information on this title: www.cambridge.org/9780521875745 © S. K. Ghosh 2007 This publication is in copyright. Subject to statutory exception and to the provision of relevant collective licensing agreements, no reproduction of any part may take place without the written permission of Cambridge University Press. First published in print format 2007 eBook (NetLibrary) ISBN-13 978-0-511-28472-4 ISBN-10 0-511-28626-0 eBook (NetLibrary) ISBN-13 ISBN-10
hardback 978-0-521-87574-5 hardback 0-521-87574-9
Cambridge University Press has no responsibility for the persistence or accuracy of urls for external or third-party internet websites referred to in this publication, and does not guarantee that any content on such websites is, or will remain, accurate or appropriate.
Dedicated to my loving parents
Contents
page xi
Preface 1
2
3
Background
1
1.1
Notion of Visibility
1
1.2
Polygon
2
1.3
Asymptotic Complexity
5
1.4
Triangulation
6
1.5
The Art Gallery Problem
8
1.6
Special Types of Visibility
11
Point Visibility
13
2.1
Problems and Results
13
2.2
Computing Visibility of a Point in Simple Polygons
16
2.2.1
Non-Winding Polygon: O(n) Algorithm
16
2.2.2
Removing Winding: O(n) Algorithm
23
2.3
Computing Visibility of a Point in Polygons with Holes
31
2.4
Recognizing Simple Polygons Visible from a Point
38
2.5
Notes and Comments
43
Weak Visibility and Shortest Paths
46
3.1
Problems and Results
46
3.2
Characterizing Weak Visibility
51
3.3
Computing Weak Visibility in Simple Polygons
58
3.3.1
Scanning the Boundary: O(n log n) Algorithm
58
3.3.2
Using Shortest Path Trees: O(n) Algorithm
65
vii
viii
Contents
3.4
Computing Weak Visibility in Polygons with Holes
66
3.5
Recognizing Weakly Internal Visible Polygons
68
3.5.1
Using Visibility Graph: O(E) Algorithm
68
3.5.2
Scanning the Boundary: O(n) Algorithm
73
3.6
4
5
82
3.6.1
In Simple Polygons: O(n) Algorithm
82
3.6.2
In Weak Visibility Polygons: O(n) Algorithm
87
3.7
Recognizing Weakly External Visible Polygons
3.8
Notes and Comments
95 102
LR-Visibility and Shortest Paths
105
4.1
Problems and Results
105
4.2
Characterizing LR-Visibility
108
4.3
Computing LR-Visibility Polygons
110
4.4
Recognizing LR-Visibility Polygons
113
4.5
Walking in an LR-Visibility Polygon
115
4.6
Computing Shortest Path Trees using LR-Visibility
124
4.7
Notes and Comments
135
Visibility Graphs
136
5.1
Problems and Results
136
5.2
Computing Visibility Graphs of Simple Polygons
138
5.3
Computing Visibility Graphs of Polygons with Holes
143
5.4
5.5 6
Computing Shortest Path Trees
5.3.1
Worst-Case: O(n2 ) Algorithm
143
5.3.2
Output-Sensitive: O(n log n + E) Algorithm
146
Computing Tangent Visibility Graphs
161
5.4.1
Convex Holes: O(n + h2 log h) Algorithm
161
5.4.2
Non-Convex Holes: O(n + h2 log h) Algorithm
165
Notes and Comments
169
Visibility Graph Theory
171
6.1
Problems and Results
171
6.2
Recognizing Visibility Graphs of Simple Polygons
174
6.2.1
174
Necessary Conditions
Contents
6.2.2
7
180
6.3
Characterizing Visibility Graphs of Simple Polygons
183
6.4
Recognizing Special Classes of Visibility Graphs
187
6.4.1
Spiral Polygons: O(n) Algorithm
187
6.4.2
Tower Polygons: O(n) Algorithm
195
6.5
Characterizing a Sub-Class of Segment Visibility Graphs
201
6.6
A Few Properties of Vertex-Edge Visibility Graphs
205
6.7
Computing Maximum Clique in a Visibility Graph
208
6.8
Computing Maximum Hidden Vertex Set in a Visibility Graph
214
6.9
Notes and Comments
216
Visibility and Link Paths
218
7.1
Problems and Results
218
7.2
Computing Minimum Link Paths in Simple Polygons
221
7.2.1
Using Weak Visibility: O(n) Algorithm
221
7.2.2
Using Complete Visibility: O(n) Algorithm
224
7.3
Computing Minimum Link Paths in Polygons with Holes
231
7.4
Computing Link Center and Radius of Simple Polygons
238
7.5
Computing Minimum Nested Polygons
242
7.5.1
Between Convex Polygons: O(n log k) Algorithm
242
7.5.2
Between Non-Convex Polygons: O(n) Algorithm
248
7.6 8
Testing Necessary Conditions: O(n2 ) Algorithm
ix
Notes and Comments
253
Visibility and Path Queries
255
8.1
Problems and Results
255
8.2
Ray-Shooting Queries in Simple Polygons
259
8.3
Visibility Polygon Queries for Points in Polygons
267
8.3.1
Without Holes: O(log n + k) Query Algorithm
267
8.3.2
With Holes: O(n) Query Algorithm
272
Path Queries Between Points in Simple Polygons
278
8.4.1
Shortest Paths: O(log n + k) Query Algorithm
278
8.4.2
Link Paths: O(log n + k) Query Algorithm
289
8.4
8.5
Notes and Comments
292
x
Contents
Bibliography
295
Index
311
Preface
Education is the manifestation of the perfection already in man.
Swami Vivekananda (1863–1902)
This book is entirely devoted to the area of visibility algorithms in computational geometry and covers basic algorithms for visibility problems in two dimensions. It is intended primarily for graduate students and researchers in the field of computational geometry. It will also be useful as a reference/text for researchers working in algorithms, robotics, graphics and geometric graph theory. The area of visibility algorithms started as a sub-area of computational geometry in the late 1970s. Many researchers have contributed significantly to this area in the last three decades and helped this area to mature considerably. The time has come to document the important algorithms in this area in a text book. Although some of the existing books in computational geometry have covered a few visibility algorithms, this book provides detailed algorithms for several important visibility problems. Hence, this book should not be viewed as another book on computational geometry but complementary to the existing books. In some published papers, visibility algorithms are presented first and then the correctness arguments are given, based on geometric properties. While presenting an algorithm in this book, the geometric properties are first established through lemmas and theorems, and then the algorithm is derived from them. My experience indicates that this style of presentation generally helps a reader in getting a better grasp of the fundamentals of the algorithms. Moreover, this style has also helped in refining several visibility algorithms, which is a significant contribution of this book. In keeping with the distinctive approach of this book, all the algorithms herein have been explained using this approach.
xi
xii
Preface
Structure of the book The book consists of eight chapters. The first chapter provides the background material for visibility, polygons and algorithms. Each chapter from 2 to 8 deals with a specific theme of visibility. In the first section (i.e., Problems and Results) of these chapters, results on visibility problems under the theme of the chapter are reviewed. In each intermediate section of a chapter, one or two algorithms are presented in detail or some properties of visibility are proved. Sometimes, two algorithms for the same problem are presented to show the improvement in time complexity or that the different approaches lead to the same time complexity. Two algorithms for two different types of polygons are also presented for the same problem. In the last section (i.e., Notes and Comments) of every chapter from 2 to 8, results on parallel or on-line algorithms for the problems considered in the chapter are mentioned. In the same section, some visibility issues connected to the theme of the chapter are discussed. Exercises in the book are placed at suitable positions within a section to allow a reader to solve them while reading that section. This process of solving exercises will help in gaining a better understanding of the current topic of discussion. Prerequisites Some time back, I offered a graduate course in the Tata Institute of Fundamental Research entitled ‘Algorithmic Visibility in the Plane’ using a preliminary version of this manuscript. After every lecture, an appropriate section was given to each student for reading. In the next lecture, I asked them to explain the algorithms contained in that section. It was very satisfying to see that these students, who did not have any background in computational geometry prior to my course, had comprehensively followed the algorithms. However, the students had prior knowledge of algorithms and data structures. Courses on algorithms and data structures are essential prerequisites for understanding this book. As stated earlier, this book is not meant as a first course in computational geometry. However, some algorithms herein can certainly be included in such a course in computational geometry. Moreover, this book can be used for assigning research projects to students. In addition, this book can be a natural choice for graduate-level seminar courses.
Preface
xiii
Acknowledgments Over the last 5 years, many people have helped me in various ways in preparing this book. Partha Pratim Goswami and Sudebkumar Prasant Pal read the entire manuscript and have suggested several corrections and revisions. Amitava Bhattacharya and Tilikepalli Kavitha made suggestions for improving the presentation of the book. Discussions on the contents of the book with Binay Bhattacharya, Anil Maheshwari and Thomas Shermer in the initial phase helped me to organize the book in a better way. Discussions with Arnab Basu helped me to structure many sentences in a more meaningful way. My students helped me by identifying some typographical errors. I sincerely thank all of them. I would also like to thank John Barretto, Vivek Borkar, Raymond D’Mello, Daya Gaur, Nitin Gawandi, Ramesh Krishnamurti, Saswata Shannigrahi, Subhas Nandy, Paritosh Pandya, Sugata Sanyal, Sudeep Sarkar and Aniruddha Sen for their help during different phases in preparing the book. I take this opportunity to sincerely thank David Tranah of Cambridge University Press for his constant positive initiative for the publication of this manuscript. Finally, I gratefully acknowledge the constant support that my wife Sumana and son Rajarshi provided me with during the entire period of 5 years. Subir Kumar Ghosh Mumbai, India
1 Background
1.1 Notion of Visibility
Visibility is a natural phenomenon in everyday life. We see objects around us and then decide our movement accordingly. Seeing an object means identifying the portions of the object visible from the current position of an observer. The entire object may not be visible as some of its parts may be hidden from the observer. The observer also determines shapes and sizes of visible portions of an object. Visible portions of an object change as the observer moves from one position to another. Moreover, the observer may see several objects in different directions from its current position; the visible portions of these objects form the scene around the observer. Constructing such a scene continuously is very natural for a human observer as the human visual system can execute such tasks effortlessly. Suppose a robot wants to move from a starting position to a target position without colliding with any object or obstacle around it. The robot constructs the scene around itself from its current position and then guides its motion in the free space lying between itself and the visible portion of the objects around it. The positions of the robot and the objects can be represented in the computer of the robot by their x, y and z co-ordinates and therefore, the scene consisting of visible portions of these objects can be computed for the current position of the robot. The problem of computing visible portions of given objects from a viewpoint has been studied extensively in computer graphics [115]. Since the scene is constructed from thousands of objects of different shapes and sizes lying in different positions, it becomes a complex task from a computational point of view. Even computing visible portions of one object in the presence of several other objects is a non-trivial task. Moreover, computing such a scene for every position on the path of the robot is a time-consuming task even for high-speed computers. Designing efficient algorithms for executing such movements of a robot in the presence of obstacles in a reasonable period of time is one of the objectives in the field of robot path planning [226]. 1
2
Background
The above problem of robot path planning can be reduced to the corresponding problem in two dimensions. If a mobile robot that maintains contact with the floor is projected on the floor, the two-dimensional footprint of the robot can be modeled as a polygon. Similar projections on the floor can now also be produced for all obstacles. This process yields a map consisting of polygons in two dimensions. The polygon corresponding to the robot can be navigated using this map by avoiding collisions with polygonal obstacles. Thus a collision-free path of the robot can be computed from its starting position to the target position. While navigating, the visible portions of polygonal obstacles are computed to construct the scene around the current position of the robot. Although such a representation in two dimensions has reduced the complexity of the robot path planning problem, designing efficient algorithms for such computations remains a challenging task. The notion of visibility has also been used extensively in the context of the art gallery problem in computational geometry [271, 310, 333]. The art gallery problem is to determine the number of guards that are sufficient to see every point in the interior of an art gallery room. This means that every interior point of the room must be visible to one of the guards so that all paintings in the gallery remain guarded. There are many theorems and algorithms for the minimization of the number of guards and their placement in the art gallery room. The study of visibility started way back in 1913 when Brunn [67] proved a theorem regarding the kernel of a set. Today visibility is used in many fields of computer science including robotics [66, 226, 249, 283], computer vision [139, 168] and computer graphics [93, 113, 115].
1.2 Polygon A polygon P is defined as a closed region R in the plane bounded by a finite set of line segments (called edges of P ) such that there exists a path between any two points of R which does not intersect any edge of P . Any endpoint of an edge of P is called a vertex of P , which is a point in the plane. Since P is a closed and bounded region, the boundary of P consists of cycles of edges of P , where two consecutive edges in a cycle share a vertex. If the boundary of P consists of two or more cycles, then P is called a polygon with holes (see Figure 1.1(a)). Otherwise, P is called a simple polygon or a polygon without holes (see Figure 1.1(b)). The region R is called the internal region or interior of P . Similarly, the regions of the plane excluding all points of R are called the external regions or exterior of P . A vertex of P is called convex if the interior angle at the vertex formed by two edges of that vertex is at most π; otherwise it is called reflex. Note that the interior angle at a vertex always faces the interior of P . As defined above, a simple polygon P is a region of the plane bounded by a cycle of edges such that any pair of non-consecutive edges do not intersect. In this book,
1.2 Polygon
3
Figure 1.1 (a) In this polygon with holes, b and c are visible from a but not d. (b) In this simple polygon (or a polygon without holes), b and c are visible from a, but not d.
we assume that P is given as a doubly linked list of vertices. Each vertex has two fields containing x and y co-ordinates of the vertex and it has two pointers pointing to the next clockwise and counterclockwise vertices of P . It can be seen that if edges of P are traversed in counterclockwise (or clockwise) order, then the interior of P always lies to the left (respectively, right) of the edges of P . Let c0 , c1 , c2 , . . . , ch be the cycles on the boundary of a polygon P with h holes, where c0 represents the outer boundary of P . Let Rj denote the region of the plane enclosed by cj for all j ≤ h (see Figure 1.1(a)). Since P is a closed and bounded region, Rj ⊂ R0 for all j > 0. Moreover, Rj ∩ Rk = ∅ where k 6= j and k > 0. Therefore, R = R0 − (R1 ∪ R2 ∪ . . . ∪ Rh ). Observe that if P is a simple polygon, then R = R0 as the boundary of P consists of only one cycle c0 (see Figure 1.1(b)). In this book, we assume that a polygon P with h holes is given in the form of h cycles, where vertices of each cycle are stored in a doubly linked list as stated above and there is an additional pointer to one vertex of each cycle of P to access that cycle. Two points p and q in P are said to be visible if the line segment joining p and q contains no point on the exterior of P . This means that the segment pq lies totally inside P . This definition allows the segment pq to pass through a reflex vertex or graze along a polygonal edge. We also say that p sees q if p and q are visible in P . It is obvious that if p sees q, q also sees p. So, we sometime say that p and q are mutually visible. In Figure 1.1, the point a sees two points b and c, but not the point d. Exercise 1.2.1 Given two points p and q inside a polygon P , design a method to determine whether p and q are visible in P . Suppose a set of line segments in the plane is given such that they do not form a polygon. Let A denote the arrangement of these line segments in the plane (see
4
Background
Figure 1.2 (a) In this arrangement of line segments A, points b and c are visible from a but not d. (b) A convex polygon P where any two points are mutually visible. (c) A star-shaped polygon P where the entire polygon is visible from any point of the kernel K.
Figure 1.2(a)). Two points p and q in the plane are said to be visible in the presence of A if the line segment joining p and q does not cross any line segment in A. This definition permits the segment pq to touch a line segment of A. In Figure 1.2, a point a sees two points b and c, but not the point d. Using the definition of visibility in a polygon, we define two special classes of simple polygons called convex and star-shaped polygons. A simple polygon P is called convex if every pair of points in P is mutually visible [176] (see Figure 1.2(b)). It can be seen that the internal angle at every vertex of a convex polygon is at most π [327]. A convex polygon can also be defined as intersections of closed half-planes which is bounded. A simple polygon P is said to be star-shaped if there exists a point z inside P such that all points of P are visible from z (see Figure 1.2(c)). The set of all such points z of P is called the kernel of P . The kernel of P is always convex [67]. If P is a star-shaped polygon with respect to a point z, it can be seen that the order of vertices on the boundary of P is same as the angular order of vertices around z. We refer to this property by saying that the vertices of P are in sorted angular order around z. It follows from the theorem of Krasnosel’skii [223] that a simple polygon P is star-shaped if and only if every triple of convex vertices is visible from some point of P [334]. Note that a convex polygon is also a star-shaped polygon and all points of the convex polygon belong to the kernel. Exercise 1.2.2 Prove that a polygon P is star-shaped if and only if every triple of convex vertices is visible from some point of P [223].
Exercise 1.2.3 Prove that the kernel of a star-shaped polygon is convex.
1.3 Asymptotic Complexity
5
Exercise 1.2.4 Draw two star-shaped polygons A and B such that each edge of A intersects every edge of B [291].
1.3 Asymptotic Complexity The time and space complexity of the sequential algorithms presented in this book are measured using the standard notation O(f (n)), where n is the size of the input to the algorithm. The notation O(f (n)) denotes the set of all functions g(n) such that there exist positive constants c and n0 with |g(n)| ≤ c|f (n)| for all n ≥ n0 . We say that an algorithm runs in polynomial time if the running time of the algorithm is O(nk ) for some constant k. The notation Ω(f (n)) denotes the set of all functions g(n) such that there exist positive constants c and n0 with g(n) ≥ cf (n) for all n ≥ n0 .
The idea of evaluating asymptotic efficiency of an algorithm is to know how the running time (or space) of the algorithm increases with the size of the input. The running time expressed using O notation gives a simple characterization of the efficiency of the algorithm, which in turn allows us to compare the efficiency of one algorithm with another. For more discussion on asymptotic efficiency of algorithms, see the book by Cormen et al. [96].
The real RAM (Random Access Machine) has become the standard model of computation for sequential algorithms in computational geometry. As stated in [291], the real RAM is a random access machine with infinite precision and real number arithmetic. The real RAM can be used to perform addition, subtraction, multiplication, division and comparisons on real numbers in unit time. In addition, various other operations such as indirect addressing of memory (integer address only), computing the intersection of two lines, computing the distance between two points, testing whether a vertex is convex are also available. These operations are assumed to take constant time for execution. For more details of these operations, see O’Rourke [272]. Exercise 1.3.1 Is O(2n ) = O(2O(n) )? Exercise 1.3.2 Given a point z and a polygon P , design an O(n) time algorithm to test whether z lies in the interior of P [291]. All parallel algorithms mentioned in this book (at the end of chapters) are designed for the Parallel Random Access Machine (PRAM) model of computations [35, 172, 211]. This can be viewed as the parallel analog of the sequential RAM. A PRAM consists of several independent sequential processors, each with its own private memory, communicating with one another through a global memory. In one unit
6
Background
of time, each processor can read one global or local memory location. PRAMs can be classified according to restrictions on global memory access. An Exclusive-Read Exclusive-Write (or EREW) PRAM is a PRAM for which simultaneous access to any memory location by different processors is forbidden for both reading and writing. In Concurrent-Read Exclusive-Write (or CREW) PRAM, simultaneous reads are allowed but not simultaneous writes. A Concurrent-Read Concurrent-Write (or CRCW) PRAM allows simultaneous reads and writes. PRAM models of computation allow for infinite precision real arithmetic, with all simple unary and binary operations being computable in O(1) time by a single processor. We say that a parallel algorithm in the PRAM model of computations runs in polylogarithmic time if it runs in O(log k n) time using O(nm ) processors, where k and m are constants and n is the size of the input to the algorithm. A problem is said to be in the class N C if it can be solved in polylogarithmic time using a polynomial number of processors. A parallel algorithm is called optimal if the product of the running time of a parallel algorithm and the number of processors used by the parallel algorithm is within a constant factor of the best sequential algorithm for the same problem.
1.4 Triangulation In this section, we provide a brief overview of the results on triangulation of a polygon as there are visibility algorithms that depend on a first stage of computing a triangulation of the input polygon. A triangulation of a polygon P is a partition of P into triangles by diagonals (see Figure 1.3), where a line segment joining any two mutually visible vertices of P is called a diagonal of P [242]. Note that if a line segment joining two vertices u and v of P passes through another vertex w of P and the segment uv lies inside P , then uw and vw are diagonals and not uv. Exercise 1.4.1 Prove that every simple polygon admits triangulation [272]. Exercise 1.4.2 Using the proof of Exercise 1.4.1, design an O(n2 ) time algorithm for triangulating a simple polygon of n vertices [272]. It can be seen that a triangulation of P is not unique as many subsets of diagonals give triangulations of the same polygon. The dual of a triangulation of P is a graph where every triangle is represented as a node of the graph and two nodes are connected by an arc in the graph if and only if their corresponding triangles share a diagonal (see Figure 1.3). Since there are three sides of a triangle, the degree of every node in the dual graph is at most three. A graph with no cycle is called a tree. In the following lemmas, we state some of the properties of triangulations of P.
1.4 Triangulation
7
Figure 1.3 (a) A triangulation of a polygon with holes and its dual graph. (b) A triangulation of a simple polygon and its dual tree.
Lemma 1.4.1 Every triangulation of a simple polygon of n vertices uses n − 3 diagonals and has n − 2 triangles. Corollary 1.4.2 The sum of the internal angles of a simple polygon of n vertices is (n − 2)π. Lemma 1.4.3 Every triangulation of a polygon with h holes with a total of n vertices uses n + 3h − 3 diagonals and has n + 2h − 2 triangles. Lemma 1.4.4 The dual graph of a triangulation of a simple polygon is a tree. Lemma 1.4.5 The dual graph of a triangulation of a polygon with holes must have a cycle. Exercise 1.4.3 Prove that there is no cycle in the dual graph of a triangulation of a simple polygon. Exercise 1.4.4 Let a graph G of m vertices denote the dual of a triangulation of a polygon with holes. Design an O(m) time algorithm to locate a cycle in G. The first O(n log n) time algorithm for triangulating a simple polygon P was given by Garey et al. [148]. The first step of their algorithm is to partition P into y-monotone polygons. A simple polygon is called y-monotone if its boundary can be divided into two chains of vertices such that each chain has vertices with increasing y-coordinates. The partition of P into y-monotone polygons can be done in O(n log n) time by the algorithm of Lee and Preparata [233] for locating a point in a given set of regions. It has been shown by Garey et al. that each y-monotone polygon can be triangulated in a time that is proportional to the number of vertices
8
Background
of the y-monotone polygon. So, the overall time complexity of the algorithm for triangulating P is O(n log n). This algorithm also works for polygons with holes, as pointed out by Asano et al. [29], and it is optimal for this class of polygons. Another O(n log n) time algorithm for triangulating a simple polygon was presented by Mehlhorn [257] and uses the plane sweep technique. This algorithm was generalized for a polygon with holes by Ghosh and Mount [165] with the same time complexity (see Section 5.3.2). Later, Bar-Yehuda and Chazelle [43] gave an O(n + h log1+² h), ² > 0 time algorithm for triangulating a polygon with h holes with a total of n vertices. Many researchers worked for more than a decade on the problem of triangulating a simple polygon P in less than O(n log n) time. One approach was to consider special classes of simple polygons that could be triangulated in O(n) time [48, 131, 142, 162, 183, 239, 280, 331, 342]. Another approach was to find algorithms whose running time was based on structural properties of simple polygons [78, 193]. Tarjan and Van Wyk [326] were the first to establish an improvement by proposing an O(n log log n) time algorithm for this problem. Later, a simpler O(n log log n) time algorithm was presented by Kirkpatrick et al. [217]. Finally, an O(n) time optimal algorithm for this problem was presented by Chazelle [71] settling this long-standing open problem. We have the following theorem. Theorem 1.4.6 A simple polygon P of n vertices can be triangulated in O(n) time. The algorithm of Chazelle [71] uses involved tools and notions such as a planar separator theorem, polygon cutting theorem and conformality. Although this algorithm does not use any complex data structure, it is conceptually difficult and too complex to be considered practical. Moreover, although it has been used as a preprocessing step for many of the visibility algorithms presented in this book, the development of a simple O(n) time algorithm for triangulating a simple polygon remains an open problem.
1.5 The Art Gallery Problem As stated in Section 1.1, the art gallery problem is to determine the number of guards that are sufficient to see every point in the interior of an art gallery room. The art gallery can be viewed as a polygon P of n vertices and the guards are stationary points in P . A point z ∈ P is visible from a guard g if the line segment zg lies inside P . If guards are placed at vertices of P , they are called vertex guards. If guards are placed at any point of P , they are called point guards. Since guards placed at points or vertices are stationary, they are referred as stationary guards. If guards are mobile along a segment inside P , they are referred as mobile guards. If mobile guards move along edges of P , they are referred as edge guards.
1.5 The Art Gallery Problem
9
Exercise 1.5.1 Draw a simple polygon of 3k vertices for k > 1 showing that k stationary guards are necessary to see the entire polygon [91].
In a conference in 1976, V. Klee first posed the art gallery problem (see [198]). Chav´atal [91] showed that for a simple polygon P , bn/3c stationary guards are always sufficient and occasionally necessary to see or guard the entire P . Later, Fisk [141] gave a simple proof for this bound. Using this proof, Avis and Toussaint [41] designed an O(n log n) time algorithm for positioning guards at vertices of P . For mobile guards, O’Rourke [270] showed that bn/4c mobile guards are always sufficient and occasionally necessary. For edge guards, bn/4c edge guards appear to be sufficient, except for some types of polygons (see [333]). Exercise 1.5.2 Let P be a triangulated simple polygon of n vertices. Design an O(n) time algorithm for positioning at most bn/3c stationary guards at vertices of P such the entire P is visible for these guards [41, 141]. A polygon is said to be rectilinear if its edges are aligned with a pair of orthogonal coordinate axes. For a simple rectilinear polygon P where edges of P are horizontal or vertical, Kahn et al. [207] showed that bn/4c stationary guards are always sufficient and occasionally necessary to guard P . An alternative proof for this bound was given later by O’Rourke [269]. These proofs first partition P into convex quadrilaterals and then bn/4c guards are placed in P . A convex quadrilaterization of P can be obtained by using the algorithms of Edelsbrunner et al. [121], Lubiw [250], Sack [299] and Sack and Toussaint [301]. For mobile guards in rectilinear polygons P , Aggarwal [11] proved that b(3n + 4)/16c mobile guards are always sufficient and occasionally necessary to guard P . Bjorling-Sachs [55] showed later that this bound also holds for edge guards in rectilinear polygons. Exercise 1.5.3 Let P be a triangulated simple polygon of n vertices. Design an O(n) time algorithm for partitioning P into convex quadrilaterals [250, 301].
For a polygon P with h holes, O’Rourke [271] showed that P can always be guarded by at most b(n + 2h)/3c vertex guards. For point guards, Hoffmann et al. [194] and Bjorling-Sachs and Souvaine [56] proved independently that d(n+h)/3e point guards are always sufficient and occasionally necessary to guard P . Bjorling-Sachs and Souvaine also presented an O(n2 ) time algorithm for positioning guards in P . No tight bound is known on the number of mobile guards sufficient
10
Background
for guarding P . However, since d(n + h)/3e point guards are sufficient for guarding P , the bound obviously holds for mobile guards. For an rectilinear polygon P with h holes, Gy¨ori et al. [182] showed that b(3n + 4h + 4)/16c mobile guards are always sufficient and occasionally necessary for guarding P . For more details on art gallery theorems and algorithms, see O’Rourke [271], Shermer [310] and Urrutia [333]. We do not cover this subfield of visibility in this book. The minimum guard problem is to locate the minimum number of guards for guarding a polygon with or without holes. O’Rourke and Supowit [276] proved that the minimum point, vertex and edge guard problems are NP-hard in polygons with holes. Even for simple polygons, these problems are NP-hard as shown by Lee and Lin [231]. There are approximation algorithms for these NP-hard problems. Ghosh [152] presented approximation algorithms for minimum vertex and edge guard problems for polygons P with or without holes. The approximation algorithms run in O(n5 log n) time and yield solutions that can be at most O(log n) times the optimal solution. This means that the approximation ratio of these algorithms is O(log n). These algorithms partition the polygonal region into convex pieces and construct sets consisting of these convex pieces. Then the algorithms use an approximation algorithm for the minimum set-covering problem on these constructed sets to compute the solution for the minimum vertex and edge guard problems in P . Recently, Ghosh [158] has improved the running time of these approximation algorithms by improving the upper bound on the number of convex pieces in P . After improvement, the approximation algorithms run in O(n4 ) time for simple polygons and O(n5 ) time for polygons with holes. Efrat and Har-Peled [122] also gave approximation algorithms for the minimum vertex guard problem in polygons with or without holes. Let copt denote the number of vertices in the optimal solution. Their approximation algorithm for simple polygons runs in O(nc2opt log4 n) time and the approximation ratio is O(log copt ). Their other approximation algorithm is for polygons with holes, which runs in O(nhc3opt polylog n) time, where h is the number of holes in the polygon. The approximation ratio is O(log n log(copt log n)). For the minimum point guard problem in simple polygons, they gave an exact algorithm which runs in O((ncopt )3(copt +1) ) time. Observe that in the worst case, copt can be a fraction of n. So, the approximation ratio of approximation algorithms of Ghosh [152, 158] and Efrat and Har-Peled [122] is O(log n) in the worst case. On the other hand, Eidenbenz [123, 124] showed that the problems of minimum vertex, point and edge guards in simple polygons are APX-hard. This implies that there exists a constant ² > 0 such that no polynomial time approximation algorithm for these problems can guarantee an approximation ratio of 1 + ² unless P = N P .
1.6 Special Types of Visibility
11
Figure 1.4 (a) The points u and v are clearly visible in P but u and w are not. (b) Points u and v are staircase visible in P . The point w is not staircase visible in P from u or v.
1.6 Special Types of Visibility In this section, we mention some variations of visibility studied by researchers in the field of visibility. Breen [62, 63] introduced clear visibility, which is perhaps the smallest variation of standard visibility possible. Two points u and v in a polygon P are called clearly visible if the open line segment joining u and v lies in the interior of P . Note that clear visibility does not permit the line of sight to touch the boundary of P (see Figure 1.4(a)). Let us consider staircase visibility between points in rectilinear polygons. This type of visibility has been studied by Culberson and Reckhow [99], Motwani et al. [263, 264], Reckhow and Culberson [296], Schiuerer and Wood [305] and Wood and Yamamoto [343]. If a path inside a rectilinear polygon P is monotone with respect to both axes, the path is called staircase path in P . Two points u and v in P are called staircase visible if there is a staircase path between u and v in P (see Figure 1.4(b)). Note that if two points u and v of P are visible under the standard definition of visibility, u and v are also staircase visible. Staircase visibility has been generalized to O-visibility, where O represents a set of two or more orientations between 0◦ and 180◦ . If a path inside a rectilinear polygon P is monotone with respect to every direction in O, the path is called O-staircase path in P . Two points u and v in P are called O-visible if there is an O-staircase path between u and v in P . This type of visibility has been studied by Bremner [64], Bremner and Shermer [65], Rawlins [294], Rawlins and Wood [295], Schuierer et al. [304] and Schiuerer and Wood [305]. Fink and Wood [140] have studied O-visibility in connection with convexity. Like staircase visibility, rectangular visibility is generally used for points inside rectilinear polygons. If the sides of a rectangle are parallel to the axes, the rectangle is called aligned. For any two points u and v in a rectilinear polygon P , if the
12
Background
Figure 1.5 (a) The points u and v are rectangularly visible in P but u and w are not. (b) The points u and v are circularly visible in P .
aligned rectangle with u and v as opposite corners lies totally inside P , then u and v are called rectangularly visible (see Figure 1.5(a)). Rectangular visibility has been studied by Gewali [149], Gewali et al. [150], Keil [214], Munro et al. [265] and Overmars and Wood [279]. Circular visibility, another variation of visibility, has been studied by Agarwal and Sharir [8, 9], Chou and Woo [90] and Garcia-Lopez and Ramos-Alonso [147]. If two points u and v in a polygon P can be connected by a circular arc such that the circular arc lies totally inside P , then u and v are called circularly visible (see Figure 1.5(b)). Dean et al. [110] have studied X-ray visibility, which is another variation of visibility. Two points u and v are X-ray visible in a polygon P if the segment uv does intersect more than a fixed number of edges of P .
2 Point Visibility
2.1 Problems and Results Determining the visible region of a geometric object from a given source under various constraints is a well-studied problem in computational geometry [30]. The visibility polygon V (q) of a point q in a simple polygon P is the set of all points of P that are visible from q. In other words, V (q) = {p ∈ P | q sees p}. A similar definition holds in a polygon with holes or an arrangement of segments. The problem of computing the visibility polygon V (q) of a point q is related to hidden line elimination problem and it is a part of the rendering process in computer graphics [115]. Figure 2.1 shows V (q) in a simple polygon, a polygon with holes, and a line segment arrangement. By definition, any V (q) is a star-shaped polygon and q belongs to the kernel of P . The visibility polygon of a point in a line segment arrangement may not be always bounded. Let ab be an edge on the boundary of V (q) such that (i) no point of ab, except the points a and b, belong to the boundary of P , (ii) three points q, a and b are
Figure 2.1 The visibility polygons of q (a) in a simple polygon, (b) in a polygon with holes, and (c) in a line segment arrangement.
13
14
Point Visibility
Figure 2.2 The revolution number of P with respect to q in (a) is two and in (b) is one.
collinear, and (iii) a or b is a vertex of P . Such an edge ab is called a constructed edge of V (q). It can be seen that once constructed edges of V (q) are known, the boundary of V (q) can be constructed by adding the boundary of P between two consecutive constructed edges. Since each constructed edge can be computed in O(n) time (see Exercise 2.1.1), a naive algorithm for computing V (q) takes O(n 2 ) time. Exercise 2.1.1 For each vertex vi of a given polygon P (with or without holes), determine whether vi is visible from q in O(n) time and if vi is visible from q, compute the constructed edge at vi (if it exists) in O(n) time. This problem for a simple polygon was first considered in a theoretical framework by Davis and Benedikt [107], who presented an O(n2 ) time algorithm. Then, ElGindy and Avis [128] and Lee [230] presented O(n) time algorithms for this problem. In Section 2.2.1, we present Lee’s algorithm. It has been shown in Joe [204] and Joe and Simpson [205] that both algorithms of ElGindy and Avis, and Lee may fail on some polygons with sufficient winding, i.e., if the revolution number is at least two (see Figure 2.2(a)). For a simple polygon P and a point z ∈ P , the revolution number of P with respect to z is the number of revolutions that the boundary of P makes about z. If the revolution number of P with respect to z is one (see Figure 2.2(b)), P is called a non-winding polygon. Joe and Simpson [205] suggested an O(n) time algorithm for computing V (q) which correctly handles winding in the polygon by keeping the count of the number of revolutions around q. Exercise 2.1.2 Given a point z inside or outside a simple polygon P of n vertices, design an O(n) algorithm for computing the revolution number of P with respect to z.
2.1 Problems and Results
15
Observe that the portion of the boundary of the given simple polygon P , that makes the revolution number of P with respect to q more than one, is not visible from q. So, it is better to prune P before using the algorithm of ElGindy and Avis or Lee so that (i) the revolution number of the pruned polygon of P with respect to q is one, and (ii) the pruned polygon of P contains q and V (q). In Section 2.2.2, we present the algorithm of Bhattacharya et al. [49] for pruning P that runs in linear time. This algorithm removes winding by locating a subset of Jordon sequence that is in the proper order and uses only one stack like the algorithm of Lee [230]. So, the algorithm of Bhattacharya et al. [49] can be viewed as a preprocessing step before V (q) is computed by Lee’s algorithm. For a polygon with h holes with a total of n vertices, Asano [27] presented O(n log h) algorithms for computing V (q) (see Figure 2.1(b)). Around the same time, Suri and O’Rourke [321] and Asano et al. [28] proposed O(n log n) time algorithms for this problem. Later, Heffernan and Mitchell [185] proposed an O(n + h log h) time algorithm for this problem. We present the algorithm of Asano [27] in Section 2.3. Consider a simple polygon P such that the visibility polygon V (q) of P from some point q ∈ P is same as P , i.e., P = V (q). Then P is a star-shaped polygon and q belongs to the kernel of P . For definitions of a star-shaped polygon and its kernel, see Section 1.2. So, the problem of recognizing the point visibility polygon is to locate a point q ∈ P such that P = V (q). In other words, a point q ∈ P is to be located such that V (q) does not have any constructed edge. Lee and Preparata [234] solved the recognition problem by presenting an O(n) time algorithm for computing the kernel of P . If the kernel of P is non-empty, then P is the visibility polygon of P from any point of the kernel. We present the algorithm of Lee and Preparata in Section 2.4.
Exercise 2.1.3 Let uv be an edge of a star-shaped polygon P , where v is a reflex vertex. Extend uv from v till it meets a point u0 on the boundary of P . Prove that all points of the kernel of P lies on the same side of vu 0 .
Exercise 2.1.4 Let ab and cd be two constructed edges of the visibility polygon V (q) of a point q inside a simple polygon P such that (i) a and d are reflex vertices of P , (ii) b and c are some points on the edges of P and (iii) the counterclockwise boundary from a to d passes through b and c. Prove that if there exists another such pair of constructed edges in V (q), then P is not a star-shaped polygon.
16
Point Visibility
Figure 2.3 (a) The point q lies outside the convex hull of P . (b) The point q lies outside P but inside the convex hull of P .
2.2 Computing Visibility of a Point in Simple Polygons 2.2.1 Non-Winding Polygon: O(n) Algorithm In this section, we present the algorithm of Lee [230] for computing the visibility polygon V (q) of a simple polygon P of n vertices from a point q in O(n) time. The first step of the algorithm is to determine whether q lies inside or outside P . If q lies outside P , a simple polygon P 0 is constructed from P such that q ∈ P 0 and V (q) ⊆ P 0 . Then, the procedure for computing the visibility polygon from an internal point can be used to compute V (q) in P 0 as q ∈ P 0 .
Let us explain the procedure for constructing P 0 from P when q lies outside P . There are two situations depending on whether q lies inside the convex hull of P (see Figure 2.3). The convex hull of P is the smallest convex polygon containing P and it can be computed in O(n) time by the algorithm of Graham and Yao [175]. If q lies outside the convex hull of P (see Figure 2.3(a)), draw two tangents (say, qvi and qvj ) from q to the convex hull of P . Let bd(P ) denote the boundary of P . Observe that all points of bd(P ) visible from q lie between vi and vj facing q. So, bd(P 0 ) consists of this part of bd(P ) between vi and vj and two tangents qvi and qvj . Now, q is an internal point of P 0 . Consider the other situation when q lies outside P but inside the convex hull of P (see Figure 2.3(b)). Draw a line from q passing →). Let q 0 be the closest point of q among through any vertex vk of P (denoted as − qv k → with bd(P ). Starting from q 0 , traverse bd(P ) in all points of intersections of − qv k clockwise (and in counterclockwise) order till a convex hull vertex vi (respectively, vj ) is reached. Note that vi and vj are consecutive vertices on the convex hull of P . So, bd(P 0 ) consists of bd(P ) between vi and vj containing q 0 , and the convex hull edge vi vj . Now, q is an internal point of P 0 .
2.2 Computing Visibility of a Point in Simple Polygons
17
Figure 2.4 (a) The vertex vi is pushed on the stack. (b) The vertices of bd(vi , vk−1 ) are not visible from q.
From now on, we consider that the given point q is an internal point of P . If the boundary of the given polygon P winds around q, the winding is removed from P by the algorithm in Section 2.2.2. Henceforth, we assume that bd(P ) does not wind around q. The problem is to compute V (q) of P from q. Exercise 2.2.1 Let pi = (xi , yi ), pj = (xj , yj ), and pk = (xk , yk ) be three points in the plane. Let S = xk (yi − yj ) + yk (xj − xi ) + yj xi − yi xj . Show → that (i) if S > 0 then pk lies to the left of − p− i pj , (ii) if S = 0 then pi , pj −− → and pk are collinear, and (iii) if S < 0 then pk lies to the right of p i pj . We know that V (q) is a star-shaped polygon, where q is a point in the kernel of V (q). Let v0 denote the closest point of q among the intersection points of bd(P ) with the horizontal line drawn from q to the right of q (see Figure 2.4(a)). We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order with v1 as the next counterclockwise vertex after v0 . So, v1 and vn lie to the left →0 , respectively. and right of − qv Assume that the procedure for computing V (q) has scanned bd(P ) in counterclockwise order from v1 to vi−1 and vi is the current vertex under consideration. The star-shaped polygon formed by the vertices and points on the stack at any stage along with q is referred to as the current visibility region Vc (q). Let bd(vj , vk ) denote the counterclockwise boundary of P from vj to vk . We also assume that vertices (and the endpoints of constructed edges) on bd(v0 , vi−1 ), which are found to be visible from q by the procedure, are pushed on a stack in the order they are encountered, where v0 and vi−1 are at the bottom and top of the stack, respectively. So, the vertices and points in the stack are in sorted angular order around q. The
18
Point Visibility
Figure 2.5 (a) The edge vi−1 vi intersects uq. (b) The edge vi−1 vi does not intersect uq.
procedure always ensures that the content of the stack satisfies this property at any stage of the execution. We have the following cases. −− → Case 1. The vertex vi lies to the left of − qv i−1 (Figure 2.4(a)). −−− → Case 2. The vertex vi lies to the right of qv i−1 (Figure 2.4(b) and Figure 2.5(a)). −−−→ Case 2a. The vertex vi lies to the right of v−− i−2 vi−1 (Figure 2.4(b)). −−−→ Case 2b. The vertex vi lies to the left of v−− i−2 vi−1 (Figure 2.5(a)). Consider Case 1. Since vi and the vertices and points in the stack are in sorted angular order with respect to q (see Figure 2.4(a)), vi is pushed on the stack. Consider Case 2. It can be seen that vi−1 and vi cannot both be visible from q (see Figure 2.4(b) and Figure 2.5(a)), as either qvi is intersected by bd(v0 , vi−1 ) (Case 2a) or qvi−1 is intersected by bd(vi+1 , vn ) (Case 2b). Consider Case 2a. The vertex vi and some of the subsequent vertices of vi (yet to be scanned) are not visible from q (see Figure 2.4(b)). Let vk−1 vk be the first edge from vi+1 on bd(vi+1 , vn ) in counterclockwise order such that vk−1 vk intersects −−− → −−−→ qv i−1 . Let z be the point of intersection. Note that vk lies to the left of qvi−1 as bd(P ) does not wind around q. So, no vertices of bd(vi , vk−1 ) are visible from q and therefore, z is the next point of vi−1 on bd(vi−1 vn ) visible from q. So, vi z is a constructed edge of V (q), where q, vi−1 and z are collinear points. Push z and vk on the stack, and vk+1 becomes the new vi . Consider Case 2b. The vertex vi−1 and some of the preceding vertices of vi (currently on the stack) are not visible from q (see Figure 2.5(a)). Pop the stack to remove vi . Let u denote the vertex on the top of the stack. The edge vi−1 vi is called a forward edge. While vi−1 vi intersects uq and u is a vertex of P , pop the stack.
2.2 Computing Visibility of a Point in Simple Polygons
19
Figure 2.6 (a) Backtracking ends by pushing m and vi on the stack. (b) Backtracking continues with vk−1 vk as the current forward edge.
Note that popped vertices are not visible from q as their visibility from q is blocked by vi−1 vi . After the execution of this step of backtracking, there are two situations that can arise: (i) vi−1 vi does not intersect uq (see Figure 2.5(b)), and (ii) vi−1 vi intersects uq (see Figure 2.7). In the first situation, the procedure decides whether further backtracking is →i (see Figure required (see Figure 2.5(b) and Figure 2.6). If vi+1 lies to the right of − qv 2.5(b)), backtracking continues with vi vi+1 as the current forward edge. Otherwise, →i (see Figure 2.6). Let m be the intersection point of − →i vi+1 lies to the left of − qv qv −−→ with the polygonal edge containing u. If vi+1 lies to the right of − vi−1 vi , then the backtracking ends (see Figure 2.6(a)). Push m and vi on the stack and vi+1 becomes −−→ the new vi . If vi+1 lies to the left of v−i−1 vi (see Figure 2.6(b)), scan bd(vi+1 , vn ) from vi+1 until a vertex vk is found such that the edge vk−1 vk intersects mvi . Backtracking continues with vk−1 vk as the current forward edge. In the second situation, u is not a vertex of P (see Figure 2.7). Let w be the vertex immediately below u on the stack. So, uw is a constructed edge computed earlier by the procedure in Case 2a. Let p be the point of intersection of uq and vi−1 vi . If p ∈ qw (see Figure 2.7(a)), the visibility of both u and w from q is blocked by vi−1 vi . Pop the stack. Backtracking continues and vi−1 vi remains the current forward edge. Otherwise, vi−1 vi has intersected uw as p belongs to uw (see Figure 2.7(b)). Scan bd(vi+1 , vn ) from vi+1 until a vertex vk is found such that the edge vk−1 vk has intersected wp at some point (say, z). So, the entire bd(w, z) (excluding w and z) is not visible from q. Pop the stack. Push z and vk on the stack. So, vk+1 becomes the new vi . Note that we have assumed uw is a constructed edge computed earlier in Case 2a. It may so happen that the constructed edge ending at u (say, uu0 ) has been computed in Case 2b at the end of an earlier backtracking
20
Point Visibility
Figure 2.7 (a) The edge vi−1 vi does not intersect the constructed edge uw. (b) The edge vi−1 vi intersects uw at p, and the edge vk−1 vk intersects pw at z.
phase. It means that the vertex u0 is the last vertex popped of the stack in the current backtracking phase. Therefore, q, w and u are not collinear. Hence, pop the stack and it becomes the first situation of the current backtracking. In the following steps, we formally present the algorithm for computing V (q). As before, we assume that v0 is the closest point of bd(P ) to the right of q, and the vertex v1 is the next counterclockwise vertex of v0 . Push v0 on the stack and initialize i by 1. Step 1. Push vi on the stack and i := i + 1. If i = n + 1 goto Step 8. −− → Step 2. If vi lies to the left of − qv i−1 (Figure 2.4(a)) then goto Step 1 (Case 1). −−− → −−−−−→ Step 3. If vi lies to the right of both qv i−1 and vi−2 vi−1 then (Case 2a) Step 3a. Scan from vi+1 in counterclockwise order until a vertex vk is found such −−− → that vk−1 vk intersects qv i−1 (Figure 2.4(b)). Let z be the point of intersection. Step 3b. Push z on the stack, i := k and goto Step 1. −− → −−−−−→ Step 4. If vi lies to the right of − qv i−1 and to the left of vi−2 vi−1 (Figure 2.5(a)) then (Case 2b)
Step 4a. Let u denote the element on the top of the stack. Pop the stack. Step 4b. While u is a vertex and vi−1 vi intersects uq, pop the stack (Figure 2.5(a)). Step 5. If vi−1 vi does not intersect uq (Figure 2.5(b)) then →i (Figure 2.5(b)) then i := i + 1 and goto Step Step 5a. If vi+1 lies to right of − qv 4b. →i and the edge containing u. If Step 5b. Let m be the point of intersection of − qv − − − → vi+1 lies to the right of vi−1 vi (Figure 2.6(a)) then push m on the stack and goto Step 1.
2.2 Computing Visibility of a Point in Simple Polygons
21
Step 5c. Scan from vi+1 in counterclockwise order until a vertex vk is found such that vk−1 vk intersects mvi (Figure 2.6(b)). Assign k to i and goto Step 4b. Step 6. Let w be the vertex immediately below u on the stack. Let p be the point of intersection between vi−1 vi and uq. If p ∈ qw (Figure 2.7(a)) or q, w and u are not collinear then pop the stack and goto Step 4b. Step 7. Scan from vi+1 in counterclockwise order until a vertex vk is found such that vk−1 vk intersects wp (Figure 2.7(b)). Push the intersection point on the stack, assign k to i and goto Step 1. Step 8. Output V (q) by popping all vertices and points on the stack and Stop. Let us discuss the correctness of the algorithm. As stated earlier, V (q) is a star-shaped polygon with its kernel containing q, i.e., vertices of V (q) are in sorted angular order with respect to q. The algorithm maintains an invariant that the vertices and points on the stack at any stage are in sorted angular order with respect to q. When the algorithm terminates, the current visibility region Vc (q) is V (q). The algorithm scans the vertices of P starting from v0 in counterclockwise order and checks in Step 2 whether the current vertex vi is in the sorted angular order with the vertices and points on the stack. If vi satisfies this property (see Figure −−− → 2.4(a)), it means that vi lies to the left of qv i−1 and vi is pushed on the stack. Since vi is pushed on the stack, the current region of V (q) is enhanced by the triangle formed by q, vi−1 and vi . If vi is not in sorted angular order, vi must lie to the right −− → of − qv i−1 . Moreover, vi may lie inside Vc (q). Consider the situation when vi lies outside Vc (q) and vi also lies to the right of −−− → qv i−1 . Observe that although vi lies outside Vc (q), the edge vi−1 vi may pass through Vc (q) (see Figure 2.7(b)). In the other situation, vi−1 vi does not pass through Vc (q) (see Figure 2.4(b)). Consider the later situation. Observe that qvi is intersected by bd(v0 , vi−1 ) and therefore, vi cannot be visible from q. Let vk−1 vk be the first edge in counterclockwise order starting from vi such that vk−1 vk intersects qvi−1 at some points (say, z). Since P is a closed and bounded region, such an edge vk−1 vk −−− → intersecting qv i−1 exists. Note that since P does not have winding by assumption, vk satisfies sorted angular order along with the vertices and points on the stack. So, the algorithm correctly locates such a vertex vk in Step 3, and Vc (q) is enhanced by the triangle formed by q, z and vk . If vi−1 vi passes through Vc (q) (see Figure 2.7(b)), it can be seen that vi−1 vi has intersected a constructed edge uw computed by the algorithm earlier, where w is a vertex of bd(v0 , vi−1 ). So, vi cannot be visible from q as bd(v0 , w) intersects qvi . Let p be the intersection point of vi−1 vi and uw. Let vk−1 vk be the first edge in counterclockwise order starting from vi such that vk−1 vk intersects pw at some point (say, z). Since P is a closed and bounded region, such an edge vk−1 vk exists. Observe that all points of bd(w, z) (excluding w and z) cannot be visible from q, and vk is in sorted angular order with the vertices and points of bd(v0 , w) on the stack. So,
22
Point Visibility
Figure 2.8 (a) Backtracking ends at vk . (b) The edges vj−1 vj and vk−1 vk are two consecutive forward edges on bd(vi−1 , vt ).
the algorithm correctly locates such a vertex vk in Step 7. Vc (q) is reduced triangle by triangle as vertices are popped off the stack till qw becomes a boundary edge of Vc (q), and then Vc (q) is enhanced by the triangle formed by q, z and vk (see Figure 2.7(b) and Figure 2.8(a)). Consider the other situation when vi lies inside Vc (q) (see Figure 2.5(a)). So, vi−1 vi blocks the visibility from q to some of the vertices and points currently on the stack. These vertices and points are popped off the stack in Step 4. While popping the stack, Vc (q) is also reduced triangle by triangle until vi no longer lies inside Vc (q) (see Figure 2.5(b)). The vertex vi is now in sorted angular order with the vertices and points on the stack. However, vi+1 may lie inside Vc (q) (see Figure 2.5(b)) (which is checked in Step 5a) and therefore, backtracking continues. So, Step 4b is again executed with vi vi+1 as the current forward edge. Observe that two consecutive forward edges may not always be two consecutive edges on bd(vi−1 , vn ). In Figure 2.8(b), vj−1 vj and vk−1 vk are two consecutive forward edges. It can happen when the next counterclockwise edge vj vj+1 of the current forward edge vj−1 vj does not lie inside Vc (q) but the visibility from q to vj+1 is blocked by forward edges on bd(vi−1 , vj ). Let vk−1 vk be the first edge in →j . Since counterclockwise order starting from vj+1 such that vk−1 vk intersects − qv P is a closed and bounded region, such an edge vk−1 vk exists and it becomes the current forward edge. So, the algorithm correctly locates the next forward edge in Step 5c. Backtracking finally ends in Step 5b when the visibility of the next counterclockwise edge (say, vt vt+1 ) of the current forward edge vt−1 vt from q is not blocked by any forward edge of bd(vi−1 , vt ) (see Figure 2.8(b)). So, vt+1 and vt are
2.2 Computing Visibility of a Point in Simple Polygons
23
Figure 2.9 Alternate segments w1 w2 , w3 w4 , w5 w6 and w7 w8 have divided P into subpolygons and the sub-polygon with w0 as a boundary point contains both q and V (q).
in sorted angular order with the vertices and points currently on the stack. V c (q) is first enhanced to vt and then to vt+1 . Finally, the algorithm reaches vn and it outputs Vc (q) in Step 8 as V (q). It can be seen that every vertex of P is considered once by the algorithm while scanning from v0 to vn . If any vertex vi is pushed on the stack, vi remains on the stack unless it is removed during backtracking. Once vi is removed of the stack, vi is not considered again by the algorithm. Hence, the overall time complexity of the algorithm is O(n). We state the result in the following theorem. Theorem 2.2.1 The visibility polygon V (q) of a given point q inside an n-sided simple polygon P can be computed in O(n) time. Exercise 2.2.2 Let q be a point inside a given triangulated simple polygon P . Design a procedure for computing the visibility polygon of q in P whose running time is proportional to the number of triangles, partially or totally visible from q, in the triangulation of P .
2.2.2 Removing Winding: O(n) Algorithm In this section, we present an O(n) time algorithm of Bhattacharya et al. [49] to remove the winding of a simple polygon P with respect to a given point q inside P . Given a simple polygon P and a point q ∈ P , the problem is to compute a simple polygon P1 ⊆ P (called a pruned polygon) such that P1 contains both V (q) and q, and the angle subtended at q is at most 2π while the boundary of P1 is scanned in clockwise or counterclockwise order (see Figure 2.9). This means that the revolution number of P1 with respect to q is one. We have the following lemma.
24
Point Visibility
Lemma 2.2.2 Draw the half-line from q to the right of q intersecting bd(P ) at points (w0 , w1 , ..., wk ) such that for all j, wj ∈ qwj+1 (Figure 2.9). Alternate segments w1 w2 , w3 w4 ,..., wk−1 wk lie inside P . Exercise 2.2.3 Prove Lemma 2.2.2. Partition P by adding segments w1 w2 , w3 w4 ,..., wk−1 wk to P . Since these segments lie inside P by Lemma 2.2.2, P splits into several parts and the part with w0 as a boundary point (say, P1 ) contains both q and V (q). Analogously, draw a horizontal line from q to the left of q and remove winding from P1 . Since the new P1 does not have winding with respect to q, the revolution number of the new P1 is one. We know that points w0 , w1 ,..., wk can be computed in O(n) time and then they can be sorted along the half-line in O(n log n) time. Using the property that w 0 , w1 ,..., wk belong to the boundary of simple polygon, which is a closed and bounded region, Hoffmann et al. [195] showed that the sorting of w0 , w1 ,..., wk along the half-line can be done in O(n) time. Hence, the pruned polygon P1 containing both q and V (q) can be computed in O(n) time. However, the algorithm of Hoffmann et al. [195] is difficult to implement as it uses involved data structures called level-linked search trees. Observe that the winding in the polygon P in Figure 2.9 can be removed by adding only the segments w1 w2 or w5 w6 . This suggests that the winding in P can be removed by adding a few selected segments. We show that these segments can be identified in O(n) time using only one stack without the sorting of all intersection points along the half-line as follows. Let L denote the horizontal line passing through q. The portion of L to the right (or left) of q is denoted as Lr (respectively, Ll ) (see Figure 2.10(a)). The closest point of q among the intersection points of bd(P ) with Lr (or Ll ) is denoted as qr (respectively, ql ). Since ql qr lies inside P , two sub-polygons Pa and Pb are constructed by adding the segment ql qr in P , where the boundary of Pa (or Pb ) consists of ql qr and the boundary of P from qr to ql in counterclockwise (respectively, clockwise) order. It can be seen that there are four types of sub-segments of L lying inside P formed by pairs of intersection points of bd(Pa ) or bd(Pb ) with Lr or Ll (see Figure 2.10(a)). The algorithm identifies some of these sub-segments and by adding these sub-segments to P , the winding of P is removed. Among these sub-segments, the sub-segments formed by the intersection of Lr with Pa is located by scanning bd(Pa ) from qr to ql in counterclockwise order; the procedure is called CC(Pa , qr , ql , Lr ). The remaining sub-segments on Lr or Ll are identified by analogous procedures C(Pa , ql , qr , Ll ), C(Pb , qr , ql , Lr ) and CC(Pb , ql , qr , Ll ). In Figure 2.10(a), sub-segments z1 z2 , z3 z4 , z7 z8 and z5 z6 are identified by CC(Pa , qr , ql , Lr ),
2.2 Computing Visibility of a Point in Simple Polygons
25
Figure 2.10 (a) Each procedure identifies one sub-segment on L. (b) Every pair of consecutive intersection points on Lr is of opposite type.
C(Pa , ql , qr , Ll ), C(Pb , qr , ql , Lr ) and CC(Pb , ql , qr , Ll ), respectively. Among these four procedures, only the procedure CC(Pa , qr , ql , Lr ) is presented here as other procedures are analogous. Let us present CC(Pa , qr , ql , Lr ). An intersection point z between bd(Pa ) and Lr is called a downward (respectively, upward) point if the next counterclockwise vertex of z on bd(Pa ) is below (or above) Lr . For example, qr is always an upward point. Two intersection points of bd(Pa ) and Lr are called same type if both of them are downward or upward points. Otherwise, they are opposite type. For example in Figure 2.10(a), z1 and z2 are downward and upward points, respectively, and therefore, (z1 , z2 ) is a pair of opposite type. In the following lemma, we present properties of pairs of intersection points between Lr and bd(Pa ). Lemma 2.2.3 Let w and z be two intersection points between Lr and bd(Pa ). (i) If w and z are of same type, wz does not lie inside Pa . (ii) If wz lies inside Pa , then w and z are of opposite type. (iii) If w is a downward point, z is upward point and wz lies inside Pa , then w lies on qz. (iv) If w is a downward point, z is an upward point and wz does not lie inside Pa , then wz contains a pair of opposite type. Exercise 2.2.4 Prove Lemma 2.2.3. The above lemma suggests that for locating sub-segments of Lr lying inside Pa , locate pairs of opposite type and then test whether a pair contains another pair of opposite type. Let Z = (z0 , z1 , ..., zm ) be the intersection points from qr to ql along bd(Pa ) in counterclockwise order, where qr = z0 (see Figure 2.10(b)). We say that (z0 , z1 , ..., zi−1 ) is in the proper order if for all k less than i − 1, zk ∈ qzk+1 and
26
Point Visibility
Figure 2.11 (a) The next pair is formed by zi and zk . (b) The next pair is formed by zi and zj .
(zk , zk+1 ) is a pair of opposite type. Observe that if there is no winding in Pa , all points in Z are in the proper order and therefore, segments connecting alternate pairs of points in Z lie inside Pa . We have the following properties on the proper order. Lemma 2.2.4 Assume that (z0 , z1 , ..., zi−1 ) is in the proper order. (i) If zi preserves the proper order, then zi ∈ / qzi−1 and (zi−1 , zi ) is a pair of opposite type. (ii) If zi violates the proper order, then zi ∈ qzi−1 or (zi−1 , zi ) is a pair of same type. (iii) If there is a point zj ∈ zk zk+1 , where k < i − 1 and j > i − 1, then zj is a subsequent point of zi−1 in Z. Assume that CC(Pa , qr , ql , Lr ) has tested points z0 , z1 , ..., zi−1 and they are in the proper order (see Figure 2.10(b)). This means that z0 is an upward point, z1 is a downward point, z2 is a upward point and so on. We know that z0 z1 , z2 z3 , . . . , zi−3 zi−2 do not lie inside Pa . We assume that (z1 , z2 ), (z3 , z4 ), . . . , (zi−2 , zi−1 ) are pushed on the stack by the procedure with (zi−2 , zi−1 ) on top of the stack. Note that zi−1 is an upward intersection point by assumption. The procedure checks whether (z0 , z1 , ..., zi−1 , zi ) is in proper order. We have the following four cases depending upon the type and position of zi . Case Case Case Case
1. 2. 3. 4.
The The The The
point point point point
zi zi zi zi
is is is is
a downward point and zi ∈ / qzi−1 (see Figure 2.10(b)). a downward point and zi ∈ qzi−1 (see Figure 2.12(a)). an upward point and zi ∈ qzi−1 (see Figure 2.12(b)). an upward point and zi ∈ / qzi−1 (see Figure 2.14(b)).
2.2 Computing Visibility of a Point in Simple Polygons
27
Figure 2.12 (a) The downward point zi belongs to zk zk+1 . (b) There is no pair in the stack whose segment contains the upward point zi .
Consider Case 1. We know from Lemma 2.2.4 that zi preserves the proper order as zi is a downward point and zi ∈ / qzi−1 . The procedure checks whether zi and zi+1 form a pair of opposite type and zi+1 preserves the proper order. Consider the situation where zi+1 ∈ qzi (see Figure 2.11(a)). By Lemma 2.2.4, zi+1 has violated the proper order. Starting from zi+2 , scan Z to locate a point zk such that zi ∈ qzk . Points (zi+1 , . . . , zk−1 ) are removed from Z and zk becomes the new zi+1 . So, zi ∈ qzi+1 . If zi+1 is an upward point (see Figure 2.10(b)), then (z0 , z1 , ..., zi , zi+1 ) is in the proper order by Lemma 2.2.4. So, the next pair of opposite type (zi , zi+1 ) is pushed on the stack. Otherwise, both zi and zi+1 are downward points (see Figure 2.11(b)) and zi+1 has violated the proper order by Lemma 2.2.4. Since bd(zi , zi+1 ) has wound around q, scan Z starting from zi+2 and locate a point zj such that zj ∈ zi zi+1 . Since zj is an upward point and zi ∈ qzj , (zi , zj ) becomes the next pair of opposite type by Lemma 2.2.4. Remove all points of Z that do not belong to qzi+1 and push (zi , zj ) on the stack. Observe that if zi zj lies inside Pa , zi zj can be added to Pa to remove winding in bd(zi , zi+1 ). Otherwise, by Lemma 2.2.3, there exists a pair of opposite type in Z (see Figure 2.11(b)) lying on the zi zj , which is detected later. Consider Case 2. By Lemma 2.2.4, zi has violated the proper order (see Figure 2.12(a)) as zi is a downward point and zi ∈ qzi−1 . Pop the stack till the pair (say, (zk , zk+1 )) is on top of the stack such that zi ∈ zk zk+1 . We know from Lemma 2.2.3 that there is a pair of opposite type in Z lying on zk zk+1 . Therefore scan Z from zi+1 and locate a point zj such that zj ∈ zk zi . It can be seen that zj is an upward point. Therefore, (zk , zj ) is a pair of opposite type. Hence, (z0 , z1 , . . . , zk , zj ) is in the proper order by Lemma 2.2.4. Push (zk , zj ) on the stack after (zk , zk+1 ) is popped from the stack.
28
Point Visibility
Figure 2.13 (a) The next pair formed by wk and wk+1 is in the proper order. (b) The next pair in the proper order is formed by wk and wj .
Consider Case 3. By Lemma 2.2.4, zi has violated the proper order as zi is an upward point and zi ∈ qzi−1 (see Figure 2.12(b) and Figure 2.13(a)). Scan Z from zi and locate two consecutive downward points zj−1 ∈ qzi−1 and zj ∈ qzi−1 (see Figure 2.12(b)). Remove (zi , . . . , zj−1 ) from Z and zj becomes the new zi . Execute Case 2. If no such points zj−1 and zj exist (see Figure 2.13(a)), the segments formed by pairs in the stack are added to partition Pa . In the process, the stack becomes empty. Observe that bd(zi−1 , zi ) still has winding (see Figure 2.13(a)) which has to be removed. Using the same stack, CC(Pa , qr , ql , Lr ) locates the sub-segments of qzi (from zi toward q) lying inside Pa . Traverse bd(Pa ) in counterclockwise order starting from zi , where zi = w0 (see Figure 2.13(a)) and compute intersection points W = (w0 , w1 , . . . , wp ) between bd(zi , q) and qzi . Observe that although any two consecutive points wk−1 and wk in W are of opposite type, wk may not belong to qwk−1 for all k and therefore, W may not be in the proper order in the direction from w0 towards q. The following lemma, which is analogous to Lemma 2.2.4, states the properties of the proper order of W . Lemma 2.2.5 Assume that (w0 , w1 , . . . , wk−1 ) is in the proper order. (i) If wk preserves the proper order, then wk ∈ / w0 wk−1 . (ii) If wk violates the proper order, then wk ∈ w0 wk−1 . (iii) If there is a point wj ∈ wt wt+1 , where t < k − 1, then wj is a subsequent point of wk−1 in W . Assume that CC(Pa , qr , ql , Lr ) has tested points w0 , w1 , . . . , wk−1 and they are in proper order (see Figure 2.13(a)). We also assume that (w0 , w1 ), (w2 , w3 ), . . ., (wk−2 , wk−1 ) are pushed on the stack by the procedure. Note that w0 is an upward point. If wk ∈ / w0 wk−1 , then (w0 , w1 , . . . , wk−1 , wk ) is in the proper order by Lemma
2.2 Computing Visibility of a Point in Simple Polygons
29
Figure 2.14 (a) The next pair in the proper order is formed by wj and wr . (b) Pa is partitioned by adding segments w0 w1 and w2 w5 .
2.2.5. If wk+1 ∈ / w0 wk (see Figure 2.13(a)), then (w0 , w1 , . . . , wk , wk+1 ) is also in the proper order by Lemma 2.2.5. So (wk , wk+1 ) is pushed on the stack as it is the next pair of opposite type. Otherwise, wk+1 has violated the proper order by Lemma 2.2.5 as wk+1 ∈ w0 wk (see Figure 2.13(b)). Scan W starting from wk+2 and locate a point wj such that wj ∈ / w0 wk . So (w0 , w1 , . . . , wk , wj ) is in the proper order by Lemma 2.2.5 and push (wk , wj ) on the stack. If wk ∈ w0 wk−1 (see Figure 2.14(a)), wk has violated the proper order by Lemma 2.2.5. Pop the stack till the pair (say, (wj , wj+1 )) is on top of the stack such that wk ∈ wj wj+1 . Scan W from wk+1 and locate a point wr ∈ wj wk . It can be seen that wr is a downward point and by Lemma 2.2.5, (w0 , w1 , . . . , wj , wr ) is in the proper order. Push (wj , wr ) on the stack. Consider Case 4. By Lemma 2.2.4, zi has violated the proper order as zi is an upward point and zi ∈ / qzi−1 (see Figure 2.14(b)). Note that there is a winding around q in bd(zi−1 , zi ). Traverse bd(Pa ) in counterclockwise order starting from zi and compute intersection points W = (w0 , w1 , ..., wp ), where zi = w0 , between bd(zi , q) and zi−1 zi . Clear the stack. Locate the pairs of opposite type in W from zi toward zi−1 using the same method stated above for W . Partition Pa by adding segments corresponding to these pairs and the part containing q on its boundary is the new Pa . Execute CC(Pa , qr , ql , Lr ) with new Pa and new Z. Since Case 4 cannot occur again, CC(Pa , qr , ql , Lr ) terminates after the second round of execution. In the following, we state the major steps of the procedure CC(Pa , qr , ql , Lr ). Step 1. Compute intersection points Z = (z0 , z1 , ..., zm ) between Lr and bd(Pa ) in the order from qr to ql , where z0 = qr . Initialize i by 1 and h by 0. Step 2. If zi is a downward point not belonging to qzh (see Case 1) then Step 2a. Scan Z from zi+1 and locate a point zk on qzi . Step 2b. If zk is an upward point then push (zi , zk ) on the stack and i := k + 1
30
Point Visibility
else locate a point zj ∈ zi zk by scanning Z from zk+1 , push (zi , zj ) on the stack and i := j + 1. Step 2c. If all points of Z are considered then goto Step 10 else h := i − 1 and goto Step 2. Step 3. If zi is a downward point on qzh (see Case 2) then Step 3a. Let (zk , zr ) denote the top element on the stack. Pop the stack until zi is a point on zk zr . Scan Z from zi+1 and locate a point zj ∈ zk zi . Pop the stack and push (zk , zj ) on the stack. Step 3b. If all points of Z are considered then goto Step 10 else i := j+1, h := i−1 and goto Step 2. Step 4. If zi is an upward point on qzh (see Case 3) then Step 4a. Scan Z from zi+1 and locate two consecutive downward points zj ∈ qzh and zj−1 ∈ qzh . If zj and zj−1 are found then i := j and goto Step 3. Step 4b. Partition Pa by adding segments corresponding to pairs on the stack to Pa . Clear the stack. Step 4c. Compute intersection points W = (w0 , w1 , ..., wp ), where w0 = zi , between qzi and bd(zi , ql ) in the order from zi to ql and goto Step 6. Step 5. If zi is an upward point not belonging to qzh (see Case 4) then Step 5a. Compute intersection points W = (w0 , w1 , ..., wp ), where w0 = zi , between zh zi and bd(zi , ql ) in the order from zi to ql . Step 5b. Clear the stack. Step 6. Step 7. push Step 8.
Initialize the stack by (w0 , w1 ) and k := 2. If wk ∈ / w0 wk−1 then locate a point wj ∈ / w0 wk by scanning W from wk+1 , (wk , wj ) on the stack, k := j + 1 and goto Step 9 If wk ∈ w0 wk−1 then
Step 8a. Let (wj , wt ) denote the top element on the stack. Pop the stack till wk is a point on wj wt . Step 8b. Scan W from wk+1 and locate a point wr ∈ wj wk . Pop the stack and push (wj , wr ) on the stack. Step 9. If all points of W are not considered then goto Step 7. Step 10. Partition Pa by adding the segments corresponding to pairs on the stack to Pa and Stop.
The correctness of the procedure CC(Pa , qr , ql , Lr ) follows from Lemmas 2.2.3, 2.2.4 and 2.2.5. After the modification of Pa by CC(Pa , qr , ql , Lr ), Pa is again modified by the procedure C(Pa , ql , qr , Ll ), which gives the portion of the pruned polygon P1 lying above the line L. Similarly, the portion of the pruned polygon P1 lying below the line L is obtained by executing the procedures C(Pb , qr , ql , Lr ) and CC(Pb , ql , qr , Ll ). The union of these two portions gives P1 . Since each procedure
2.3 Computing Visibility of a Point in Polygons with Holes
31
Figure 2.15 (a) The line L has intersected edges of P at u1 , u2 ,..., u7 . (b) A balanced binary tree T is initialized by edges e(u1 ), e(u2 ),..., e(u7 ).
runs in O(n) time, the algorithm takes O(n) time. We summarize the result in the following theorem. Theorem 2.2.6 Given a point q inside a simple polygon P of n vertices, a subpolygon P1 of P containing both q and the visibility polygon of P from q can be computed in O(n) time such that the boundary of P1 does not wind around q.
2.3 Computing Visibility of a Point in Polygons with Holes In this section, we present the algorithm of Asano [27] for computing the visibility polygon V (q) from a point q inside a polygon P with h holes with a total of n vertices. We first present an O(n log n) time algorithm based on angular plane sweep. Then we demonstrate how polygonal structures can be used to improve the time complexity of the algorithm to O(n log h). The algorithm starts by drawing the horizontal line L from q to the right of q (see Figure 2.15(a)). Then it sorts the vertices of P based on their polar angles at q. The polar angle of a vertex vj of P is the counterclockwise angle subtended by qvj at q with L. Let θ(vj ) denote the polar angle of vj . Vertices of P are labeled as v1 , v2 ,..., vn such that θ(vi−1 ) < θ(vi ) < θ(vi+1 ) for all i (see Figure 2.15(a)). Exercise 2.3.1 A tree with a specific node as root is called a binary tree T if every node of T has either no child, a left child, a right child or both a left and a right child [15]. The height of T is the number of nodes in the longest path from the root to a leaf. Show that the maximum number of nodes in T of height h is 2h+1 − 1.
32
Point Visibility
Figure 2.16 (a) Both edges of vi are active edges and they are deleted from T . (b) The active edge vi vk is replaced by the edge vi vj in T .
Consider the intersection points of L with the edges of P (see Figure 2.15(a)). They can be ordered by sorting such that the distance from q to the intersection point ui in the sorted list is less that of the intersection point uj for all i < j. Accordingly, the polygonal edges e(u1 ), e(u2 ), . . . , e(uk ) are ordered from left to right along L, where e(ui ) denotes the polygonal edge containing ui . Let T denote a balanced binary tree, where e(u1 ), e(u2 ), . . . , e(uk ) are represented as nodes of T and if e(ui ) is the left (or right) child of e(uj ) in T , then i < j (respectively, j < i) (see Figure 2.15(b)). So, e(u1 ) and e(uk ) are the leftmost and rightmost leaves of T. Suppose L is rotated around q in the counterclockwise direction. During the rotation, if an edge of P is intersected by the current position of L, the edge is called an active edge of P for that position of L. So, the list of active edges of P changes during the rotation (or angular sweep) of L and therefore, T also changes accordingly. Before we state the remaining steps for computing V (q), we explain how the list of active edges of P changes during the angular sweep of L. We start with the following observation. Lemma 2.3.1 The list of active edges of P changes if and only if L sweeps a vertex of P . The above lemma suggests that T needs modification at each vertex of P during the angular sweep. Let us consider the situation when L passes through a vertex v i . Let vi vj and vi vk be two polygonal edges incident at vi . If both vj and vk lie to the →i (see Figure 2.16(a)), then vi vj and vi v no longer remain active edges right of − qv k once L crosses vi and therefore, the nodes of T containing vi vj and vi vk are deleted →i (see from T . Consider the situation when vj and vk lie to the opposite side of − qv
2.3 Computing Visibility of a Point in Polygons with Holes
33
Figure 2.17 (a) Both edges vi vk and vi vj are not active edges and they are inserted in T . (b) Since wi+1 = wi+2 , no constructed edge is introduced at this vertex.
→i . It can be seen that Figure 2.16(b)). Let vk be the vertex lying to the right of − qv vi vj becomes a new active edge. On the other hand, vi vk is not an active edge once L crosses vi . So, vi vk is replaced by vi vj in T . If both vj and vk lie to the left of − →i (see Figure 2.17(a)), then vi vj and vi v become new active edges and therefore, qv k two nodes representing them are inserted in T . Let us return to the description of the algorithm. After initializing T , the algorithm traverses the sorted list v1 , v2 ,..., vn starting from v1 . Suppose the algorithm has processed from v1 to vi−1 and vi is currently under consideration. It performs one of the three operations on T for vi : Delete(T, i), U pdate(T, i) and Insert(T, i). Delete(T, i) is performed if both edges of vi are active edges (see Figure 2.16(a)). So, the nodes corresponding to the edges of vi are deleted from T . U pdate(T, i) is performed when one of two edges of vi is an active edge (see Figure 2.16(b)). So, the active edge of vi in T is replaced by the other edge of vi . Insert(T, i) is performed if both edges of vi are not active edges (see Figure 2.17(a)). Insert(T, i) locates two nodes in T by binary search, where one node is the parent of other node in T , such that vi lies between the two active edges represented by these two nodes in T . Then both edges of vi are inserted as two new nodes in T in the position of T located by the binary search. Note that after each operation of Insert(T, i) or Delete(T, i), T is balanced again. We have the following lemma. Lemma 2.3.2 Any point z on a polygonal edge e(z) is visible from q if and only if e(z) is the left most leaf of T at some stage of the angular sweep of L. The above lemma can be used to construct V (q) as follows. Let W = (w1 w2 , w3 w4 , . . . , wj wj+1 ) be the ordered set of edges of P appeared in the leftmost leaf of
34
Point Visibility
Figure 2.18 (a) The segment wi+1 z is the constructed edge at wi+1 . (b) The segment z 0 wi+2 is the constructed edge at wi+2 .
T during the angular sweep of L from its initial position to the final position (see Figure 2.17(b)). So, w1 w2 is the first active edge in the leftmost leaf of T when T is initialized, and wj wj+1 is the last active edge in the leftmost leaf of T . We have the following observation. Lemma 2.3.3 Two endpoints of every constructed edge of V (q) belong to two consecutive edges wi wi+1 and wi+2 wi+3 of W and one of the endpoints of the constructed edge is either wi+1 or wi+2 . The above lemma can be used for computing constructed edges of V (q). Consider any two consecutive edges wi wi+1 and wi+2 wi+3 . If wi+1 is same as wi+2 (see Figure 2.17(b)), then no constructed edge is introduced. Otherwise, either wi+1 or wi+2 is the vertex of the constructed edge (see Figure 2.18). If the extension of the line segment qwi+1 from wi+1 meets wi+2 wi+3 at some point (say, z), then wi+1 z is the constructed edge (see Figure 2.18(a)). Otherwise, the extension of the line segment qwi+2 from wi+2 meets wi wi+1 at some point (say, z 0 ). So, z 0 wi+2 is the constructed edge (see Figure 2.18(b)). Thus, all constructed edges of V (q) can be computed by considering all pairs of consecutive edges of W . In the following, we present the major steps for computing V (q). Step 1. Draw the horizontal line L from q to the right of q and compute the intersection points of L with edges of P . Step 2. Sort the intersection points from left to right along L. Let (u1 , u2 , . . . , uk ) be the sorted order of intersection points along L. Step 3. Represent edges e(u1 ), e(u2 ), . . . , e(uk ) as nodes and connect them according to the sorted order (u1 , u2 , . . . , uk ) to form a balanced binary tree T .
2.3 Computing Visibility of a Point in Polygons with Holes
35
Step 4. Sort the vertices of P based on their polar angle and label them accordingly as v1 , v2 ,..., vn . Initialize the index i by 1. Step 5. If both edges of vi are active edges then Step 5a. Delete(T, i). Step 5b. If there is a change in the leftmost leaf of T then compute the intersection →i and the edge currently in the leftmost leaf of T and add vi z to point z of − qv the list of constructed edges. Step 5c. Goto Step 8. Step 6. If one edge of vi is an active edge then U pdate(T, i) and goto Step 8. Step 7. If both edges of vi are not active edges then Step 7a. Insert(T, i). Step 7b. If there is a change in the leftmost leaf of T then compute the intersection →i and the edge previously in the leftmost leaf of T and add z 0 vi to point z 0 of − qv the list of constructed edges. Step 8. If i 6= n then i := i + 1 and goto Step 5.
Step 9. Output V (q) and Stop.
The correctness of the algorithm follows from Lemmas 2.3.1, 2.3.2 and 2.3.3. Let us now analyze the time complexity of the algorithm. Intersection points of the edges of P with L in Step 1 can be computed in O(n) time. Sorting of intersection points based on their distance to q in Step 2 takes O(n log n) time. Step 3 takes O(n) time to initialize T . Step 4 takes O(n log n) time to sort the vertices of P according to their polar angles. Since the height of T is O(log n), one operation of Insert(T, i) or Delete(T, i) can be done in O(log n) time [15]. Therefore, the total time taken for these two operations is O(n log n) as there can be at most n such operations. Since one operation of U pdate(T, i) takes O(1) time, total time for this operation is O(n). All constructed edges in V (q) can be computed in O(n) time as each constructed edge can be computed in O(1) time. Therefore, Steps 5, 6 and 7 together take O(n log n) time. Hence, the overall time complexity of the algorithm is O(n log n). We summarize the result in the following theorem. Theorem 2.3.4 The visibility polygon V (q) of a point q in a polygon P with holes with a total of n vertices can be computed in O(n log n) time. We modify the above algorithm to derive an O(n log h) time algorithm for computing V (q). Let H1 , H2 ,..., Hh be the holes inside P . For every hole Hi , compute the boundary of Hi that is externally visible from q (denoted as BV (Hi , q)) by the algorithm of Lee stated in Section 2.2. So, the line segment joining q and any point z of BV (Hi , q) is not intersected by any edge of Hi as the vertices of BV (Hi , q) are in the sorted angular order with respect to q. Since all holes of P except H i are
36
Point Visibility
ignored while computing BV (Hi , q), qz may be intersected by an edge of some other hole Hj for i 6= j.
We know that the boundary of P consists of boundaries of H1 , H2 ,..., Hh and the outer boundary of P enclosing all holes. So the algorithm also computes the portion of the outer boundary of P internally visible from q ignoring all holes. Since this visible boundary is like the visible boundary of any other hole, we can consider that P has h + 1 holes. However, for simplicity of notation, we assume that no point of the outer boundary of P belongs to V (q) and therefore, it is enough to consider holes H1 , H2 ,..., Hh for computing V (q). We have the following observation on BV (Hi , q). Lemma 2.3.5 Let z be a point on the boundary of Hi for some i. If z belongs to the boundary of V (q), then z ∈ BV (Hi , q). The above lemma suggests that in order to compute V (q), it is sufficient to consider BV (Hi , q) for all i. This property can be used to design an O(n log h) time algorithm for computing V (q) as follows. The algorithm starts by drawing the horizontal line L from q to the right of q and locates the edges of BV (Hi , q) for all i that are intersected by L. Ordering these intersected edges from left to right along L takes O(h log h) time as L can intersect only one edge of BV (Hi , q) for every i. These edges are represented as nodes of a balanced binary tree T as described in the earlier algorithm and it can be done in O(h) time. Observe that L intersects only one edge of BV (Hi , q) not only for the initial position of L but also for any position of L during the angular sweep, which suggests the following lemma. Lemma 2.3.6 The number of nodes in T is at most h during the angular sweep of L. Corollary 2.3.7 Each Delete(T, i) or Insert(T, i) operation takes O(log h) time. Let S denote the list of union of vertices of BV (H1 , q), BV (H2 , q), . . . , BV (Hh , q) in the sorted angular order around q in the counterclockwise direction. Since S can have O(n) vertices, direct sorting takes O(n log n) time. To keep the time complexity of the algorithm bounded by O(n log h), we need a different approach for constructing S. Let Si denote the list of vertices of BV (Hi , q) in clockwise order. So, the first vertex and the last vertex of Si make the minimum and maximum polar angles at q, respectively, among the vertices of Si . We show that S can be obtained by merging S1 , S2 , . . . , Sh in O(n log h) time using a heap [15]. Initially, the heap contains all vertices of active edges in T that are above L. These vertices are placed in the heap based on their polar angles at q. So, the root of the heap contains the vertex (say w) whose polar angle at q is the smallest in the heap (see Figure 2.19). The heap is used to find the next vertex in S. After initializing
2.3 Computing Visibility of a Point in Polygons with Holes
37
Figure 2.19 (a) The first vertex u in S 0 is v1 . (b) The vertex w in the root of the heap is v1 .
the heap, the algorithm takes only the first and last vertices from every Si and sorts these 2h vertices according to their polar angles at q in O(h log h) time. Let us denote this sorted list by S 0 . Let u denote the first vertex in S 0 . If θ(u) < θ(w) (see Figure 2.19(a)), then u is the first vertex v1 in S. Let u belong to Sk for some k. So the next vertex of u in Sk is added to the heap. The new vertex in the root of the heap becomes the current w and the next vertex of u in S 0 becomes the current u. If θ(u) > θ(w) (see Figure 2.19(b)), then w is the first vertex v1 in S and w is removed from the heap. Then the new vertex currently in the root of the heap becomes w. The process is repeated till the entire S is constructed. Since there can be at most h vertices in the heap, it takes O(log h) time to find the vertex whose polar angle at q is the smallest in the heap. Therefore, S can be constructed in O(n log h) time. After S is constructed, the algorithm performs the angular sweep of L and performs one of the three operations Delete(T, i), U pdate(T, i) and Insert(T, i) on T at each vertex of S as in the the earlier algorithm. However, there is a small difference. Delete(T, i) removes one edge from T instead of two edges. The same is true for Insert(T, i). Then the algorithm constructs V (q) from the active edges that appear in the leftmost leaf of T as before. The above method constructs V (q) correctly if there is no intersection between a constructed edge of BV (Hk , q) with an edge of a hole Hp for p 6= k. If such an intersection takes place (see Figure 2.19), ordering of the active edges along L changes at the place of intersection. The correct order of active edges along L can be represented in T by modifying the operation U pdate(T, i) as follows. Suppose U pdate(T, i) is to be performed at some vertex vi to replace the active edge of vi by the other edge of vi (say, vi vj ) which is a constructed edge of BV (Hk , q) for some k (see Figure 2.19). Without loss of generality, we assume that v j is the next clockwise vertex of vi in Sk . Note that one of vi and vj is actually a point on the
38
Point Visibility
Figure 2.20 (a) The shaded region is the interior half-plane of vi−1 vi . (b) The common intersection region K1 of the interior half-planes of vn v1 and v1 v2 .
boundary of Hk and the point is treated as a vertex in S. Instead of replacing one edge of vi by the other edge, the operation U pdate(T, i) performs Delete(T, i) and Insert(T, j) operations. Thus, the ordering of active edges along L is correctly maintained without increasing the overall time complexity of the algorithm. We summarize the result in the following theorem. Theorem 2.3.8 The visibility polygon V (q) of a point q in a polygon P with h holes with a total of n vertices can be computed in O(n log h) time. Corollary 2.3.9 The visibility polygon of a point in a convex polygon P with h convex holes with a total of n vertices can be computed in O(n + h log h) time.
2.4 Recognizing Simple Polygons Visible from a Point In this section, we present the algorithm of Lee and Preparata [234] for computing the kernel of a simple polygon P of n vertices in O(n) time. If the kernel of P is not empty, then P is the visibility polygon of P from any point of the kernel. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order, where v1 is a reflex vertex. We also assume that the given polygon P is a non-winding polygon (i.e., the revolution number of P is one) as the kernel of a winding polygon is always empty. Suppose an edge vi−1 vi of P is extended from both ends and this line vi−1 vi divides the plane into half-planes (see Figure 2.20(a)). The half-plane that lies to −−→ the left (or right) of v−i−1 vi is called the interior half-plane (respectively, exterior half-plane) of vi−1 vi . It can be seen that the interior half-plane of vi−1 vi is same as the exterior half-plane of vi vi−1 . We have the following lemma.
2.4 Recognizing Simple Polygons Visible from a Point
39
Lemma 2.4.1 The kernel of P is the intersection of the interior half-planes of v 1 v2 , v2 v3 ,..., vn v1 . Exercise 2.4.1 Prove Lemma 2.4.1. The above characterization immediately suggests an algorithm for computing the kernel of P in O(n2 ) time. Using the divide and conquer, the time complexity can be improved to O(n log n) [291]. Exercise 2.4.2 Let Q1 and Q2 be two convex polygons (without holes) with a total of m vertices. Design an algorithm for computing the common intersection region of Q1 and Q2 in O(m) time [291]. Exercise 2.4.3 Using Exercise 2.4.2, design an O(n log n) time algorithm for computing the common intersection region of n arbitrary half-planes by divide and conquer [291]. The algorithm of Lee and Preparata incrementally constructs the kernel of P in O(n) time taking advantage of the structure of a polygon as follows. The algorithm starts by constructing the common intersection region K1 of the interior half-planes of vn v1 and v1 v2 (see Figure 2.20(b)). Then it constructs two tangents from v1 to → K1 , which are two rays from v1 , one in the direction of v−− n v1 and the other in the − − → direction of v2 v1 . Note that the two tangents are rays as K1 is unbounded. Next, it constructs K2 by computing the intersection of K1 with the interior half-plane of v2 v3 . While computing K2 , tangents from v2 to K2 are also located. Then, it constructs K3 by computing the intersection of K2 with the interior half-plane of v3 v4 and so on till Kn−1 is computed, which is the kernel of P by Lemma 2.4.1. It can be seen that K1 , K2 , . . . , Kn−1 are convex. We now describe the method for computing K1 , K2 , . . . , Kn−1 . Assume that the algorithm has computed Ki−1 by computing the intersection of interior half-planes of vn v1 , v1 v2 , . . . , vi−1 vi . In the next stage, Ki is computed from the intersection of Ki−1 and the interior half-plane of vi vi+1 . We also assume that two tangents from vi to Ki−1 have been computed. Let vi li and vi ri denote the left and right tangents from vi to Ki−1 (see Figure 2.21), where li and ri are two corner −→ points of Ki−1 such that no point of Ki−1 lies to the left of vi li and to the right of → v−− i ri . The following cases can arise depending upon the positions of l i and ri with respect to vi vi+1 . → Case 1. Both points li and ri lie to the right of − vi−v− i+1 (see Figure 2.21(a)). → Case 2. Both points li and ri lie to the left of v−i−v− i+1 (see Figure 2.21(b)). → Case 3. Points li and ri lie on the opposite sides of v−i−v− i+1 (see Figure 2.22).
40
Point Visibility
Figure 2.21 (a) The entire region Ki−1 lies in the exterior half-plane of vi vi+1 . (b) The entire region Ki−1 lies in the interior half-plane of vi vi+1 .
→ Consider Case 1. Since both points li and ri lie to the right of v−i−v− i+1 , the entire Ki−1 lies in the exterior half-plane of vi vi+1 (see Figure 2.21(a)). Hence, P is not a star-shaped polygon as the kernel of P is empty. → Consider Case 2. Since both points li and ri lie to the left of v−i−v− i+1 , the entire
Ki−1 lies in the interior half-plane of vi vi+1 (see Figure 2.21(b)). So, Ki = Ki−1 . Scan the boundary of Ki−1 from li in counterclockwise order till a corner point u is −→ reached such that no point of Ki lies to the left of v−− i+1 u. Hence, vi+1 u is the left tangent from vi+1 to Ki and li+1 is u. Similarly, scan the boundary of Ki−1 from ri in counterclockwise order till a corner point w is reached such no point of K i lies to −→ the right of v−− i+1 w. Hence, vi+1 w is the right tangent from vi+1 to Ki and ri+1 is w. → Consider Case 3. Since li and ri lie to the opposite sides of v−i−v− i+1 , the line vi vi+1 intersects Ki−1 (see Figure 2.22). So, a part of Ki−1 has to be removed to obtain Ki . Let z and z 0 be the intersection points of vi vi+1 with the boundary of Ki−1 , where z ∈ z 0 vi . The following observations help in computing z and z 0 .
Lemma 2.4.2 Assume that vi vi+1 has intersected Ki−1 . If vi is a reflex vertex, li and ri lie in the exterior and interior half-planes of vi vi+1 , respectively (Figure 2.22(a)). Lemma 2.4.3 Assume that vi vi+1 has intersected Ki−1 . If vi is a convex vertex, ri and li lie in the exterior and interior half-planes of vi vi+1 , respectively (Figure 2.22(b)). The above lemmas suggest a simple way to compute z and z 0 by traversing the boundary of Ki−1 as follows. Consider the situation when vi is a reflex vertex (see Figure 2.22(a)). Scan the boundary of Ki−1 from li in counterclockwise (or
2.4 Recognizing Simple Polygons Visible from a Point
41
Figure 2.22 (a) Since vi is a reflex vertex, the part of Ki−1 containing li is removed. (b) Since vi is a convex vertex, the part of Ki−1 containing ri is removed.
clockwise) order to locate the intersection point z (respectively, z 0 ). Partition Ki−1 using the segment zz 0 . By Lemma 2.4.2, the portion of Ki−1 containing li does not belong to Ki . Therefore, the other part (which contains ri ) is Ki . Observe that z is li+1 . The right tangent vi+1 ri+1 can be located by scanning the boundary of Ki from ri in counterclockwise order as stated earlier. Consider the situation when vi is a convex vertex (Figure 2.22(b)). Again, scan the boundary of Ki−1 from ri in clockwise (respectively, counterclockwise) order to locate the intersection point z (respectively, z 0 ). Note that z or z 0 may lie on the edge vi vi+1 as vi is convex. Partition Ki−1 using the segment zz 0 and by Lemma 2.4.3, the portion of Ki−1 containing ri is removed to obtain Ki . Observe that z is ri+1 . The left tangent vi+1 li+1 can be located by scanning the boundary of Ki from li in counterclockwise order as stated earlier. In the following, we present the major steps for computing the kernel of P . Step 1. Compute the intersection of the interior half-planes of vn v1 and v1 v2 and → assign it to K1 . Take a point z on v−− 1 v2 lying outside the convex hull of P and 0 − − → assign z to l2 . Take a point z on vn v1 lying outside the convex hull of P and assign z 0 to r2 . Initialize the index i by 2. → Step 2. If both li and ri lie to the right of − vi−v− i+1 (Figure 2.21(a)) then report that the kernel of P is empty and Stop.
→ Step 3. If both li and ri lie to the left of v−i−v− i+1 then (Figure 2.21(b)) Step 3a. Assign Ki−1 to Ki . Step 3b. Locate the left tangent vi+1 li+1 by scanning the boundary of Ki from li in counterclockwise order.
42
Point Visibility
Step 3c. Locate the right tangent vi+1 ri+1 by scanning the boundary of Ki from ri in counterclockwise order and goto Step 8. Step 4. If vi is a reflex vertex then (Figure 2.22(a)) −−→ Step 4a. Locate the points of intersection z and z 0 of − vi+1 vi and the boundary of Ki−1 by scanning the boundary of Ki−1 from li in counterclockwise and clockwise order, respectively. Step 4b. Partition Ki−1 by zz 0 and assign the portion of Ki−1 containing ri to Ki . Assign z to li+1 . Step 4c. Locate the right tangent vi+1 ri+1 by scanning the boundary of Ki from ri in counterclockwise order and goto Step 8. → Step 5. Locate the points of intersection z and z 0 of v−i−v− i+1 and the boundary of Ki−1 by scanning the boundary of Ki−1 from ri in clockwise and counterclockwise order, respectively (see Figure 2.22(b)).
Step 6. Partition Ki−1 by zz 0 and assign the portion of Ki−1 containing li to Ki . Assign z 0 to ri+1 . Step 7. Locate the left tangent vi+1 li+1 by scanning the boundary of Ki from li in counterclockwise order. Step 8. If i 6= n − 1 then i := i + 1 and goto Step 2. Step 9. Report Kn−1 as the kernel of P and Stop.
Let us discuss the correctness of the algorithm. For computing Ki from Ki−1 , the algorithm checks whether vi vi+1 intersects Ki−1 . If there is no intersection, Ki−1 lies entirely in the interior or exterior half-plane of vi vi+1 . If the entire Ki−1 lies in the exterior half-plane of vi vi+1 (see Figure 2.21(a)), the common intersection region of interior half-planes becomes empty and therefore, P is not a star-shaped polygon by Lemma 2.4.1. So, the algorithm terminates in Step 2. If the entire K i−1 lies in the interior half-plane of vi vi+1 (see Figure 2.21(b)), the common intersection region of half-planes is same as Ki−1 . So, Ki−1 is assigned to Ki in Step 3. If vi vi+1 intersects Ki−1 (Figure 2.22), one part of Ki−1 is the common intersection region of interior half-planes. The algorithm uses Lemmas 2.4.2 and 2.4.3 in Steps 4 and 6 to decide which part of Ki−1 is the common intersection region of interior half-planes, and Ki is assigned accordingly. Thus the algorithm correctly computes Kn−1 which is the kernel of P by Lemma 2.4.1. The overall time complexity of the algorithm consists of (i) the time for computing K1 , K2 , . . . , Kn−1 , and (ii) the time for locating the left and right tangents for all vertices. It can be seen that two corner points can be introduced in the common intersection region by a half-plane and therefore, the total number of corner points that can be introduced is at most 2n. Since the cost for computing Ki from Ki−1 for all i is proportional to the number of corner points removed from K i−1 , the time taken for computing K1 , K2 , . . . , Kn−1 is O(n). The time for locating the left and
2.5 Notes and Comments
43
right tangents for all vertices is O(n), as the tangents move around the common intersection region of interior half-planes once in counterclockwise order. Hence, the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 2.4.4 The kernel of an n-sided simple polygon P can be computed in O(n) time. Corollary 2.4.5 Recognizing an n-sided simple polygon P visible from an internal point can be done in O(n) time.
2.5 Notes and Comments Let us consider the parallel algorithms for point visibility problems investigated in this chapter. Computing the visibility polygon from a point in a polygon P with holes was first considered by Atallah and Goodrich [38]. Their algorithm runs in O(log n log log n) time using O(n) processors in the CREW-PRAM model of computations. Using the cascading divide and conquer technique, Atallah et al. [37] showed that the visibility polygon of P from a point can be computed in O(log n) time using O(n) processors in the CREW-PRAM model of computations. Independently, Bertolazzi et al. [45] gave another algorithm for this problem which also runs in O(log n) time using O(n) processors in the CREW-PRAM model of computations. Although the above algorithms also work for polygons without holes, Atallah and Chen [32] showed that a faster algorithm is possible for this problem if the given polygon P is simple. They showed that the visibility polygon of P from a point can be computed in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations. Finally, Atallah et al. [36] gave an optimal algorithm for this problem which runs in O(log n) time using O(n/ log n) processors in the EREW-PRAM model of computations. Their algorithm starts by partitioning the boundary of P into chains. For each chain, it computes the portion of the chain whose vertices are in sorted angular order with respect to the given point. Then these chains are tested for intersections among themselves by exploiting polygonal properties. Finally, appropriate portions of these chains between intersection points are combined to form the visible boundary of P . If P is a star-shaped polygon, the visible boundary of P can be computed by a simple algorithm of Ghosh and Maheshwari [160], which also runs in O(log n) time using O(n/ log n) processors in the EREW-PRAM model of computations. Consider the problem of computing the kernel of a simple polygon P . We know that the sequential algorithm of Lee and Preparata [234] incrementally constructs the kernel of P . This means that their method does not directly lead to a parallel
44
Point Visibility
algorithm. Using a different approach, Chen [81] showed that the kernel of P can be computed in O(log n) time using O(n/ log n) processors in the EREW-PRAM model of computations. Let us mention results on the problems of visibility with reflections. Let q be a point light source inside a simple polygon P . Let z ∈ P be a point such that z is not visible from q directly. If light rays from q are allowed to reflect on edges of P , z can become visible from q. This means that certain portions of P , which are not visible directly from q, may become visible due to one or more reflections on the edges of P . Observe that since rays after reflection may intersect each other, the boundary of visible portions of P may contain several intersection points of these rays. There are two types of reflection. Reflection at a point is called specular reflection if the reflected ray follows the standard law of reflection; i.e., the angle of incidence is same as the angle of reflection. If reflecting edges are not perfect, another type of reflection called diffuse reflection can take place, where a light ray that is incident at a point is reflected in all possible directions toward the interior of P . Aronov et al. [25] studied the size of the visibility polygon for one specular or diffuse reflection. Corresponding problems for multiple specular or diffuse reflections were studied by Aronov et al. [24], Prasad et al. [289] and Pal et al. [281].
Exercise 2.5.1 Draw a simple polygon P where there exists two points u and v in P such that if a light source is placed at u, no light ray from u reaches v by specular reflections on edges of P [328].
Let us consider the visibility-based, pursuit-evasion problem in a polygon P . A point pursuer is assigned a task of locating moving evaders that are present in P . The evaders are also assumed to be points and are allowed to move in P continuously with unbounded speed. To solve the problem, the pursuer must move in P in such a way that every evader becomes visible to the pursuer eventually. This problem was first considered by Suzuki and Yamashita [323]. They gave algorithms for the movement of the pursuer in special classes of polygons having omni-directional visibility or flashlights. Guibas et al. [180] gave a complete solution for this problem for the case of omni-directional visibility. The variations of this problem in different types of polygons with one or more pursuers having omni-directional visibility or a given number of flashlights have been studied by Crass et al. [98], Lee et al. [236, 237], Park et al. [282], LaValle et al. [228], Suzuki et al. [322], Suzuki et al. [324] and Yamashita et al. [344]. For related problems, see LaValle [227] and Zhang [347].
2.5 Notes and Comments
Exercise 2.5.2 Let Q be a set of m points inside a simple polygon P of n vertices. Design an algorithm for locating a point z ∈ P (if it exists) in O((n + m) log(n + m)) time such that all points of Q are visible from z in P [153]. Exercise 2.5.3 Let S be a subset of vertices of a polygon P with or without holes. Design a polynomial time algorithm to test whether every internal point of P is visible from some vertex of S [152].
45
3 Weak Visibility and Shortest Paths
3.1 Problems and Results The notion of weak visibility of a polygon from a segment was introduced by Avis and Toussaint [42] in the context of the art gallery problem. They considered a variation of the problem when there is only one guard and the guard is permitted to move along an edge of the polygon. They defined visibility from an edge vi vi+1 in a simple polygon P in three different ways. (i) P is said to be completely visible from vi vi+1 if every point z ∈ P and any point w ∈ vi vi+1 , w and z are visible (Figure 3.1(a)). (ii) P is said to be strongly visible from vi vi+1 if there exists a point w ∈ vi vi+1 such that for every point z ∈ P , w and z are visible (Figure 3.1(b)). (iii) P is said to be weakly visible from vi vi+1 if each point z ∈ P , there exists a point w ∈ vi vi+1 (depending on z) such that w and z are visible (Figure 3.1(c)).
Figure 3.1 The polygon P is (a) completely, (b) strongly and (c) weakly visible from the edge vi vi+1 .
46
3.1 Problems and Results
47
Figure 3.2 The (a) complete and (b) weak visibility polygons of P from the edge v i vi+1 .
If P is completely visible from vi vi+1 , the guard can be positioned at any point w on vi vi+1 . In other words, P and the visibility polygon V (w) of P from any point w ∈ vi vi+1 are same. If P is strongly visible from vi vi+1 , there exists at least one point w on vi vi+1 from which the guard can see the entire P , i.e., P = V (w). Finally, if P is weakly visible from vi vi+1 , it is necessary for the guard to patrol along vi vi+1 in order to see the entire P . Exercise 3.1.1 Determine in O(n) time whether a simple polygon P is completely or strongly visible from a given edge vj vj+1 of P [42]. The above definitions for weak visibility also hold if P is a polygon with holes. It can be seen that there is no polygon with holes which is completely or strongly visible from an edge. However, the complete visibility polygon of P with or without holes can be defined as follows. A point z ∈ P is called completely visible from an edge vi vi+1 if it is visible to every point of vi vi+1 . The set of all points of P completely visible from vi vi+1 is called the complete visibility polygon of P from vi vi+1 (see Figure 3.2(a)). Similarly, a point z ∈ P is said to be weakly visible from an edge vi vi+1 if it is visible to some point of vi vi+1 . The set of all points of P weakly visible from vi vi+1 is called the weak visibility polygon of P from vi vi+1 (see Figure 3.2(b)). A more general notion of complete and weak visibility polygons allows visibility of P from an internal segment pq, not necessary an edge (see Figure 3.3). Let us consider the problem of computing the complete visibility polygon from an internal segment pq in a polygon P with or without holes (see Figure 3.3(a)). Consider any point z ∈ P that is visible from both endpoints p and q. If P is a
48
Weak Visibility and Shortest Paths
Figure 3.3 The (a) complete and (b) weak visibility polygons of P from an internal segment pq.
simple polygon, then z is completely visible from pq. If P contains holes, then the region enclosed by segments pq, qz and zp may contain a hole. In that case z may not be completely visible from pq. The following lemma suggests a way to compute the complete visibility polygon from pq inside P . Lemma 3.1.1 The complete visibility polygon from a line pq in a polygon P with or without holes is the visibility polygon from q inside the visibility polygon of P from p.
The above lemma suggests first to compute V (p) inside P which can be done in O(n log n) time if P has holes (see Section 2.3) and in O(n) time if P is a simple polygon (see Section 2.2). Then the visibility polygon from q inside V (p) can be computed in O(n) time to obtain the complete visibility polygon from pq inside P . On the other hand, it is not a straightforward task to compute the weak visibility polygon of a segment pq in a polygon P with or without holes (see Figure 3.3(b)). If P is a polygon without holes, ElGindy [127], Lee and Lin [232], and Chazelle and Guibas [76] gave O(n log n) time algorithms for this problem. Guibas et al. [178] showed that this problem can be solved in O(n) time if a triangulation of P is given along with P . Since P can be triangulated in O(n) time by the algorithm of Chazelle [71] (see Theorem 1.4.6), the algorithm of Guibas et al. [178] runs in O(n) time. In Section 3.3.1, we present the algorithm of Lee and Lin [232] which computes the weak visibility polygon by scanning the boundary of P . We present the algorithm of Guibas et al. [178] in Section 3.3.2.
3.1 Problems and Results
49
The relation between weak visibility polygons and Euclidean shortest paths was first observed by Guibas et al. [178] and Toussaint [330]. Their characterization was in terms of Euclidean shortest paths from p and q to every vertex of a weak visibility polygon, which was later used by them in computing the weak visibility polygon from pq. Ghosh et al. [163] generalized this characterization for any two vertices of a weak visibility polygon, which helped in recognizing weak visibility polygons. It has been shown by Icking and Klein [200], Das et al. [100] and Bhattacharya and Mukhopadhyay [50] that weak visibility polygons can also be characterized in terms of non-redundant components. In the next section (i.e., Section 3.2), we state these characterizations of weak visibility polygons along with some properties of Euclidean shortest paths. The union of Euclidean shortest paths from a vertex to all vertices of a simple polygon is called the shortest path tree (see Figure 3.24(a)). The shortest path tree has been used extensively as a tool in computational geometry for computing visibility in a polygon. Guibas et al. [178] presented an O(n) time algorithm for computing the shortest path tree in a triangulated simple polygon, which they also used in computing weak visibility polygon from a segment. We present their algorithm in Section 3.6.1 for computing the shortest path tree. For computing the weak visibility polygon from a line segment in a polygon with holes, Suri and O’Rourke [321] presented an O(n4 ) time algorithm. The algorithm is worst-case optimal as there are polygons with holes whose weak visibility polygon from a given segment can have O(n4 ) vertices. In Section 3.4, we present the algorithm of Suri and O’Rourke [321]. In the paper introducing weak and complete visibility, Avis and Toussaint [42] gave an O(n) time algorithm for recognizing a given simple polygon P that is weakly visible from a given edge vi vi+1 (see Figure 3.1(c)). Applying this algorithm to each edge of P , it can be tested in O(n2 ) time whether P is weakly visible from any edge of P . Sack and Suri [300] and Shin and Woo [311] improved this result by giving O(n) time algorithms for determining whether P is weakly visible from an edge. Chen [83] presented an O(n) time algorithm for computing the shortest sub-segment of an edge of P from which P is weakly visible. Exercise 3.1.2 Let uw be an edge of a simple polygon P of n vertices. Design an O(n) time algorithm for testing whether P is weakly from the edge uw [42]. Any line segment connecting two boundary points of P and lying inside P is called a chord of P . The general recognition problem is to construct a chord st (if it exists) inside a given simple polygon P such that P is weakly visible from st (see Figure 3.4(a)). The chord st is called a visibility chord. Ghosh et al. [163] gave an algorithm for this problem and their algorithm runs in O(E) time, where E is the number of
50
Weak Visibility and Shortest Paths
Figure 3.4 (a) The polygon P is weakly visible from the chord st but P is not weakly visible from any edge. (b) A weakly externally visible polygon P .
edges in the visibility graph of P . We present their algorithm in Section 3.5.1. For this problem, Doh and Chwa [114] and Kim et al. [215] presented O(n log n) time algorithms. For the same problem, Das et al. [100] and Bhattacharya and Mukhopadhyay [50] presented O(n) time algorithms. The algorithm of Das et al. [100] can also report all visibility chords. Das and Narasimhan [103] presented an O(n) time algorithm for computing the shortest segment from which P is weakly visible. In Section 3.5.2, we present the recognition algorithm given by Bhattacharya et al. [47], which is the combined results of Bhattacharya and Mukhopadhyay [50] and Das and Narasimhan [103]. Suppose a simple polygon P is given and the problem is to compute the shortest path tree from a vertex in P , if P has a visibility chord. It has been shown by Ghosh et al. [162] that the shortest path tree can be computed in P from any vertex in O(n) time without the prior knowledge of any visibility chord. If the algorithm terminates without computing the shortest path tree, then P does not have a visibility chord. If the algorithm computes the shortest path tree, P may have a visibility chord. The algorithm computes the shortest path tree by scanning the boundary of P and it does not require a triangulation of P as a preprocessing step. In fact, a triangulation of P can be constructed once the shortest path has been computed. This algorithm has been used as a preprocessing step in recognizing weak visibility polygons in the algorithms of Ghosh et al. [163] and Bhattacharya and Mukhopadhyay [50]. We present the algorithm of Ghosh et al. [162] in Section 3.6.2. Avis and Toussaint [42] first considered external visibility of a simple polygon P . A point z on the boundary of P is said to be externally visible from another point z0 ∈ / P if the line segment zz 0 does not intersect the interior of P . If every point
3.2 Characterizing Weak Visibility
51
Figure 3.5 The Euclidean shortest path between s and t (a) in a simple polygon P and (b) in a polygon P with holes.
on the boundary of P is visible from some point outside the convex hull of P , P is called a weakly externally visible polygon (see Figure 3.4(b)). Let c 1 , c2 , . . . , ck be the vertices of the convex hull of P in counterclockwise order. Note that the convex hull of P can be computed in O(n) time by the algorithm of Graham and Yao [175]. Using the algorithm of Avis and Toussaint [42], it can be tested whether the counterclockwise boundary of P from ci to ci+1 is weakly visible from the convex hull edge ci ci+1 for all i. Thus, the external weak visibility of P can be determined in O(n) time. A variation of this problem is to compute the shortest line segment for which the given simple polygon is weakly externally visible. This problem was solved in O(n) time by Bhattacharya and Toussaint [54] when P is a convex polygon. Later, they extended this result along with Mukhopadhyay [52, 53] for arbitrary simple polygons. In Section 3.7, we present the algorithm of Bhattacharya et al. [53].
3.2 Characterizing Weak Visibility We start this section with some properties of Euclidean shortest paths in a polygon P with and without holes. The Euclidean shortest path between two points s and t in P (denoted as SP (s, t)) is the path connecting s and t such that (i) the entire path lies totally inside P , and (ii) the length of the path is smaller than that of any path connecting s and t (see Figure 3.5). Observe that s and t can be connected by several paths inside P . In the following lemmas, we prove a few properties of SP (s, t); some of these properties have been observed by Lozano-Perez and Wesley [249], Lee and Preparata [235] and Chein and Steinberg [79].
52
Weak Visibility and Shortest Paths
Lemma 3.2.1 SP (s, t) is a simple path in P . Proof. If SP (s, t) intersects itself at some point u, by removing the sub-path from u to itself (i.e., the loop at u) a shorter path can be obtained, which is a contradiction.
Lemma 3.2.2 Let SP (s, t) = (s, ..., u, ..., v, ..., t). Then, SP (u, t) and SP (s, v) pass through v and u respectively. Proof. If SP (u, t) does not pass through v, then there exists a shorter path between s and t consisting of SP (s, u) and SP (u, t) contradicting the assumption that SP (s, t) is the shortest path. Analogous argument shows that SP (s, v) passes through u. Lemma 3.2.3 SP (s, t) turns only at vertices of P .
Proof. Assume that SP (s, t) has turned at some point u where u is not a vertex of P . Consider two points v and w on SP (s, t) such that (i) they are arbitrary close to u, (ii) v is on SP (s, u), and (iii) w is on SP (u, t). If the segment vw does not lie inside P for any choice of v and w, then u is a vertex of P which contradicts the assumption that u is not a vertex of P . So, we assume that the segment vw lies inside P . By triangle inequality the length of vw is less than the sum of the length of SP (v, u) and SP (u, w). So, there exists a shorter path between s and t consisting of SP (s, v), vw and SP (w, t). Hence, if SP (s, t) has turned at some point u, then u must be a vertex of P .
Corollary 3.2.4 The angle facing the exterior of the polygon at every vertex of P on SP (s, t) is convex (called outward convex). Lemma 3.2.5 If P does not contain a hole, then SP (s, t) is a unique path in P .
Proof. Assume that there are two paths between s and t inside P having the minimum length. Since both paths are shortest paths between s and t, they satisfy Lemmas 3.2.1 and 3.2.3. Without loss of generality, assume that both paths meet only at s and t. Since both paths lie inside P and P does not contains holes, the two paths form a simple polygon P 0 . Let m denote the number of vertices of P 0 . From Corollary 3.2.4, the internal angle at each vertex of P 0 is reflex except at s and t. Therefore, the sum of the internal angles of P 0 is more than (m − 2)π, contradicting the fact that the sum of internal angles of a simple polygon of m vertices is (m−2)π.
3.2 Characterizing Weak Visibility
53
Corollary 3.2.6 If P contains holes and there exists two paths between s and t having minimum length, then the region enclosed by these two paths must contain a hole. Let us state the relation in a simple polygon P between Euclidean shortest paths between vertices of P and weak visibility polygons from edges of P as observed by Guibas et al. [178] and Toussaint [330]. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. An edge vk vk+1 of P is called a convex edge if both vk and vk+1 are convex vertices. As before, bd(vi , vj ) denote the counterclockwise boundary of P from a vertex vi to another vertex vj . In the following lemma, we state the relationship. Lemma 3.2.7 Let vk vk+1 be a convex edge of a simple polygon P . A vertex vi of P is visible from some point of vk vk+1 if and only if SP (vk , vi ) makes a left turn at every vertex in the path and SP (vk+1 , vi ) makes a right turn at every vertex in the path. Proof. If vi is visible from a point u on vk vk+1 (see Figure 3.6(a)), then SP (vk , vi ) cannot intersect the segment uvi . So all vertices in SP (vk , vi ) must belong to bd(vi , vk ). Therefore, SP (vk , vi ) can only make a left turn at every vertex in the path. Analogously, SP (vk+1 , vi ) makes a right turn at every vertex in the path. Now we prove the converse. Let vp and vq denote the next vertex of vi in SP (vk , vi ) and SP (vk+1 , vi ), respectively (see Figure 3.6(a)). Since SP (vk , vi ) makes a left turn at → every vertex in the path, vk lies to the right of − v− i vp . Analogously, since SP (vk+1 , vi ) −−→ makes a right turn at every vertex in the path, vk+1 lies to the left of − v− i vk+1 . So, vk − − → − − → and vk+1 lie on opposite sides of the wedge formed by rays vi vp and vi vq . Therefore, the wedge intersects vk vk+1 . Hence vi is visible from any point of vk vk+1 lying in the wedge. Corollary 3.2.8 If a vertex vi of P is visible from some point of a convex edge vk vk+1 , then SP (vk , vi ) and SP (vk+1 , vi ) are two disjoint paths and they meet only at vi . Corollary 3.2.9 If a vertex vi of P is visible from some point of a convex edge vk vk+1 , then the region enclosed by SP (vk , vi ), SP (vk+1 , vi ) and vk vk+1 (called funnel) is totally contained inside P . Exercise 3.2.1 Draw a simple polygon showing that Lemma 3.2.7 does not hold if vk or vk+1 is a reflex vertex. It can be seen that the properties in Lemma 3.2.7 are of the shortest paths from the vertices vk and vk+1 to one other vertex vi of P. The shortest path between any
54
Weak Visibility and Shortest Paths
Figure 3.6 (a) The wedge formed by two rays intersects vk vk+1 . (b) All vertices of SP (vi , vj ) belong to bd(vi , vj ).
two vertices vi and vj of P also satisfy certain properties as shown by Ghosh et al. [163]. We state these properties in the following lemmas. Lemma 3.2.10 Assume that P is weakly visible from a convex edge vk vk+1 . Let vi and vj be two vertices of P such that vk vk+1 belongs to bd(vj , vi ). All vertices of SP (vi , vj ) belong to bd(vi , vj ). Proof. Since vi is visible from some point zi of vk vk+1 (see Figure 3.6(b)), SP (vi , vj ) does not intersect the segment vi zi and therefore, SP (vi , vj ) cannot pass through any vertex of bd(vk+1 , vi ). Again, since vj is visible from some point zj of vk vk+1 (see Figure 3.6(b)), SP (vi , vj ) does not intersect the segment vi zj and therefore, SP (vi , vj ) cannot pass through any vertex of bd(vj , vk ). Hence SP (vi , vj ) passes only through vertices of bd(vi , vj ). Lemma 3.2.11 Let vk vk+1 be a convex edge of P . Let vi and vj be two vertices of P such that vk vk+1 belongs to bd(vj , vi ). If all vertices of SP (vi , vj ) belong to bd(vi , vj ), then SP (vi , vj ) makes a right turn at every vertex in the path. Proof. Consider any vertex vq of SP (vi , vj ). Assume on the contrary that SP (vi , vj ) makes a left turn at vq (see Figure 3.7(a)). If the convex angle at vq is facing towards the interior of P , then by triangle inequality SP (vi , vj ) does not pass through vq , which is a contradiction. If the convex angle at vq is facing toward the exterior of P , then vq belongs to bd(vj , vi ), which is also a contradiction. Therefore SP (vi , vj ) makes a right turn at vq . Hence, SP (vi , vj ) makes a right turn at every vertex in the path.
3.2 Characterizing Weak Visibility
55
Figure 3.7 (a) The vertex vq does not belong to SP (vi , vj ). (b) The edge vp vq is an eave in SP (vi , vj ).
Lemma 3.2.12 Let vk vk+1 be a convex edge of P . For every vertex vi of P , if SP (vk+1 , vi ) makes a right turn at every vertex in the path and SP (vk , vi ) makes a left turn at every vertex in the path, then P is weakly visible from vk vk+1 . Proof. Proof follows along the line of the proof of Lemma 3.2.7. Using the above lemmas, Ghosh et al. [163] characterized simple polygons that are weakly visible from a convex edge. Their characterization is stated in the following theorem. Theorem 3.2.13 Let vk vk+1 be a convex edge of a simple polygon P . The following statements are equivalent. (i) P is weakly visible from vk vk+1 . (ii) For any two vertices vi and vj of P , where vk vk+1 belongs to bd(vj , vi ), SP (vi , vj ) passes only through vertices of bd(vi , vj ). (iii) For any two vertices vi and vj of P , where vk vk+1 belongs to bd(vj , vi ), SP (vi , vj ) makes a right turn at every vertex in the path. (iv) For any vertex vi of P , SP (vk+1 , vi ) makes a right turn at every vertex in the path and SP (vk , vi ) makes a left turn at every vertex in the path. Proof. (i) implies (ii) by Lemma 3.2.10, (ii) implies (iii) by Lemma 3.2.11, (iii) implies (iv) as a special case and (iv) implies (i) by Lemma 3.2.12. Using Theorem 3.2.13, Ghosh et al. [163] characterized simple polygons that are weakly visible from a chord st. Their characterization is stated in the following theorem.
56
Weak Visibility and Shortest Paths
Theorem 3.2.14 A simple polygon P is a weak visibility polygon if and only if there is a chord st inside P dividing P into sub-polygons P1 and P2 , where the boundary of P1 consists of bd(t, s) and st, and the boundary of P2 consists of bd(s, t) and ts, such that the following equivalent conditions hold for P1 and analogously for P2 . (i) For any two vertices vi and vj of P1 where vi belongs to bd(t, vj ), SP (vi , vj ) passes only through vertices of bd(vi , vj ). (ii) For any two vertices vi and vj of P1 , where vi belongs to bd(t, vj ), SP (vi , vj ) makes a right turn at every vertex in the path. (iii) For any vertex vi of P1 , SP (t, vi ) makes a right turn at every vertex in the path and SP (s, vi ) makes a left turn at every vertex in the path. Proof. If P is a weak visibility polygon from a chord st, then it follows from Theorem 3.2.13 that the three equivalent conditions hold for P1 as well as for P2 as st is a convex edge of both P1 and P2 . Let us prove the converse. If there is a chord st in P such that the three equivalent conditions hold for P1 and P2 , then it follows from Theorem 3.2.13 that both P1 and P2 are weakly visible from st. Therefore, P is weakly visible from st. From Theorem 3.2.14, we know that the shortest path between any two vertices in a sub-polygon P1 or P2 is convex. However, the shortest path from a vertex vi of one sub-polygon to another vertex vj of an other sub-polygon may not be convex (see Figure 3.7(b)). In that case, there exists an edge vp vq in SP (vi , vj ) such that SP (vi , vj ) makes a left turn (or, right turn) at vp and makes a right turn (respectively, left turn) at vq . Such edges vp vq are called eaves. In the following lemmas, we present the properties of eaves given by Ghosh et al. [163]. Lemma 3.2.15 If st is a visibility chord of a simple polygon P , then the shortest path between any two vertices in the same sub-polygon has no eaves. Proof. Proof follows from Theorem 3.2.14. Lemma 3.2.16 If the shortest path between two vertices vi and vj in a weak visibility polygon P has an eave vp vq , then every visibility chord st of P intersects the eave vp vq . Proof. Proof follows from Lemma 3.2.15. Lemma 3.2.17 In a weak visibility polygon P , the shortest path between any two vertices vi and vj of P has at most one eave. Proof. Proof follows from Lemma 3.2.16.
3.2 Characterizing Weak Visibility
57
Figure 3.8 (a) The counterclockwise C-polygon of vi . (b) The counterclockwise C-polygon of vi is redundant as it contains the counterclockwise C-polygon of vj . (c) The clockwise C-polygons of vi and vj lie inside the region P − R.
Exercise 3.2.2 Draw a simple polygon P such that (i) there is no eave in the shortest path between any two vertices of P , and (ii) P is not weakly visible from any chord. Let us present the characterization of weak visibility polygons in terms of nonredundant components as stated in Bhattacharya et al. [47]. Let vi be a reflex vertex of P . Extend the edge vi+1 vi (and vi−1 vi ) from vi till it meets a point ui (respectively, wi ) on the boundary of P (see Figure 3.8(a)). The clockwise boundary of P from vi to wi (i.e., bd(wi , vi )) is called the clockwise component of vi . Similarly, the counterclockwise component of vi is bd(vi , ui ). A component is redundant if it totally contains another component (see Figure 3.8(b)). Otherwise, it is called a non-redundant component. The region of P enclosed by the chord vi wi (or vi ui ) and bd(wi , vi ) (respectively, bd(vi , ui )) is called the clockwise (respectively, counterclockwise) C-polygon of vi (see Figure 3.8(a)). We have the following lemma. Lemma 3.2.18 P is weakly visible from an internal line segment ` if and only if ` intersects every non-redundant C-polygon of P . Proof. If ` does not intersect a non-redundant C-polygon of some vertex v i , then ` cannot see vi−1 or vi+1 . Hence P is not weakly visible from `. Let us prove the converse. Assume that ` intersects every non-redundant C-polygon of P but there exists a point z on the boundary of P that is not visible from ` (Figure 3.8(c)). So, ` lies in a region of P (denoted as R) that is not visible from z. Let z 0 vi be the constructed edge on the boundary of R, where the vertex vi is reflex. Observe that P − R totally contains either the clockwise or the counterclockwise C-polygon of vi . Moreover, ` does not intersect the C-polygon of vi . If the C-polygon of vi lying inside P − R is non-redundant, then ` has intersected all non-redundant C-polygons, which is a contradiction. So, we assume that the C-polygon of vi lying inside P − R
58
Weak Visibility and Shortest Paths
is redundant. Therefore, there exists another C-polygon of some reflex vertex v j lying totally inside P − R which is non-redundant. Hence, ` has not intersected this C-polygon of vj as well, which is a contradiction. Corollary 3.2.19 Every weak visibility polygon P has at most two disjoint Cpolygons. Corollary 3.2.20 If P has three or more mutually disjoint C-polygons, then P is not a weak visibility polygon.
3.3 Computing Weak Visibility in Simple Polygons 3.3.1 Scanning the Boundary: O(n log n) Algorithm In this section, we present an O(n log n) time algorithm of Lee and Lin [232] for computing the weak visibility polygon of a simple polygon P of n vertices from a line segment pq inside P (see Figure 3.3(b)). The weak visibility polygon of P from pq is denoted as V (pq). So, V (pq) contains all points of P that are visible from some point of pq. − Let u be the closest point to p among the intersection points of → qp with bd(P ) (see
Figure 3.9(a)) and let u lie on the edge vi vi+1 . Similarly, let w be the closest point − to q among the intersection points of → pq with bd(P ) and let w lie on the edge vk vk+1 . Cut P into two polygons P1 and P2 along uw. Let P1 =(vi , u, p, q, w, vk+1 , ..., vi−1 , vi ) and P2 =(vi+1 , ..., vk , w, q, p, u, vi+1 ). It can be seen that V (pq) is the union of weak visibility polygons of P1 and P2 from pq. So the problem is now to compute the weakly visible polygons of P1 and P2 from the edge pq. Since pq has become a convex edge of both P1 and P2 , the procedures for computing the weak visibility polygon from pq in P1 and P2 are analogous. For simplicity, we assume that pq is a convex edge of the given polygon P and we present the procedure accordingly. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order, where q = v1 and p = vn . If the revolution number of P with respect to p or q is more than one, the algorithm in Section 2.2.2 can be used to prune P . Hence, we assume that the revolution number of P with respect to p or q is one. In our definition, bd(a, b) denotes the counterclockwise boundary of P from a point a to another point b. We also denote bd(a, b) as bdcc (a, b). In the same way, bdc (a, b) denotes the clockwise boundary of P from a to b. Let SPcc (vj , vk ) denote the convex path restricted to bdcc (vj , vk ) (see Figure 3.9(b)) such that (i) intermediate vertices of the path belong to bdcc (vj , vk ), and (ii) the path makes only right turns. In general, SP (vj , vk ) may not pass through only the vertices of bdcc (vj , vk ) as it can also pass through vertices of bdc (vj , vk ).
3.3 Computing Weak Visibility in Simple Polygons
59
Figure 3.9 (a) P is divided by uw into two sub-polygons P1 and P2 . (b) SPcc (vj , vk ), SPcc (q, vi−1 ) and SPcc (q, vi ) make only right turns.
Therefore, SP (vj , vk ) and SPcc (vj , vk ) can be different and hence, SPcc (vj , vk ) may not always lie totally inside P . Again, SPc (vj , vk ) denotes the convex path restricted to bdc (vj , vk ) such that (i) intermediate vertices of the path belong to bdc (vj , vk ), and (ii) the path makes only left turns. We have the following lemma. Lemma 3.3.1 A vertex vi is weakly visible from pq if and only if SP (p, vi ) = SPc (p, vi ) and SP (q, vi ) = SPcc (q, vi ). Proof. Proof follows from Theorem 3.2.13. Based on the above lemma, the algorithm scans bdcc (v2 , vn−1 ) in counterclockwise order, and computes SPcc (q, v2 ), SPcc (q, v3 ),..., SPcc (q, vn−1 ). During the scan, if SPcc (q, vi ) does not make only right turns for some vertex vi , SPcc (q, vi ) is removed. In this process, the algorithm computes SPcc (q, w) for all those vertices w ∈ bdcc (v2 , vn−1 ) such that SPcc (q, w) makes only right turns. Analogously, the algorithm scans bdc (vn−1 , v2 ) in clockwise order and computes SPc (p, w) for all those vertices w ∈ bdc (vn−1 , v2 ) such that SPc (p, w) makes only left turns. After both scans, those vertices vi of P that have both SPcc (q, vi ) and SPc (p, vi ) are weakly visible from pq due to Lemma 3.3.1. Let us explain the procedure for computing SPcc (q, v2 ), SPcc (q, v3 ), SPcc (q, v4 )..., SPcc (q, vn−1 ). Assume that SPcc (q, v2 ), SPcc (q, v3 ),..., SPcc (q, vi−1 ) have been computed and the procedure wants to compute SPcc (q, vi ). The tree formed by the union of SPcc (q, v2 ), SPcc (q, v3 ),..., SPcc (q, vi−1 ) is denoted as SP Tcc (q, vi−1 ). Let uj denote the parent of vj in SP Tcc (q, vi−1 ), i.e., uj is the previous vertex of vj in SPcc (q, vj ). We have the following cases.
60
Weak Visibility and Shortest Paths
Figure 3.10 (a) SPcc (q, vi ) = (SPcc (q, vi−1 ), vi ). (b) Since there is a reverse turn at vi−1 , some vertices, including vi−1 , are not visible from pq.
−− −−−→ Case 1. The vertex vi lies to the left of u i−1 vi−1 (see Figure 3.9(b)). −− −−−→ Case 2. The vertex vi lies to the right of u i−1 vi−1 . −−−→ Case 2a. The vertex vi lies to the right of v−− i−2 vi−1 (see Figure 3.10(a)). − − − − → Case 2b. The vertex vi lies to the left of vi−2 v− i−1 (see Figure 3.10(b)). −− −−−→ Consider Case 1. Since vi lies to the left of u i−1 vi−1 , it means that SPcc (q, vi ) makes only right turns. Let vk be the previous vertex of vi in SPcc (q, vi ). It can be seen that vi vk is the tangent from vi to SPcc (q, vi−1 ) (see Figure 3.9(b)). So, SPcc (q, vi ) = (SPcc (v1 , vk ), vi ), where vk is the first vertex of SPcc (q, vi−1 ) starting → from vi−1 such that vi lies to the right of − u− k vk . Hence, vk becomes the parent of vi in SP Tcc (q, vi ). In other words, vk becomes ui . The region enclosed by vi−1 vi , vi ui and SPcc (ui , vi−1 ) are divided into triangles by extending each edge of SPcc (ui , vi−1 ) to vi−1 vi . −− −−−→ −−−−−→ Consider Case 2a. Since vi lies to the right of both u i−1 vi−1 and vi−2 vi−1 (see
Figure 3.10(a)), it means that SPcc (q, vi ) makes only right turns, and vi−1 is the previous vertex of vi in SPcc (q, vi ) as vi vi−1 is the tangent from vi to SPcc (q, vi−1 ). So, SPcc (q, vi ) = (SPcc (q, vi−1 ), vi ). −− −−−→ −−−−−→ Consider Case 2b. Since vi lies to the right of u i−1 vi−1 and to the left of vi−2 vi−1
(see Figure 3.10(b)), SP (q, vi−1 ) passes through vertices of bdcc (vi , p) and therefore, SP (q, vi−1 ) and SPcc (q, vi−1 ) are not the same. So vi−1 is removed from SP Tcc (q, vi−1 ). We say that there is a reverse turn at vi−1 . Observe that there may be other vertices vk like vi−1 in SP Tcc (q, vi−1 ) such that SP (q, vk ) and SPcc (q, vk ) are not the same. This means that the edge vi−1 vi has intersected some edges of SPcc (q, vk ). By checking the intersection with vi−1 vi (explained later), such vertices vk are removed from SP Tcc (q, vi−1 ). The edge vi−1 vi is called the current inward
3.3 Computing Weak Visibility in Simple Polygons
61
Figure 3.11 (a) Backtracking continues with vi vi+1 as the current inward edge. (b) Backtracking continues with rvj+1 as the current inward edge.
edge. Let vm be the first vertex from vi−1 on bdcc (q, vi−1 ) such that vi−1 vi does not intersect SPcc (q, vm ) (see Figure 3.10(b)). Locate ui by drawing the tangent from → vi to SPcc (q, vm ) as stated in Case 1. If vi+1 lies to the right of − u− i vi (see Figure 3.11(a)), the process of backtracking as stated above for vi−1 vi continues with vi vi+1 as the current inward edge. Consider the other situation when vi+1 lies to the left → of − u− i vi (see Figure 3.11(b) and Figure 3.13(a)). Let w denote the point of intersec→ −−−→ tion of vm vm+1 and − u− i vi . If vi+1 lies to the left of vi−1 vi (see Figure 3.11(b)), scan bdcc (vi+1 , p) from vi+1 in counterclockwise order until an edge vj vj+1 is located such that vj vj+1 intersects wvi at some point r. So, backtracking continues with rvj+1 −−→ as the current inward edge. If vi+1 lies to the right of v−i−1 vi (see Figure 3.13(a)), backtracking ends at vi . Let us explain the procedure for locating the parent ui of vi . Let xyz be a triangle (see Figure 3.13(a)) such that (i) y and z are two consecutive points or vertices on bdcc (q, vi−1 ), (ii) x is the parent of y in SP Tcc (q, vi−1 ), and (iii) if z is a vertex (or a point), then x is the parent (respectively, grandparent) of z in SP Tcc (q, vi−1 ). Note that if z is a point (created in Case 1), the parent of z (which is a vertex) is lying on xz. Observe that there exists one triangle xyz such that vi−1 vi has intersected xy but it has not intersected xz (see Figure 3.13(a)). So, x is the parent u i of vi in SP Tcc (q, vi−1 ). The above discussion suggests that the problem of locating ui is to locate the triangle xyz containing vi . The procedure initializes xyz by the triangle whose xy is ui−1 vi−1 . If xz of the current triangle xyz is not intersected by vi−1 vi (see Figure 3.13(a)), then the process of checking for intersections ends as xyz contains vi . Otherwise, the procedure has to identify the next triangle for checking the
62
Weak Visibility and Shortest Paths
Figure 3.12 (a) The edge vi−1 vi has intersected the segment connecting z and its parent z 0 . (b) Number of extension points inserted on edges of P can be O(n2 ).
intersection. If z is not a vertex, then vi−1 vi intersects either xz 0 (see Figure 3.13(b)) or z 0 z (see Figure 3.12(a)), where z 0 is the parent of z lying on the segment xz. If vi−1 vi intersects xz 0 (or, z 0 z), the other triangle of the segment xz 0 (respectively, z 0 z) becomes the current triangle xyz. If z is a vertex of P , then the other triangle of xz is unique. Observe that the cost of locating ui is proportional to the number of triangles intersected by vi−1 vi . In the following, we formally present the procedure for computing SP Tcc (q, vn−1 ). Initialize SP Tcc (q, v2 ) by assigning v1 as the parent of v2 and the index i by 2. −− −−−→ Step 1. If vi lies to the left of u i−1 vi−1 (Figure 3.9(b)) then Step 1a. Scan SPcc (q, vi−1 ) from vi−1 till a vertex vk is reached such that vi lies → to the right of − u− k vk . Assign vk as the parent ui of vi in SP Tcc (q, vi ). Step 1b. For every intermediate vertex vl in SPcc (ui , vi−1 ), extend ul vl from vl to vi−1 vi meeting it at some point w, insert w on vi−1 vi and assign vl as the parent of w in SP Tcc (q, vi ). Goto Step 4 −− −−−→ −−−−−→ Step 2. If vi lies to the right of both u i−1 vi−1 and vi−2 vi−1 (Figure 3.10(a)) then assign vi−1 as the parent ui of vi in SP Tcc (q, vi ) and goto Step 4. −− −−−→ −−−−−→ Step 3. If vi lies to the right of u i−1 vi−1 and to the left of vi−2 vi−1 (Figure 3.10(b)) then Step 3a. Locate the parent ui of vi in SP Tcc (q, vi−1 ) by checking for intersections with triangles. Extend ui vi from vi meeting the side of the triangle containing vi at w (Figure 3.10(b)). → −−−→ Step 3b. If vi+1 lies to the left of both − u− i vi and vi−1 vi (Figure 3.11(b)) then locate
3.3 Computing Weak Visibility in Simple Polygons
63
Figure 3.13 (a) Backtracking ends at vi . (b) The edge vi−1 vi has intersected the segment connecting the parent z 0 and the grandparent x of z.
the edge vj vj+1 intersecting wvi at a point r by scanning bdcc (vi+1 , p) from vi+1 and treat r as vi . Step 3c. Connect ui to vi by an edge in SP Tcc (q, vi ) and remove the region of P bounded by vi w and bdcc (w, vi ). Assign vi as the parent of w in SP Tcc (q, vi ) and treat w as vi−1 . → Step 3d. If vi+1 lies to the right of − u− i vi (Figure 3.11(a)) then i := i + 1 and goto Step 3a. Step 4. If i 6= n − 1 then i := i + 1 and goto Step 1. Step 5. Report SP Tcc (q, vn−1 ) and Stop. It can be seen that the above procedure has removed some regions of P in Step 3c. Let P 0 denote the remaining polygon. Using the analogous procedure, SP Tc (p, v2 ) can be computed by scanning the boundary P 0 in clockwise order. The remaining portion of P 0 is V (pq). Let us discuss the correctness of the algorithm. As stated in Lemma 3.3.1, a vertex vi−1 of P is weakly visible from pq if and only if SP (p, vi−1 ) = SPc (p, vi−1 ) and SP (q, vi−1 ) = SPcc (q, vi−1 ). This means that if SP (q, vi−1 ) 6= SPcc (q, vi−1 ), SP (q, vi−1 ) makes both left and right turns and therefore there is an edge in bdcc (vi , p) intersecting SPcc (q, vi−1 ). The procedure for computing SP Tcc (q, vn−1 ) accepts the current vertex vi in Steps 1 and 2 if vi lies outside the region enclosed by SPcc (q, vi−1 ) and bdcc (q, vi−1 ), which ensures that SPcc (q, vi ) makes only right turns. However, if vi lies inside the region enclosed by SPcc (q, vi−1 ) and bdcc (q, vi−1 ), the procedure locates the first vertex vm in the clockwise order starting from vi−1 in Step 3 such that vi lies outside the region enclosed by SPcc (q, vm ) and bdcc (q, vm ). By maintaining this invariant, the procedure for computing SP Tcc (q, vn−1 ) com-
64
Weak Visibility and Shortest Paths
putes SPcc (q, w) only for those vertices w ∈ bdcc (v2 , vn−1 ) such that SPcc (q, w) makes only right turns. Analogous arguments show that the procedure for computing SP Tc (p, v2 ) computes SPc (p, w) only for those vertices w ∈ bdc (vn−1 , v2 ) such that SPc (p, w) makes only left turns. Therefore, the vertices vi for which both SPcc (q, vi ) and SPc (p, vi ) belong to SP Tcc (q, vn−1 ) and SP Tc (p, v2 ), respectively, are only those vertices of P that are weakly visible from pq. Hence the algorithm correctly computes V (pq). Let us analyze the time complexity of the algorithm. It can be seen that the algorithm runs in O(n + m) time, where m is the number of points inserted on the boundary during the execution of Step 1b. If m is O(n), then we have O(n) time algorithm. Can m become O(n2 )? Yes, it can become O(n2 ) as shown in Figure 3.13(b). In this figure, n/2 points are removed during backtracking for one inward edge and then n/2 points are again inserted in the very next edge. The process can repeat for every pair of edges. Hence, the algorithm can take O(n2 ) time in the worst case. Recall that the parent ui of vi is located in Step 1a by a linear search on SPcc (q, vi−1 ) starting from vi−1 and in the process, extension points are inserted on edges of P . Instead of a linear search, a binary search can be carried out on SPcc (q, vi−1 ) to locate ui as SPcc (q, vi−1 ) is convex. On the other hand, the procedure needs the extension points to check the intersection of the current inward edge vi−1 vi with the triangles formed by these extension points in Step 3a. To overcome this difficulty. a binary search can be carried out to locate an edge vm vm+1 of P such that vi−1 vi intersects the tree edge vm+1 um+1 but does not intersect the tree edge vm um . This means that vi lies in the region bounded by vm vm+1 , vm+1 um+1 , SPcc (um+1 , um ) and um vm . In other words, vm is the first vertex from vi−1 in clockwise order such that vi−1 vi does not intersect SPcc (q, vm ). Another binary search can be carried out to locate ui in SPcc (um+1 , um ). In this process, the parent ui of vi can be located. So, at most two binary searches are required for each vertex v i to locate its parent ui . Thus, the overall time complexity of the algorithm can be reduced to O(n log n). To facilitate the above binary search, SP Tcc (q, vi−1 ) can be stored in concatenable queues. Concatenable queues support binary search, split and merge operations [14]. After locating the parent ui of vi by binary search on SPcc (q, vi−1 ), a split operation is performed at ui and then vi is added to SPcc (q, ui ). Similarly, merge operations are performed at vertices during backtracking to obtain SP cc (um+1 , um ). We summarize the result in the following theorem.
Theorem 3.3.2 The weak visibility polygon V (pq) of an internal segment pq in an n-sided simple polygon can be computed in O(n log n) time.
3.3 Computing Weak Visibility in Simple Polygons
65
Figure 3.14 (a) SP (p, vj ) makes a first right turn at vi . (b) SP (q, vj ) makes a first left turn at vi .
3.3.2 Using Shortest Path Trees: O(n) Algorithm In this section, we present an O(n) time algorithm of Guibas et al. [178] for computing the weak visibility polygon V (pq) of a simple polygon P of n vertices from a line segment pq inside P . As in Section 3.3.1, we present the algorithm for computing V (pq) from a convex edge pq of P . We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order, where q = v1 and p = vn . Let SP T (p) and SP T (q) denote the shortest path trees in P rooted at p and q respectively. The union of Euclidean shortest paths from a vertex to all vertices of a simple polygon is called the shortest path tree. For more details on the shortest path tree, see Section 3.6.1. In the following lemmas, we present the main idea used in the algorithm. Lemma 3.3.3 Let vi be the parent of vj in SP T (p) such that SP (p, vj ) makes a first right turn at vi (Figure 3.14(a)). Then all descendants of vi in SP T (p) are not visible from any point of pq. Proof. Proof follows from Theorem 3.2.13. Lemma 3.3.4 Let vi be the parent of vj in SP T (q) such that SP (q, vj ) makes a first left turn at vi (Figure 3.14(b)). Then all descendants of vi in SP T (q) are not visible from any point of pq. Proof. Proof follows from Theorem 3.2.13.
66
Weak Visibility and Shortest Paths
Lemmas 3.3.3 and 3.3.4 suggest a simple algorithm to compute V (pq) by traversing SP T (p) and SP T (q) using depth-first search (see [15]) as follows. Step 1. Compute SP T (p) in P by the algorithm in Section 3.6.1. Step 2. Traverse SP T (p) using depth-first search and check the turn at every vertex vi in SP T (p). If the path makes a right turn at vi then (Figure 3.14(a)) Step 2a. Find the descendant of vi in SP T (p) with the largest index j. → Step 2b. Compute the intersection point z of vj vj+1 and − v− k vi , where vk is the parent of vi in SP T (p). Step 2c. Remove the counterclockwise boundary of P from vi to z by inserting the segment vi z. Step 3. Let P 0 denote the remaining portion of P . Compute SP T (q) in P 0 by the algorithm in Section 3.6.1. Step 4. Traverse SP T (q) using depth-first search and check the turn at every vertex vi in SP T (q). If the path makes a left turn at vi then (Figure 3.14(b)) Step 4a. Find the descendant of vi in SP T (q) with the smallest index j. → Step 4b. Compute the intersection point z of vj vj−1 and − v− k vi , where vk is the parent of vi in SP T (q). Step 4c. Remove the clockwise boundary of P 0 from vi to z by inserting the segment vi z. Step 5. Output the remaining portion of P 0 as V (pq). The correctness of the algorithm follows from Lemmas 3.3.3 and 3.3.4. We analyze the time complexity of the algorithm. The algorithm for computing SP T (p) and SP T (q) takes O(n) time (see Section 3.6.1). Every vertex of SP T (p) and SP T (q) is traversed once and the remaining operations take constant time. So, the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 3.3.5 The weak visibility polygon V (pq) from an internal segment pq in an n-sided simple polygon can be computed in O(n) time.
3.4 Computing Weak Visibility in Polygons with Holes In this section, we present an O(n4 ) time algorithm of Suri and O’Rourke [321] for computing the weak visibility polygon V (pq) of a polygon P with holes with a total of n vertices from a line segment pq inside P . We treat the line segment pq as a hole inside P . In the following lemma, we present the main idea used in the algorithm.
3.4 Computing Weak Visibility in Polygons with Holes
67
Figure 3.15 Regions R1 (v), R2 (v) and R3 (v) are added to V (pq).
Lemma 3.4.1 If any point u ∈ P is weakly visible from pq, then u is visible (i) from p or q, or (ii) from a point y ∈ pq such that there exists a vertex v lying on the segment uy. Proof. The first part of the lemma follows from the fact that V (p) ⊂ V (pq) and V (q) ⊂ V (pq). Consider a point u that is not visible from p or q but is visible from some point z of pq. As z is moved along pq toward p or q, z continues to see u till z reaches either p or q or an internal point y of pq such that the segment uy touches the boundary of P at some vertex v. Since u is not visible from p or q by assumption, uy contains v. Corollary 3.4.2 Both y and u belong to the visibility polygon V (v). Let a1 b1 , a2 b2 ,..., ak bk be the maximal intervals on pq that are visible from v (see Figure 3.15). For all i, extend vai and vbi from v to the boundary of V (v) meeting at ci and di , respectively. Let Ri (v) denote the region of V (v) lying between ai ci and bi di . For all i, Ri (v) belongs to V (pq) by Lemma 3.4.1. So, the algorithm computes all such regions Ri (v) for every vertex v of P and then takes the union of all these regions to construct V (pq). Note that the union of these regions also includes points that are visible from p or q. Let us analyze the time complexity of the algorithm. For all vertices v of P , V (v) can be computed in O(n2 ) time [28, 165, 339]. All regions Ri (v) inside V (v) can be computed in O(n) time by scanning the boundary of V (v) once. Since there can be O(n) regions in each V (v) to be added to V (pq), the total number of such regions
68
Weak Visibility and Shortest Paths
is O(n2 ). So, computing the union of these regions takes O(n4 ) time. Hence the overall time complexity of the algorithm is O(n4 ). We summarize the result in the following theorem. Theorem 3.4.3 The weak visibility polygon V (pq) from a segment pq inside a polygon P with holes with a total of n vertices can be computed in O(n4 ) time.
3.5 Recognizing Weakly Internal Visible Polygons 3.5.1 Using Visibility Graph: O(E) Algorithm In this section, we present an O(E) time algorithm of Ghosh et al. [163] to determine whether the given simple polygon P of n vertices is a weak visibility polygon from some chord, where E is the number of visible pairs of vertices in P . The algorithm computes a visibility chord st in P by searching for the locations of s and t on the polygonal edges. The polygon in Figure 3.4(a) is weakly visible from the chord st but it is not weakly visible from any edge of the polygon. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. As before, SP T (vi ) denotes the shortest path tree in P rooted at vi . We also use the notation bd(vi , vj ) to denote the counterclockwise boundary of P from vi to vj . We start with the following lemma. Lemma 3.5.1 Let st be a visibility chord of P , where s ∈ vi vi+1 and t ∈ vj vj+1 . The shortest path between any two vertices of bd(vi+1 , vj ) (or bd(vj+1 , vi )) is convex (i.e., makes only left turns or only right turns). Proof. The proof follows from Theorem 3.2.14. In order to locate a visibility chord st in P , it is necessary to locate the pair of edges vi vi+1 and vj vj+1 (called potential pair of edges) of P that satisfy the above lemma. For every edge vi vi+1 of P , the algorithm identifies the set of edges Ei of P that can form a potential pair with vi vi+1 . We call the edges in Ei as potential edges of vi vi+1 . Observe that if vi vi+1 is a potential edge of an edge vj vj+1 ∈ Ei , then vi vi+1 and vj vj+1 form a potential pair of edges by Lemma 3.5.1. The following observations on potential edges follow from Lemma 3.5.1. Lemma 3.5.2 If vj vj+1 is a potential edge of vi vi+1 , then (i) for any vertex vk ∈ bd(vi+1 , vj ), SP (vi+1 , vk ) makes only right turns, and (ii) for any vertex vk ∈ bd(vj+1 , vi ), SP (vi , vk ) makes only left turns. Lemma 3.5.3 If no two edges of P are mutually potential edges of each other, then P is not a weak visibility polygon.
3.5 Recognizing Weakly Internal Visible Polygons
69
Figure 3.16 (a) Right and left constructed edges are in proper order. (b) P has a visibility chord st but there is no potential edge of vi vi+1 .
The potential edges of vi vi+1 can be identified from constructed edges of the weak visibility polygon V (vi vi+1 ). A constructed edge vk q of V (vi vi+1 ) is called a left constructed edge (Figure 3.16(a)) if bd(q, vk ) does not contain vi vi+1 and a right constructed edge, otherwise. We have the following lemma. Lemma 3.5.4 If vj vj+1 is a potential edge of vi vi+1 , then all right constructed edges of V (vi vi+1 ) are on bd(vi+1 , vj ) and all left constructed edges of V (vi vi+1 ) are on bd(vj+1 , vi ). Proof. For any vertex vk ∈ bd(vi+1 , vj ) (or bd(vj+1 , vi )), we know from Lemma 3.5.2 (see Figure 3.16(a)) that SP (vi+1 , vk ) (respectively, SP (vi , vk )) makes only right turns (respectively, left turns). So, all right and left constructed edges of V (vi vi+1 ) belong to bd(vi+1 , vj ) and bd(vj+1 , vi ), respectively. Using the above lemma, the potential edges of vi vi+1 for all i can be identified by scanning the boundary of V (vi vi+1 ) (denoted as bV (vi vi+1 )) from vi+1 to vi in counterclockwise order. The following three cases can arise during the scan. Case 1. If there is no constructed edge, then bV (vi vi+1 ) = bd(P ). It means that the edge vi vi+1 is a visibility chord of P . Case 2. If a left constructed edge is scanned before a right constructed edge, then there is no potential edge of vi vi+1 (Figure 3.16(b)). Case 3. If all right constructed edges are scanned before all left constructed edges, then all edges of P between the last right constructed edge and the first left constructed edge are potential edges of vi vi+1 (Figure 3.16(a)). Note that the potential edges of vi vi+1 are consecutive edges on bd(P ).
70
Weak Visibility and Shortest Paths
Figure 3.17 (a) Right and left intervals on vi vi+1 as well as on vj vj+1 are overlapping. (b) There is no visibility chord in P .
Once potential edges Ei of vi vi+1 are found, check whether vi vi+1 has already been found to be a potential edge of vj vj+1 ∈ Ei . If so, vi vi+1 and vj vj+1 form a potential pair. Thus all potential pairs of edges in P can be located by scanning bV (vi vi+1 ) for i = 1, 2, ..., n. We have the following observation. Lemma 3.5.5 If (vi vi+1 , vj vj+1 ) and (vi vi+1 , vk vk+1 ) are potential pairs, where j > k, then for any edge vm vm+1 ∈ bd(vk+1 , vj ), (vi vi+1 , vm vm+1 ) is also a potential pair. We need another property for a potential pair to contain a visibility chord st. Consider a potential pair (vi vi+1 , vj vj+1 ). Let li denote the furthest point of vi+1 on vi vi+1 (Figure 3.17(a)) such that for every vertex vq ∈ bd(vi+1 , vj ), SP (li , vq ) makes only right turns. The portion li vi+1 is called the right interval of vi vi+1 for vj vj+1 . Similarly, let ri denote the furthest point of vi on vi vi+1 such that for every vertex vp ∈ bd(vj+1 , vi ), SP (ri , vp ) makes only left turns. The portion vi ri is called the left interval of vi vi+1 for vj vj+1 . We have the following lemma. Lemma 3.5.6 Let vi vi+1 and vj vj+1 be the edges of a potential pair. Assume that there exists a chord st in P where s ∈ vi vi+1 and t ∈ vj vj+1 . The chord st is a visibility chord of P if and only if s belongs to both left and right intervals of v i vi+1 for vj vj+1 and t belongs to both left and right intervals of vj vj+1 for vi vi+1 . Proof. Assume that st is a visibility chord. Since st is a visibility chord, for any vertex vp ∈ bd(vj+1 , vi ), SP (s, vp ) makes only left turns by Theorem 3.2.14 (see Figure 3.17(a)). So s lies in the left interval of vi vi+1 for vj vj+1 . Similarly, for any
3.5 Recognizing Weakly Internal Visible Polygons
71
vertex vq ∈ bd(vi+1 , vj ), SP (s, vq ) makes only right turns. So s lies in the right interval of vi vi+1 for vj vj+1 . Hence s belongs to both intervals of vi vi+1 for vj vj+1 . Analogous arguments show that t belongs to both intervals of vj vj+1 for vi vi+1 . We now prove the converse. Assume that s belongs to both left and right intervals of vi vi+1 for vj vj+1 and t belongs to both left and right intervals of vj vj+1 for vi vi+1 . Therefore, for any vertex vp ∈ bd(vj+1 , vi ), SP (s, vp ) (respectively, SP (t, vp )) makes only left (respectively, right) turns, and for any vertex vq ∈ bd(vi+1 , vj ), SP (s, vq ) (respectively, SP (t, vq )) makes only right (respectively, left) turns. Hence, st is a visibility chord of P by Theorem 3.2.14.
Let us state the procedure for computing left and right intervals of vi vi+1 for vj vj+1 . For each vertex vp ∈ bd(vj+1 , vi ) and bV (vi vi+1 ), compute the intersection → point of vi vi+1 and − v− p vk , where vk is the parent of vp in SP T (vi+1 ) (see Figure 3.17(a)). Among all the intersection points, the intersection point closest to v i is the point ri . So vi ri is the left interval of vi vi+1 for vj vj+1 . Analogously, the right interval of vi vi+1 for vj vj+1 can be computed. Observe that if vi vi+1 has two or more potential edges, the left and right intervals of vi vi+1 for all its potential edges (which are consecutive by Lemma 3.5.5) can be computed by scanning bV (vi , vi+1 ) once in clockwise order and once in counterclockwise order. We have the following lemmas. Lemma 3.5.7 Let vi vi+1 and vj vj+1 be the edges of a potential pair. Assume that the left interval vi ri and the right interval li vi+1 of vi vi+1 for vj vj+1 overlap, and the left interval vj rj and the right interval lj vj+1 of vj vj+1 for vi vi+1 overlap. If SP (li , rj ) and SP (ri , lj ) are disjoint, then there is a visibility chord st in P such that s ∈ li ri and t ∈ lj rj . Proof. Consider SP (li , lj ). If SP (li , lj ) is just the segment li lj , then s = li and t = lj . Otherwise, SP (li , lj ) contains an eave (see Figure 3.17(a)). Since SP (li , rj ) and SP (ri , lj ) are convex and disjoint, the eave in SP (li , lj ) is a cross-tangent between SP (rj , li ) and SP (lj , ri ). Extend the eave in both directions meeting li ri and lj rj at points s and t, respectively. Hence, st is a visibility chord of P by Lemma 3.5.6.
Lemma 3.5.8 Let vi vi+1 and vj vj+1 be the edges of a potential pair. Assume that the left interval vi ri and the right interval li vi+1 of vi vi+1 for vj vj+1 overlap, and the left interval vj rj and the right interval lj vj+1 of vj vj+1 for vi vi+1 overlap. If SP (li , rj ) and SP (ri , lj ) share a vertex, then there is no visibility chord in P . Proof. Let vk be a vertex common to SP (li , rj ) and SP (ri , lj ) (see Figure 3.17(b)). Since both SP (ri , lj ) and SP (li , rj ) pass through vk , there is no chord between li ri
72
Weak Visibility and Shortest Paths
and lj rj . If vk ∈ bd(vj+1 , vi ), then any visibility chord must have one endpoint on bd(vk , ri ) and the other on bd(lj , vk ), which is not possible. Analogous argument holds if vk ∈ bd(vi+1 , vj ). Hence, there is no visibility chord in P . A visibility chord st in P can be computed between the edges in a potential pair if the edges satisfy Lemma 3.5.7. If no such pair exists or there is a potential pair of edges which satisfy Lemma 3.5.8, then P does not have a visibility chord. In the following, we state the major steps for computing a visibility chord st inside P . Step 1. Compute SP T (v1 ) by the algorithm of Ghosh et al. [162] stated in Section 3.6.2. Step 2. Compute V (v1 v2 ), SP T (v2 ), V (v2 v3 ), SP T (v3 ),..., SP T (vn ), V (vn v1 ) by the algorithm of Hershberger [186] stated in Section 5.2. Step 3. For every edge vi vi+1 in P , locate the potential edges of vi vi+1 by scanning bV (vi vi+1 ) from vi+1 to vi in counterclockwise order. Step 4. For every pair of edges vi vi+1 and vj vj+1 that are mutually potential edges of each other, add (vi vi+1 , vj vj+1 ) to the list of potential pairs. Step 5. For every edge vi vi+1 in the list of potential pairs do Step 5a. Scan bV (vi vi+1 ) once in clockwise order and compute the left interval of vi vi+1 for each edge that has formed a potential pair with vi vi+1 . Step 5b. Scan bV (vi vi+1 ) once in counterclockwise order and compute the right interval of vi vi+1 for each edge that has formed a potential pair with vi vi+1 . Step 5c. If the left and right intervals of vi vi+1 do not overlap for an edge vj vj+1 then remove (vi vi+1 , vj vj+1 ) from the list of potential pairs. Step 6. If the list of potential pairs is empty or if SP (li , rj ) and SP (ri , lj ) share a vertex for a potential pair (vi vi+1 , vj vj+1 ) then report that P is not a weak visibility polygon and Stop. Step 7. Take any potential pair (vi vi+1 , vj vj+1 ) from the list of potential pairs, compute a visibility chord st by extending the eave in SP (li , lj ) in both directions to li ri and lj rj , report st as a visibility chord of P and Stop. The correctness of the algorithm follows from Lemmas 3.5.1, 3.5.4, 3.5.6, 3.5.7 and 3.5.8. We analyze the time complexity of the algorithm. The algorithm of Ghosh et al. [162] in Step 1 for computing SP T (v1 ) takes O(n) time. The algorithm of Hershberger [186] for computing V (v1 v2 ), SP T (v2 ), V (v2 v3 ), SP T (v3 ),..., SP T (vn ), V (vn v1 ) in Step 2 takes O(E) time. To find the list of potential pairs, the algorithm scans the boundary of each visibility polygon once. Since the sum of the sizes of bV (vi vi+1 ) for all i is O(E), Step 3 and Step 4 run in O(E) time. Then the algorithm scans bV (vi vi+1 ) twice to compute intervals for each vi vi+1 . So, Step 5 also takes O(E) time. Step 6 and Step 7 together run in O(n) time. Hence, the overall time complexity of the algorithm is O(E). We summarize the result in the following theorem.
3.5 Recognizing Weakly Internal Visible Polygons
73
Theorem 3.5.9 A visibility chord st in a simple polygon P can be constructed in O(E) time, where E is the number of visible pairs of vertices in P .
3.5.2 Scanning the Boundary: O(n) Algorithm In this section, we present an O(n) time algorithm of Bhattacharya et al. [47] for recognizing a weak visibility polygon P of n vertices. The algorithm constructs visibility chords of P and then computes the shortest segment from which P is weakly visible. Here we present only a part of their algorithm which locates a visibility chord in P in O(n) time. In Section 3.2, weak visibility polygons have been characterized in terms of non-redundant C-polygons. This characterization stated in Lemma 3.2.18 is used here to compute a visibility chord of P . We also use here the algorithm of Ghosh et al. [162], presented in Section 3.6.2, for computing shortest path trees in P . We know from Lemma 3.2.18 that it is enough to consider only non-redundant C-polygons of P as they determine the positions of visibility chords in P . On the other hand, Corollary 3.2.19 suggests that a weak visibility polygon can have at most two disjoint C-polygons. Let us first check whether the given simple polygon P has one, two or more disjoint C-polygons. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. Without loss of generality, we assume that v1 is a reflex vertex. Compute SP T (v1 ) in P by the algorithm of Ghosh et al. [162]. If the algorithm does not succeed in computing SP T (v1 ), then P is not a weak visibility polygon. Henceforth we assume that SP T (v1 ) has been computed. Scan bd(P ) in counterclockwise order from v2 (see Figure 3.18(a)) and locate the first vertex vi such that vi+1 is the parent of vi in SP T (v1 ). If no such vertex exists, scan bd(P ) in clockwise order from vn and locate the first vertex vi such that vi−1 is the parent of vi in SP T (v1 ). If no such vertex exists, then the entire polygon P is visible from v1 and the algorithm terminates. Without loss of generality, we assume that vi has been located during the counterclockwise scan (see Figure 3.18(a)). Locate the meeting point w i+1 by extending vi vi+1 from vi+1 (through the edges of SP T (v1 )) to bd(v1 , vi ). So, bd(wi+1 , vi+1 ) and the bounding chord vi+1 wi+1 define a clockwise C-polygon (denoted as polyc (vi+1 )). Observe that this C-polygon does not contain any other clockwise C-polygon. However, it may contain a counterclockwise C-polygon. Scan from vi−1 in clockwise order to locate the first vertex vj before reaching wi+1 such that (i) vj−1 is the parent −−→ of vj in SP T (v1 ), and (ii) v−− j vj−1 does not intersect the bounding chord vi+1 wi+1 . Locate the meeting point uj−1 by extending vj vj−1 from vj−1 to bd(vj , vi+1 ). So, the counterclockwise C-polygon with bounding chord vj−1 uj−1 (denoted as polycc (vj−1 )) is contained inside polyc (vi+1 ). It can be seen that polycc (vj−1 ) is not contained in any clockwise or counterclockwise C-polygon. If no such vertex vj is located before
74
Weak Visibility and Shortest Paths
Figure 3.18 (a) The clockwise C-polygon with bounding chord vi+1 wi+1 contains the counterclockwise C-polygon with bounding chord vj−1 uj−1 . (b) Two disjoint critical polygons with bounding chords vp wp and vq uq .
reaching wi+1 , polyc (vi+1 ) does not contain any C-polygon. Thus the algorithm locates the first disjoint C-polygon; call it a critical polygon. Without loss of generality, we assume that the algorithm has located a clockwise C-polygon as the first critical polygon; call it polyc (vp ) (see Figure 3.18(b)). It can be seen that polyc (vp ) is weakly visible from its bounding chord vp wp . If vp wp can also see the remaining portion of P , then it is a visibility chord of P . This can be tested, as shown in Section 3.6, by traversing SP T (vp ) and SP T (wp ). These two trees can be computed directly by the algorithm of Ghosh et al. [162]. They can also be computed easily by scanning bd(P ) using SP T (v1 ). Exercise 3.5.1 Let vk be a vertex of a simple polygon P of n vertices. Assume that SP T (vk ) has been given along with P . Assume that any path in SP T (vk ) has at most one eave. From any vertex vm of P , compute SP T (vm ) in O(n) time by scanning the boundary of P using SP T (vk ). We assume that vp wp is not a visibility chord and we have SP T (vp ) and SP T (wp ) in addition to SP T (v1 ). Scan bd(vp , wp ) and locate a C-polygon using SP T (vp ) or SP T (wp ) (as stated above) such that it does not contain another C-polygon and its bounding chord connects two points of bd(vp , wp ) (see Figure 3.18(b)). Without loss of generality, we assume that it is a counterclockwise C-polygon; call it poly cc (vq ). It can be tested again whether entire P is visible from the bounding chord vq uq . In the process, SP T (vq ) and SP T (uq ) have been computed. Assume that vq uq is not a visibility chord of P . It can be seen that bd(P ) has been partitioned into four
3.5 Recognizing Weakly Internal Visible Polygons
75
chains bd(vp , vq ), bd(vq , uq ), bd(uq , wp ) and bd(wp , vp ) (see Figure 3.18(b)) and each of them has a particular structure as shown in the following lemmas. Lemma 3.5.10 Let vp wp and vq uq be bounding chords of two disjoint critical polygons polyc (vp ) and polycc (vq ) in P , respectively, where vp ∈ bd(wp , vq ). One endpoint of every visibility chord st belongs to bd(wp , vp ) and the other endpoint belongs to bd(vq , uq ). Proof. We know that every visibility chord must intersect both critical polygons polyc (vp ) and polycc (vq ) by Lemma 3.2.18. Since polyc (vp ) and polycc (vq ) are disjoint (see Figure 3.18(b)), one endpoint of every visibility chord st belongs to bd(w p , vp ) and the other endpoint belongs to bd(vq , uq ). Corollary 3.5.11 Every visibility chord of P lies inside the visibility polygon of P from vp wq as well as in the visibility polygon of P from vq uq . Lemma 3.5.12 Let vp wp and vq uq be bounding chords of two disjoint critical polygons polyc (vp ) and polycc (vq ) in P , respectively, where vp ∈ bd(wp , vq ). If P is a weak visibility polygon, then for every vertex vk ∈ bd(uq , wp ), (i) SP (wp , vk ) makes only left turns, (ii) SP (uq , vk ) makes only right turns and (iii) both SP (wp , vk ) and SP (uq , vk ) pass through only the vertices of bd(uq , wp ). Proof. If SP (wp , vk ) makes a right turn at some vertex vm ∈ bd(wp , vq ), then there exists a critical polygon such that both endpoints of its bounding chord belong to bd(uq , wp ). It means that P has three disjoint critical polygons and therefore, P is not a weak visibility polygon by Corollary 3.2.20, which is a contradiction. Analogous arguments show that SP (uq , vk ) makes only right turns. If SP (wp , vk ) or SP (uq , vk ) pass through a vertex vm ∈ bd(vp , vq ), then no point of vp wp is visible from any point of vq uq and vice versa. Therefore, there is no chord with one endpoint on bd(wp , vp ) and other endpoint on bd(vq , uq ), contradicting Lemma 3.5.10. So, SP (wp , vk ) and SP (uq , vk ) pass through only the vertices of bd(wp , vq ). Lemma 3.5.13 Let vp wp and vq uq be bounding chords of two disjoint critical polygons polyc (vp ) and polycc (vq ) in P , respectively, where vp ∈ bd(wp , vq ). If P is a weak visibility polygon, then for every vertex vk ∈ bd(vp , vq ), (i) SP (vp , vk ) makes only right turns, (ii) SP (vq , vk ) makes only left turns, and (iii) both SP (vp , vk ) and SP (vq , vk ) pass through only the vertices of bd(vp , vq ). From now on we assume that bd(uq , wp ) and bd(vp , vq ) satisfy Lemmas 3.5.12 and 3.5.13, respectively. Lemma 3.5.12 suggests that there is no critical polygon with the bounding chord ending at two points on bd(uq , wp ). However, it is possible to have a critical polygon, say polycc (vk ), with bounding chord vk uk such that vk ∈ bd(uq , wp ) and uk ∈ bd(wp , vp ) (see Figure 3.19(a)). Similarly, there can be a critical
76
Weak Visibility and Shortest Paths
Figure 3.19 (a) Critical polygons polycc (vk ), polyc (vm ) and polycc (vq ) are disjoint. Similarly, critical polygons polycc (vz ), polyc (vr ) and polyc (vp ) are disjoint. (b) The bounding chords vk uk and vm wm have intersected. Similarly, vz uz and vr wr have intersected.
polygon polyc (vm ) with bounding chord vm wm such that vm ∈ bd(vp , vq ) and wm ∈ bd(wp , vp ). In the following lemma, we establish the relationship between polycc (vk ) and polyc (vm ). Lemma 3.5.14 Let vp wp and vq uq be bounding chords of two disjoint critical polygons polyc (vp ) and polycc (vq ) in P , respectively, where vp ∈ bd(wp , vq ). Let polycc (vk ) and polyc (vm ) be critical polygons with bounding chords vk uk and vm wm , respectively, where vk ∈ bd(uq , wp ) and uk ∈ bd(wp , vp ), vm ∈ bd(vp , vq ) and wm ∈ bd(wp , vp ). If vk uk and vm wm do not intersect, then there is no visibility chord in P . Proof. If two bounding chords vk uk and vm wm do not intersect, then polycc (vk ), polyc (vm ) and polycc (vq ) are three disjoint critical polygons in P (see Figure 3.19(a)). Therefore, P cannot not have a visibility chord by Corollary 3.2.20. Corollary 3.5.15 If P is a weak visibility polygon (Figure 3.19(b)), then vk uk and vm wm intersects and one endpoint of every visibility chord of P belongs to bd(wm , uk ). Let us check whether there exists two disjoint critical polygons polycc (vk ) and polyc (vm ) as stated in Lemma 3.5.14. Scan bd(uq , wp ) from wp in clockwise order (see Figure 3.20(a)) until a vertex vi+1 is located such that vi is the parent of vi+1 in SP T (vp ). Extend vi+1 vi from vi through edges of SP T (wp ) meeting bd(wp , vp ) at ui . Continue the scan to locate another such vertex vk+1 such that (i) vk is the parent −−→ of vk+1 in SP T (vp ), and (ii) − v− k+1 vk intersects vi ui . Then vk uk becomes the current
3.5 Recognizing Weakly Internal Visible Polygons
77
Figure 3.20 (a) By scanning bd(uq , wp ) from wp in clockwise order, polycc (vk ) is located. (b) By scanning bd(vp , vq ) from vp in counterclockwise order, polyc (vm ) is located.
vi ui . This process is repeated till all vertices in bd(uq , wp ) are scanned. Note that to −−→ locate uk , the algorithm first locates the edge of SP (wp , ui ) intersected by v−− k+1 vk by traversing SP (wp , ui ) from ui and then it traverses through the edges of SP T (wp ) till uk is found. Essentially, uk moves in the clockwise direction on bd(wp , vp ) toward wp . Analogously, wm can be located by scanning bd(vp , vq ) from vp in counterclockwise order and by moving wm in the clockwise direction on bd(wp , vp ) (see Figure 3.20(b)). If vk uk and vm wm do not intersect, then there cannot be any visibility chord in P by Lemma 3.5.14 and the algorithm terminates. So we assume that vk uk and vm wm intersect in P . In the following lemma, we state the corresponding lemma to Lemma 3.5.14 for the bounding chord vq uq (see Figure 3.19(a)). Lemma 3.5.16 Let vp wp and vq uq be bounding chords of two disjoint critical polygons polyc (vp ) and polycc (vq ) in P , respectively, where vp ∈ bd(wp , vq ). Let polycc (vz ) and polyc (vr ) be critical polygons with bounding chords vz uz and vr wr , respectively, where vz ∈ bd(vp , vq ) and uz ∈ bd(vq , up ), vr ∈ bd(uq , wp ) and wr ∈ bd(vq , uq ). If vz uz and vr wr do not intersect, then there is no visibility chord in P . Corollary 3.5.17 If P is a weak visibility polygon (Figure 3.19(b)), then vz uz and vr wr intersect and one endpoint of every visibility chord of P belongs to bd(v q , uq ). Corollaries 3.5.15 and 3.5.17 suggest that one endpoint, say s, of every visibility chord st belongs to bd(wm , uk ) and the other endpoint t belongs to bd(wr , uz ) (see Figure 3.19(b)). Locating s and t essentially means constructing two sub-polygons of P partitioned by st. Let Pc and Pcc denote these two sub-polygons, where bd(Pc ) consists of bd(t, s) and st, and bd(Pcc ) consists of bd(s, t) and st. We know that
78
Weak Visibility and Shortest Paths
Figure 3.21 (a) The bounding chords vi ui and vm wm are non-intersecting. (b) The bounding chords vi ui , vk uk and vm wm are mutually intersecting.
bd(uq , wp ) can be included in bd(Pc ). Similarly, bd(vp , vq ) can be included in bd(Pcc ). We also know that bd(Pc ) must include bd(uz , uq ) and bd(wp , wm ). Similarly, bd(Pcc ) must include bd(uk , vp ) and bd(vq , wr ). Let us test whether bd(Pc ) can include bd(uz , uq ). Suppose there exists a counterclockwise C-polygon polycc (vi ) (see Figure 3.21), where vi ∈ bd(uz , uq ) and vi is the parent of vi+1 in SP T (vp ). We have the following cases. Case 1. The ray Case 2. The ray Case 3. The ray
−−→ v−i+1 vi has not intersected vm wm (Figure 3.21(a)). − −−→ vi+1 vi has intersected both vk uk and vm wm (Figure 3.21(b)). − − − → vi+1 vi has not intersected vk uk (Figure 3.22(a)).
−−→ Consider Case 1. Since v−i+1 vi has not intersect vm wm (see Figure 3.21(a)), then there is no visibility chord st in P by Lemma 3.2.18 as no st between bd(wm , uk ) and bd(wr , uz ) can intersect vi ui . So, the algorithm terminates. From now on, we assume that Case 1 has not occurred. −−→ Consider Case 2. Since v−i+1 vi has intersected both v u and vm wm (see Figure k k
3.21(b)), vi ui becomes the new vk uk as any st between bd(wm , uk ) and bd(wr , uz ) must intersect vi ui . So, Case 2 changes uk which means that some consecutive vertices of the previous bd(wm , uk ) have been excluded from the current bd(wm , uk ). Excluded vertices are automatically added to the current bd(uk , vp ). Computing the exact position of ui in Case 2 can be done in the same way as uk has been computed earlier. −−→ Consider Case 3. Since v−i+1 vi has not intersected v u (see Figure 3.22(a)), any k k
st between bd(wm , uk ) and bd(wr , uz ) also intersects vi ui satisfying Lemma 3.2.18. So bd(wm , uk ) remains unchanged.
3.5 Recognizing Weakly Internal Visible Polygons
79
Figure 3.22 (a) The bounding chords vi ui and vk uk are non-intersecting. (b) The point t belongs to bd(vi+1 , uz ).
The above process of testing is also carried out before including bd(wp , wm ) in Pc , bd(uk , vp ) in Pcc and bd(vq , wr ) in Pcc . Observe that this process of testing continues as long as some vertices of the previous bd(wm , uk ) or bd(wr , uz ) have been excluded. If the algorithm does not terminate, then this process of testing ends with new bd(wm , uk ) and bd(wr , uz ) and all the vertices excluded so far have been tested. It can be seen that if the testing is again carried out for the vertices in the present bd(uz , uq ), bd(wp , wm ), bd(uk , vp ) and bd(vq , wr ), Case 1 and Case 2 cannot arise and only Case 3 occurs. Observe that the process of testing always involves a new vertex that has not been tested earlier and it has been excluded only in the previous pass. This observation keeps the recognition algorithm linear. It can be seen that the algorithm is yet to test the vertices of the present bd(w m , uk ) and bd(wr , uz ). Scan bd(wr , uz ) in clockwise order from uz until a vertex vi is found −−→ (see Figure 3.22(b)) such that (i) vi is the parent of vi+1 in SP T (vp ), and (ii) v−i+1 vi does not intersect vm wm . If no such vertex vi exists, it means that st can intersect counterclockwise C-polygons of all reflex vertices in bd(wr , uz ). If such vertex vi exists, then vi+1 can be viewed as the new wr as t must belong to bd(vi+1 , uz ). So, the excluded vertices between new wr (i.e., vi+1 ) and old wr are now added to new bd(vq , wr ) which invokes the process of testing for inclusion of these vertices in Pcc as stated earlier. While including these excluded vertices in Pcc , both Case 1 and Case 2 can occur. If Case 1 occurs, the algorithm terminates. If Case 2 occurs, it changes the current wm , which invokes the process of inclusion of vertices for Pc as stated earlier. Once the cascading process of testing for inclusion in both P c and Pcc is over, it means that new bd(wm , uk ) and bd(wr , uz ) have been computed.
80
Weak Visibility and Shortest Paths
Figure 3.23 (b) The point t belongs to bd(wr , vi−1 ). (c) The visibility chord st is the extension of a cross-tangent between SP (wm , uz ) and SP (wr , uk ).
Once the clockwise scan is over, the algorithm scans the present bd(wr , uz ) in counterclockwise order from wr (see Figure 3.23(a)) until a vertex vi is found such −−→ that (i) vi is the parent of vi−1 in SP T (wp ), and (ii) − vi−1 vi does not intersect vk uk . If no such vertex vi exists, it means that st can intersect clockwise C-polygons of all reflex vertices in bd(wr , uz ). If such vertex vi exists, then vi−1 can be viewed as the new uz as t must belong to bd(wr , vi−1 ). Then the analogous cascading process of testing for inclusion is carried out as stated earlier. If the algorithm does not terminate, it means that new bd(wm , uk ) and bd(wr , uz ) have been computed. Analogous clockwise and counterclockwise scanning of bd(wm , uk ) followed by testing (if required) are carried out until the cascading process of testing for inclusion in both Pc and Pcc is over. Hence, the algorithm computes the final bd(wm , uk ) and bd(wr , uz ). Let us now construct a visibility chord st in P . If SP (wm , uz ) or SP (wm , wr ) or SP (uk , uz ) or SP (uk , wr ) is a segment, then the segment is a visibility chord st. Otherwise, compute a cross-tangent between SP (wm , uz ) and SP (wr , uk ) (see Figure 3.23(b)) and extend its both ends to bd(P ), which is a visibility chord st in P . In the following, we state the major steps for computing a visibility chord st inside P . Step 1. Compute SP T (v1 ) by the algorithm of Ghosh et al. [162]. Step 2. By traversing SP T (v1 ), locate two disjoint critical polygons polyc (vp ) and polycc (vq ) with bounding chords vp wp and vq uq , respectively. Step 3. Compute SP T (vp ), SP T (wp ), SP T (vq ) and SP T (uq ).
3.5 Recognizing Weakly Internal Visible Polygons
81
Step 4. For each vertex vk of bd(uq , wp ), test whether (i) SP (wp , vk ) makes only left turns, and (ii) SP (uq , vk ) makes only right turns. Step 5. For each vertex vk ∈ bd(vp , vq ), test whether (i) SP (vp , vk ) makes only right turns, and (ii) SP (vq , vk ) makes only left turns. Step 6. Test whether SP (uq , wp ) passes through a vertex of bd(vp , vq ) or SP (vp , vq ) passes through a vertex of bd(uq , wp ). Step 7. Locate two critical polygons polycc (vk ) and polyc (vm ) with bounding chords vk uk and vm wm , respectively, where vk ∈ bd(uq , wp ) and uk ∈ bd(wp , vp ), vm ∈ bd(vp , vq ) and wm ∈ bd(wp , vp ). Test whether vk uk and vm wm intersect.
Step 8. Locate two critical polygons polycc (vz ) and polyc (vr ) with bounding chords vz uz and vr wr , respectively, where vz ∈ bd(vp , vq ) and uz ∈ bd(vq , uq ), vr ∈ bd(uq , wp ) and wr ∈ bd(vq , uq ). Test whether vz uz and vr wr intersect. Step 9. Using cascade testing, determine whether (i) bd(uz , wm ) can be included in bd(Pc ), and (ii) bd(uk , wr ) can be included in bd(Pcc ). Step 10. Scan bd(wr , uz ) and bd(wm , uk ) in both clockwise and counterclockwise order to compute the final bd(wr , uz ) and bd(wm , uk ). Step 11. Compute a visibility chord in P by extending a cross-tangent between SP (wm , uz ) and SP (wr , uk ) to bd(P ) and report st. Let us discuss the correctness of the algorithm. It follows from Lemma 3.2.18 that a visibility chord st must intersect all clockwise and counterclockwise C-polygons. At each stage, the algorithm considers a C-polygon Ci and checks whether it forms a disjoint critical polygon with any critical polygons CPi−1 = (C1 , C2 ,..., Ci−1 ) located so far. The algorithm also maintains two common intersection regions implicitly by maintaining bd(wm , uk ) and bd(wr , uz ) formed by the bounding chords of CPi−1 such that one common intersection region can contain s and the other can contain t. If Ci is a disjoint critical polygon with two other mutually disjoint critical polygons Cj and Ck in CPi−1 , the algorithm terminates. If Ci does not intersect either of the two common intersection regions, the algorithm terminates. If Ci intersects one of the two common intersection regions, it updates that common intersection region. If Ci intersects both common intersection regions, it leaves both common intersection regions unchanged. Once all C-polygons are considered, the algorithm constructs st by ensuring that st intersects all C-polygons of P using a cross-tangent between SP (wm , uz ) and SP (wr , uk ). Let us analyze the time complexity of the algorithm. It can be seen that all shortest paths computed in P in Steps 1 and 3 can be done in O(n) time as it involves computing five shortest path trees. Two disjoint critical polygons poly c (vp ) and polycc (vq ) in Step 2 can be located by traversing SP T (v1 ) at most four times. By traversing SP T (vp ), SP T (wp ), SP T (vq ) and SP T (uq ) once, turns at all vertices on bd(uq , wp ) and bd(vp , vq ) can be tested in Steps 4 and 5 in O(n) time. Since uk and uz move only on the clockwise direction in two disjoint portions of the boundary
82
Weak Visibility and Shortest Paths
of P , total cost for updating uk and uz is O(n). Similarly, total cost for updating wm and wr is O(n) as wm and wr move only in the counterclockwise direction on two disjoint portions of the boundary of P . Therefore, Steps 7 and 8 can be performed in O(n) time. Similarly, Steps 9 and 10 take O(n) time. The chord st in Step 11 can be constructed in O(n) time. Therefore, the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 3.5.18 A visibility chord st in a simple polygon P of n vertices can be constructed in O(n) time.
3.6 Computing Shortest Path Trees 3.6.1 In Simple Polygons: O(n) Algorithm In this section, we present an O(n) time algorithm of Guibas et al. [178] for computing Euclidean shortest paths inside a simple polygon P of n vertices from a given point s to all vertices of P . This algorithm is a generalization of the linear time algorithm of Lee and Preparata [235] for computing the shortest path from a point s to another point t inside P . Here, we also present the algorithm of Lee and Preparata. It can be seen that the union of shortest paths from s to all vertices of P form a tree (see Figure 3.24(a)) and it is called the shortest path tree rooted at s (denoted as SP T (s)). Observe that the parent of a vertex v in SP T (s) is the previous vertex u of v in SP (s, v) (see Figure 3.24(a)). The algorithm for computing SP T (s) first triangulates the given simple polygon P (denoted as T (P )). This can be done by the algorithm of Chazelle [71] in O(n) time (see Theorem 1.4.6). Then the algorithm traverses triangle by triangle using the dual graph of T (P ) and it computes the shortest paths from s to the vertices of triangles in T (P ). Thus, the algorithm computes SP T (s) in P . For properties of triangulations of P and their dual graphs, see Section 1.4. Let Ts denote the triangle containing s. So, s can be connected to all three vertices of Ts in SP T (s). Note that s is currently the least common ancestor of the vertices of Ts in SP T (s). Assume that the algorithm has computed SP (s, u) and SP (s, v), where uv is an edge of T (P ) (Figure 3.24(b)). Let w be the least common ancestor of u and v in SP T (s). The region of P bounded by SP (w, u), SP (w, v) and uv is called a funnel F, where w is the apex of the funnel, SP (w, u) and SP (w, v) are the sides of the funnel, and uv is the base of the funnel. Observe that SP (w, u) and SP (w, v) are convex paths facing toward the interior of F . Let 4uvz be the next triangle of F in T (P ). So, z lies outside F and the diagonal uv is not a polygonal edge. The vertex z is called the next vertex of F in T (P ). We have the following observation.
3.6 Computing Shortest Path Trees
83
Figure 3.24 (a) The shortest path tree SP T (s) from a point s to all vertices of P . The vertex u is the parent of the vertex v in SP T (s). (b) The tangent yz splits the funnel F into two funnels Fu and Fv .
Lemma 3.6.1 Let 4uvz be the next triangle in T (P ) of a funnel F , where w is the apex of F and uv is the base of F . Let y be the vertex of F such that yz is the tangent to SP (w, u) or SP (w, v). The vertex y is the parent of z in SP T (s). Proof. Since w is the least common ancestor of u and v in SP T (s) (see Figure 3.24(b)), the line segment joining z and any vertex on SP (s, w), excluding w, does not lie inside P . Therefore, the previous vertex of z on SP (s, z) belongs to F . Since the internal angle at the previous vertex of z on SP (s, z) is reflex by Corollary 3.2.4, the last edge in SP (s, z) is the tangent yz from z to SP (w, u) or SP (w, v). Hence, y is the parent of z in SP T (s). Corollary 3.6.2 If yz is the tangent to both SP (w, u) and SP (w, v), then y = w. The above lemma suggests a procedure for locating the parent of z in SP T (s) as follows. Traverse F starting from u or v (see Figure 3.24(b)) till a vertex y is reached such that yz is the tangent to the side of the funnel at y. Once yz is added to F , F splits into two funnels Fu and Fv . If y ∈ SP (w, u) , then Fu = (SP (y, u), z, y) and Fv = (SP (w, z), SP (v, w)) (see Figure 3.24(b)). Otherwise, Fu = (SP (w, u), SP (z, w)) and Fv = (y, z, SP (v, w)). Note that uz and zv are the bases of Fu and Fv , respectively. It can be seen that after splitting F into two funnels Fu and Fv , both Fu and Fv may have their respective next vertices (see Figure 3.24(b)) and therefore, it is again necessary to split both Fu and Fv by drawing tangents from their respective next vertices. Repeat the process of splitting a funnel as long as it has a next vertex. In other words, the process of splitting funnels terminates when the base of each
84
Weak Visibility and Shortest Paths
funnel is a polygonal edge. Thus, SP T (s) is computed. In the following, we state the major steps of the algorithm for computing SP T (s) in P . Step 1. Triangulate P by the algorithm of Chazelle [71]. Step 2. Locate the given point s in a triangle Ts of T (P ). Assign s as the parent of all three vertices of Ts in SP T (s). Initialize the list of funnels L by these three funnels. Step 3. While a funnel F in L has a next vertex then Step 3a. Let z the next vertex of F . Compute the tangent yz to F and assign y as the parent of z in SP T (s). Step 3b. Add yz to F and split F into two new funnels. Add these two funnels to L. Step 4. Output SP T (s) and Stop. The correctness of the algorithm follows from Lemma 3.6.1. Let us analyze the time complexity of the algorithm. It can be seen that the algorithm runs in O(n) time if the total cost for computing tangents in Step 3a for all funnels is O(n). Suppose the algorithm uses a linear search to locate y in F in Step 3a. It means that y is located by traversing vertices in F starting from u or v. So, the cost for locating y is proportional to the number of vertices traversed in F . Suppose y is the adjacent vertex of v in F and the linear search is performed starting at u (see Figure 3.25(a)). If m is the number of vertices in F , the number of vertices traversed for locating y is m − 1. Now Fu has all vertices of F except v, and z is added to Fu . Hence the size of Fu is same as F . If the same situation again occurs while splitting the funnel Fu , the number of vertices traversed again is m − 1. If such a situation occurs repeatedly for subsequent splitting, the total time required for splitting all funnels can be O(n2 ). Let us consider a special situation. Assume that the dual graph of T (P ) does not have any node of degree 3 (see Figure 3.25(b)). This means that whenever F is split into Fu and Fv by yz, uz or vz is a polygonal edge. Therefore, only one of Fu and Fv can have a next vertex which requires further splitting. If uz is a polygonal edge (see Figure 3.25(b)), a linear search in F can start from u. In that case, the cost for locating y in F is proportional to the size of Fu . Since Fu does not have a next vertex as uz is a polygonal edge, the vertices of Fu are not considered again for subsequent splitting of any other funnel. Similarly, if vz is a polygonal edge, a linear search in F for locating y can start from v instead of u. Using this strategy of choosing the starting vertex of a linear search, the total cost for splitting all funnels can be bounded by O(n) in this special situation. In light of above discussion, let us consider the problem of computing the shortest path SP (s, t) between two given points s and t in P . Let Ts and Tt denote the triangles in T (P ) containing s and t, respectively. Let pst denote the path from Ts
3.6 Computing Shortest Path Trees
85
Figure 3.25 (a) Splitting all funnels takes O(n2 ) time by a linear search. (b) One side of every triangle in the triangulation of P is a polygonal edge.
to Tt in the dual of T (P ). Construct the sub-polygon P 0 of P consisting of only those triangle of T (P ) that are on pst . In Figure 3.25(b), P 0 is same as P as one side of every triangle in T (P ) is a polygonal edge. Since SP (s, t) lies inside P 0 , P 0 can be considered for computing SP (s, t) in place of P . Since the dual graph of T (P 0 ) is a path, the above strategy of linear search can be used for computing SP (s, t) in O(n) time as shown by Lee and Preparata [235]. We have the following theorem. Theorem 3.6.3 The shortest path between two points inside a simple polygon P of n vertices can be computed in O(n) time. Let us return to the discussion on the cost of computing tangent yz in F in Step 3a of the algorithm for computing SP T (s). In order to obtain the desired linear time complexity for computing SP T (s), a different searching strategy for locating y is required at the time of splitting F . Is it possible to perform binary search (instead of a linear search) on F to locate y? Before we answer this question affirmatively, we need a suitable representation of F . Observe that the current funnel F can be maintained as a sorted list [ul , ul−1 , ..., u1 , w, v1 , v2 , ...., vk ], where u0 = v0 = w is the apex of F , and the sides of F are SP (u0 , ul ) = [u0 , ..., ul ] and SP (v0 , vk ) = [v0 , ..., vk ]. The list representing F is stored in a search tree. To perform search for locating the vertex y, store two pointers with each vertex x of F appearing in the search tree, pointing to its two neighbors x0 and x00 in F . This allows to calculate the slope of two edges xx0 and xx00 of F in constant time. By comparing the slopes of xx0 and xx00 with that of xz, it can be decided in constant time on which side of x the binary search should continue in order to locate y. Therefore, this data structures supports searching for
86
Weak Visibility and Shortest Paths
y in O(log(l + k + 1)) time. Since there can be at most O(n) operations of splitting funnels in P , the total time required for splitting all funnels is O(n log n). Although the binary search gives a better time complexity than a linear search, it is still possible to improve the time complexity by storing F in a finger search tree. A finger search tree is essentially a search tree equipped with fingers. A finger is a pointer to an element of the list and searching is performed in the search tree between two fingers. In a search tree, searching starts from the root of the tree, whereas in a finger search tree the searching starts from a finger. For more details on finger search trees, see Mehlhorn [256]. In our application, the fingers are placed at the first and the last node of the tree in symmetric order, i.e., at ul and vk . We now discuss the procedure for locating y in our finger search tree. Let d be the distance from ul to y in F . Observe that the number of nodes in the path Au from ul to y in the finger search tree is O(log d). The next node in the path can be determined from the current node by comparing slopes as stated earlier. If m is the size of F , then y is at a distance m − d from v k in F . So, the number of nodes in the path Av from vk to y in the finger search tree is O(log(m − d)). Using both paths Au and Av , then y can be located as follows. Move from ul to the next node in Au . Move from vk to the next node in Av . Move from the current node to the next node in Au . Move from the current node to the next node in Av and so on, until y is reached either from ul or from vk . So y can be located in O(min(log d, log(m − d)) time. The finger search tree therefore supports searching for the tangent from the next vertex in time O(log δ), where δ is the distance from y to the nearest finger. It also supports operations that split the tree into two sub-trees at y in amortized time O(log δ).
To bound the time required for splitting all funnels recursively using finger search trees, we argue as follows. Let T denote the dual tree of a triangulation of P and it has n − 2 nodes. If s lies in one triangle Ts , take that triangle as the root of T . Otherwise, s is a vertex and lies in several triangles of the given triangulation. There exists at least one triangle with a polygonal edge incident to s and take that triangle as the root of T . Thus each node of T (including the root) has 0, 1, or 2 children. The algorithm is a depth-first traversal of T [15]. We know that the cost for processing the node of x is O(min(log d, log(m − d))), where m is the size of the funnel before the node of x is processed and, d and m − d are the size of two funnels after splitting. Let C ∗ (m) denote the cost of processing the sub-tree rooted at the node of x. So, C ∗ (m) = C ∗ (d) + C ∗ (m − d) + O(min(log d, log(m − d))),
where C ∗ (d) and C ∗ (m − d) denote the cost of processing the sub-trees rooted at the children of the node of x. Taking all possible partitions of m, we obtain the formula
3.6 Computing Shortest Path Trees
87
C ∗ (m) = max1≤d≤m−1 [C ∗ (d) + C ∗ (m − d) + O(min(log d, log(m − d)))].
It can be shown by induction on m that C ∗ (m) is maximum for d = m/2. Therefore, C ∗ (m) ≤ C 0 (m) = 2C 0 (m/2)+ O(log m/2). So, C 0 (m) = O(m) + O(log{(m1 .m2 .m4 ...m2
log m
2
3
)/(21 .22.2 .23.2 .24.2 ...2log m.2
log m−1
)}).
Assuming m is power of 2, C 0 (m) = O(m) + O(log{(mm−1 )/(2m log m+1−m )}) = O(m) + O(log{(mm−1 )/(mm 21−m )}) = O(m) + O(m − 1 − log m).
Hence C ∗ (m) is O(m). So the total time required for splitting all funnels is O(n). Thus the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 3.6.4 The shortest path tree rooted at a point inside a simple polygon P of n vertices can be computed in O(n) time.
3.6.2 In Weak Visibility Polygons: O(n) Algorithm In this section, we present an O(n) time algorithm of Ghosh et al. [162] for computing the shortest path tree from a vertex in a simple polygon P of n vertices without the prior knowledge of a visibility chord in P . If the algorithm terminates without computing the shortest path tree, it means that P is not a weak visibility polygon because it does not satisfy the characterization of weak visibility polygons presented in Theorem 3.2.14. If the algorithm computes the shortest path tree, P may or may not have a visibility chord. The algorithm computes the shortest path tree by scanning the boundary of P using simple data structures. This algorithm can be viewed as a preprocessing step for recognizing weak visibility polygons as shown in Sections 3.5.1 and 3.5.2. Exercise 3.6.1 Assume that a simple polygon P of n vertices is given along with a visibility chord. Design an O(n) time algorithm for computing the shortest path tree from a vertex of P by scanning the boundary of P [162]. We assume that the vertices of the given simple polygon P are labeled v1 , v2 , . . . , vn in counterclockwise order. The algorithm chooses v1 as the root and then computes SP T (v1 ). In presenting the algorithm, we use the same notations and definitions introduced in Section 3.3.1. The algorithm starts by scanning bdcc (v2 , vn ) in counterclockwise order, and computes SPcc (v1 , v2 ), SPcc (v1 , v3 ),..., SPcc (v1 , vn−1 ) (see Figure 3.26(a)). During the counterclockwise scan, if it is found that SP (v 1 , vi−1 ) does not make only right turns for some vertex vi−1 (i.e., SP (v1 , vi−1 ) 6= SPcc (v1 , vi−1 )),
88
Weak Visibility and Shortest Paths
Figure 3.26 (a) SPcc (v1 , vi ) = (SPcc (v1 , vk ), vi ). (b) SPcc (v1 , vi ) = (SPcc (v1 , vi−1 ), vi ). (c) There is a reverse turn at vi−1 .
then the algorithm marks the vertex vi−1 as vcc (see Figure 3.26(c)), and starts the clockwise scan from vn for computing SPc (v1 , vn−1 ), SPc (v1 , vn−2 ),..., SPc (v1 , v2 ). During the clockwise scan, if it is found that SPc (v1 , vi−1 ) does not make only left turns for some vertex vi−1 (i.e., SP (v1 , vi−1 ) 6= SPc (v1 , vi−1 )), then the algorithm marks the vertex vi−1 as vc . If the counterclockwise scan reaches vn , then SP Tcc (v1 , vn ) is SP T (v1 ) (see Figure 3.26(a)). Similarly, if the clockwise scan reaches v2 , then SP Tc (v1 , v2 ) is SP T (v1 ). Otherwise, the algorithm has located vcc and vc . We say that there are reverse turns at vcc and vc . Let us explain the procedure for locating vcc during the counterclockwise scan. The vertex vc can be located by the analogous procedure. Assume that SPcc (v1 , v2 ), SPcc (v1 , v3 ),..., SPcc (v1 , vi−1 ) have been computed and the procedure wants to compute SPcc (v1 , vi ). Let uj denote the parent of vj in SP Tcc (v1 , vi−1 ). We have the following cases. −− −−−→ Case 1. The vertex vi lies to the left of u i−1 vi−1 (Figure 3.26(a)). −− −−−→ Case 2. The vertex vi lies to the right of u i−1 vi−1 . −−−→ Case 2a. The vertex vi lies to the right of v−− i−2 vi−1 (Figure 3.26(b)). − − − − → Case 2b. The vertex vi lies to the left of vi−2 v− i−1 (Figure 3.26(c)). −− −−−→ Consider Case 1. Since vi lies to the left of u i−1 vi−1 (see Figure 3.26(a)), SPcc (v1 , vi ) makes only right turns. Let vk be the first vertex of SPcc (v1 , vi−1 ) starting from → vi−1 such that vi lies to the right of − u− k vk . Therefore, vk becomes the parent ui of vi in SP Tcc (v1 , vi ) as vi vk is the tangent from vi to SPcc (v1 , vi−1 ). Hence, SPcc (v1 , vi ) = (SPcc (v1 , vk ), vi ).
3.6 Computing Shortest Path Trees
89
Figure 3.27 (a) The vertex vc belongs to bdcc (v1 , vcc ). (b) The vertex vc does not belong to bdcc (v1 , vcc ).
−− −−−→ −−−−−→ Consider Case 2a. Since vi lies to the right of both u i−1 vi−1 and vi−2 vi−1 (see Figure 3.26(b)), it means that SPcc (v1 , vi ) makes only right turns, and vi−1 is the parent ui of vi in SP Tcc (v1 , vi ) as vi vi−1 is the tangent from vi to SPcc (v1 , vi−1 ). So, SPcc (v1 , vi ) = (SPcc (v1 , vi−1 ), vi ). −− −−−→ −−−−−→ Consider Case 2b. Since vi lies to the right of u i−1 vi−1 and to the left of vi−2 vi−1 (see Figure 3.26(c)), SP (v1 , vi−1 ) passes through vertices of bdcc (vi , vn−1 ) and therefore, SP (v1 , vi−1 ) and SPcc (v1 , vi−1 ) are not same. The vertex vi−1 is marked as vcc . Exercise 3.6.2 Let v be a vertex of a simple polygon P of n vertices. Assume that the shortest path from v to each vertex of P does not make a right turn at any vertex in the path. Design an O(n) time algorithm to compute the shortest path tree in P from the next counterclockwise vertex of v by scanning the boundary of P .
From now on we assume that the algorithm has located vc and vcc , and has computed SP Tc (v1 , vc ) and SP Tcc (v1 , vcc ). We have the following two cases. Case A. The vertex vc belongs to bdcc (v1 , vcc ) (Figure 3.27(a)). Case B. The vertex vc does not belong to bdcc (v1 , vcc ) (Figure 3.27(b)). It will be shown later that Case A can be solved using the method presented for Case B. Consider Case B. From the definitions of vc and vcc , it is clear that SPc (v1 , vc ) is not SP (v1 , vc ) as SP (v1 , vc ) passes through at least a vertex of bdcc (v1 , vc ). Similarly, SPcc (v1 , vcc ) is not SP (v1 , vcc ) as SP (v1 , vcc ) passes through
90
Weak Visibility and Shortest Paths
at least a vertex of bdc (v1 , vcc ). We have the following observation on the relationship of vc and vcc with a visibility chord st in P . Lemma 3.6.5 Let v1 , vc and vcc be any three vertices of P such that SP (v1 , vcc ) and SP (v1 , vc ) pass through a vertex of bdc (v1 , vcc ) and bdcc (v1 , vc ), respectively. If P is weakly visible from a chord st, then one endpoint of st lies on bd cc (v1 , vcc ) and the other endpoint of st lies on bdc (v1 , vc ). Proof. Since SP (v1 , vcc ) passes through a vertex of bdc (v1 , vcc ) (see Figure 3.27(b)), st must intersect the eave vi vj of SP (v1 , vcc ) by Lemma 3.2.16, where vi ∈ bdcc (v1 , vcc ) and vj ∈ bdc (v1 , vcc ). Therefore, one endpoint of st lies on bdcc (v1 , vcc ). The arguments also hold for the special situation when vi = v1 . Analogous arguments show that the other endpoint of st lies on bdc (v1 , vc ). Corollary 3.6.6 The vertex v1 belongs to one sub-polygon of st, and vertices vc and vcc belong to the other sub-polygon of st. Corollary 3.6.7 For any vertex vk ∈ bdcc (vcc , vc ), SP (vc , vk ) makes only left turns and SP (vcc , vk ) makes only right turns. Corollary 3.6.7 suggests the next step of the algorithm. Scan bdcc (vcc , vc ) in counterclockwise order and compute SP Tcc (vcc , vc ). If a reverse turn is encountered during the scan, i.e., Corollary 3.6.7 does not hold, the algorithm terminates as there is no visibility chord in P . So, we assume that SP Tcc (vcc , vc ) has been computed. Analogously, scan bdc (vc , vcc ) in clockwise order and compute SP Tc (vc , vcc ). Hence, four trees SP Tcc (v1 , vcc ), SP Tcc (vcc , vc ), SP Tc (v1 , vc ) and SP Tc (vc , vcc ) have been computed. The above four partial trees computed by the algorithm can be merged to compute SP T (v1 ). We know that SPc (vc , vcc ) and SPcc (v1 , vcc ) are intersecting (see Figure 3.27(b)). So, the two paths SPc (vc , vcc ) and SPcc (v1 , vcc ) share a point other that vcc . It can be seen in Figure 3.28(a) that SPc (vc , vcc ) and SPcc (v1 , vcc ) meet only at vcc but two paths cannot be called non-intersecting as the previous vertices of vcc in the two paths are in the reverse order at vcc . So, we need a proper definition of intersecting paths. For any vertex vk ∈ bdcc (v1 , vcc ), two convex paths SPc (vc , vk ) = (vc , ..., wk , vk ), and SPcc (v1 , vk ) = (v1 , ..., uk , vk ) are said to be inter→ secting if wk lies to the right of − u− k vk (see Figure 3.28). In order to rectify the intersection of SPc (vc , vcc ) and SPcc (v1 , vcc ), a vertex vm ∈ bdcc (v2 , vcc ) is located such that (i) SPc (vc , vm ) and SPcc (v1 , vm ) are not intersecting, and (ii) SPc (vc , vm+1 ) and SPcc (v1 , vm+1 ) are intersecting (see Figure 3.27(b)). Note that no such vertex vm exists for the polygon in Figure 3.28(a) and therefore, this polygon does not have any visibility chord. From now on we assume that vm always exists (see Figure 3.27(b)). We have the following observations.
3.6 Computing Shortest Path Trees
91
Figure 3.28 (a) Two paths SPcc (v1 , vcc ) and SPc (vc , vcc ) intersect. (b) A reverse turn is encountered at vk before vm is reached.
Lemma 3.6.8 Let vk be a vertex of bdcc (v1 , vcc ). If SPc (vc , vk ) and SPcc (v1 , vk ) intersect, then SP (v1 , vk ) contains an eave. Proof. Proof follows from the definition of intersecting paths. Lemma 3.6.9 If st is a visibility chord of P , where s ∈ bdcc (v1 , vcc ) and t ∈ bdc (v1 , vc ), then every path in SP Tc (vc , s) makes only left turns and every path in SP Tcc (vcc , t) makes only right turns. Proof. Proof follows from Theorem 3.2.13 (see Figure 3.27(b)). Lemma 3.6.9 suggests a method to locate vm . The merging procedure scans bdc (vcc , v1 ) in clockwise order starting from vcc and it computes SPc (vc , vk ), where vk is the current vertex under consideration. If SPc (vc , vk ) and SPcc (v1 , vk ) are non-intersecting, then vk is vm (see Figure 3.27(b)). Otherwise, vk−1 becomes the current vertex under consideration. During the scan, if a reverse turn is encountered at vk (see Figure 3.28(b)), s belongs to bdc (vcc , vk ) by Lemmas 3.6.5 and 3.6.9. On the other hand, there is no chord connecting a point of bdc (vcc , vk ) to another point of bdc (v1 , vc ) in P . Therefore, there is no visibility chord in P and the algorithm terminates. From now on we assume that vm is reached by the algorithm by scanning bdc (vcc , v1 ). Exercise 3.6.3 Let Q1 and Q2 be two disjoint convex polygons of m1 and m2 vertices. Let a ∈ Q1 and b ∈ Q2 be two vertices such that Q1 and Q2 lie on the opposite sides of the line drawn through a and b. The segment ab is called a cross-tangent between Q1 and Q2 . Design an algorithm for locating both cross-tangents between Q1 and Q2 in O(m1 +m2 ) time [291].
92
Weak Visibility and Shortest Paths
Figure 3.29 (a) The parent uj of vj in SP Tc (vc , vm+1 ) becomes the current vj . (b) The parent ui of vi in SP Tcc (v1 , vm ) becomes the current vi .
After locating vm , the merging procedure draws the cross-tangent vi vj between SPc (vc , vm+1 ) and SPcc (v1 , vm ), where vi ∈ SPcc (v1 , vm ) and vj ∈ SPc (vc , vm+1 ) (see Figure 3.27b). So, vi is the parent of vj in SP Tcc (v1 , vj ). Concatenate the subtree at vj of SP Tc (vc , vm+1 ) as the subtree at vj in SP Tcc (v1 , vj ). Let us explain how the cross-tangent vi vj is computed. Assign vm+1 to vj . Assign the parent of vm in SP Tcc (v1 , vm ) to vi . If the parent uj of vj in SP Tc (vc , vm+1 ) lies → to the right of − v− i vj (see Figure 3.29(a)), then assign uj to vj . Otherwise, if vj lies to − − → the left of ui vi (see Figure 3.29(b)), where ui is the parent of vi in SP Tcc (v1 , vm ), assign ui to vi . This process is repeated till vi vj becomes the cross-tangent, i.e., SPc (vc , vm+1 ) and SPcc (v1 , vm ) lie on opposite sides of the line drawn through vi and vj . After computing SP Tcc (v1 , vj ), the merging procedure analogously locates the vertex vk ∈ bdc (v1 , vc ) by scanning bdc (v1 , vc ) in clockwise order starting from vc (see Figure 3.27(b)) such that (i) SPc (v1 , vk ) and SPcc (vcc , vk ) are non-intersecting, and (ii) SPc (v1 , vk−1 ) and SPcc (vcc , vk−1 ) are intersecting. Then the merging procedure locates the cross-tangent vp vq between SPc (v1 , vk ) and SPcc (vcc , vk−1 ), where vp ∈ SPc (v1 , vk ) and vq ∈ SPcc (vcc , vk−1 ). Finally, SP Tc (v1 , vk ) is extended to SP Tc (v1 , vq ). Exercise 3.6.4 Draw a figure showing SP Tcc (v1 , vj ) and SP Tc (v1 , vq ) are overlapping. After computing SP Tcc (v1 , vj ) and SP Tc (v1 , vq ), the procedure checks whether they are disjoint or overlapping. Let va and vb be the next vertex of v1 in SPcc (v1 , vj ) → and SPc (v1 , vq ), respectively. If vb lies to the left of v−− 1 va , then SP Tcc (v1 , vj ) and
3.6 Computing Shortest Path Trees
93
SP Tc (v1 , vq ) are disjoint (see Figure 3.27(b)). Otherwise, they are overlapping. We have the following observations. Lemma 3.6.10 If SP Tcc (v1 , vj ) and SP Tc (v1 , vq ) are disjoint, then (i) for every vertex vd ∈ bdc (v1 , vq ), SPc (v1 , vd ) is same as SP (v1 , vd ), and (ii) for every vertex vd ∈ bdcc (v1 , vj ), SPcc (v1 , vd ) is same as SP (v1 , vd ). Lemma 3.6.11 If SP Tcc (v1 , vj ) and SP Tc (v1 , vq ) are overlapping, then there is no visibility chord in P . Exercise 3.6.5 Prove Lemma 3.6.11. From now on, we assume that SP Tcc (v1 , vj ) and SP Tc (v1 , vq ) are disjoint. Extend vi vb from vb to bdc (vq , vj ) meeting it at z (see Figure 3.27(b)). The merging procedure scans bdcc (vj , z) in counterclockwise order starting from vj and computes SP Tcc (v1 , z) by drawing a tangent from the current vertex vr to SPcc (v1 , vr−1 ). Note that the tangent from vr can be computed by the procedure stated earlier in Case 1 and Case 2a. A reverse turn in Case 2b can be avoided by computing the cross-tangent between SPc (vc , vr ) and SPcc (v1 , vr−1 ) as stated earlier. Observe that while locating the cross-tangent, some vertices of bdcc (vj , z) are skipped when the current vertex vr is assigned to its parent in SP Tc (vc , vr ). As before, appropriate sub-trees of SP Tc (vc , vj ) at some of these skipped vertices are concatenated to complete the construction of SP Tcc (v1 , z). Similarly, SP Tc (v1 , vq ) is extended to SP Tc (v1 , z) with the help of SP Tcc (vcc , vq ). Hence, the union of SP Tc (v1 , z) and SP Tcc (v1 , z) gives SP T (v1 ). Consider Case A. In this case, vc belongs to bdcc (v1 , vcc ) (see Figure 3.27(a)). The algorithm checks whether SP Tc (v1 , vcc ) and SP Tcc (v1 , vc ) are disjoint or overlapping. If they are disjoint, the algorithm locates the intersection point z as before by extending the first edge of SPc (v1 , vcc ) to bdcc (vc , vcc ). Then the algorithm takes the union of SP Tc (v1 , z) and SP Tcc (v1 , z) to construct SP T (v1 ). Consider the other situation when SP Tc (v1 , vcc ) and SP Tcc (v1 , vc ) are overlapping (see Figure 3.27(a)). Let va and vb be the next vertex of v1 in SPcc (v1 , vcc ) and SPc (v1 , vc ), respectively. It can be seen that if bd(P ) intersects both v1 va and v1 vb , then there is no visibility chord in P by Lemma 3.2.17 as there are more than one eave in SP (v1 , vcc ) or SP (v1 , vc ). So, we assume that bd(P ) intersects either v1 vb or v1 va . Consider the situation when bd(P ) intersects v1 vb but does not intersect v1 va (see Figure 3.27(a)). Scan bdc (z, vc ) in counterclockwise order until a vertex vk ∈ bdc (vcc , vc ) is found such that (i) SPc (z, vk ) and SPcc (v1 , vk ) are not intersecting, and (ii) SPc (z, vk+1 ) and SPcc (v1 , vk+1 ) are intersecting. If no such vertex vk exists, it means that SPc (v1 , vcc ) and SPcc (v1 , vc ) have overlapped more than once and therefore, there are two or more eaves in SP (v1 , vcc ) or SP (v1 , vc ). By Lemma 3.2.17, there is no visibility chord in P . So, we assume that vk exists.
94
Weak Visibility and Shortest Paths
Draw the cross-tangent between SPc (z, vk+1 ) and SPcc (v1 , vk ) and using the crosstangent, complete the construction of SP T (v1 ) by choosing the appropriate subtrees as discussed earlier. The other situation, i.e, when bd(P ) intersects v 1 va but does not intersect v1 vb , can be handled analogously. In the following, we state the major steps of the algorithm for computing SP T (v 1 ) in P under the assumption that both vc and vcc exist, and vcc ∈ bdcc (v1 , vc ) (i.e., Case B). Step 1. Scan bd(P ) in counterclockwise order and compute SP Tcc (v1 , vcc ), where the reverse turn is encountered at the vertex vcc . Step 2. Scan bd(P ) in clockwise order and compute SP Tc (v1 , vc ), where the reverse turn is encountered at the vertex vc . Step 3. Scan bdcc (vcc , vc ) in counterclockwise order and compute SP Tcc (vcc , vc ). If a reverse turn is encountered at some vertex of bdcc (vcc , vc ) then goto Step 12. Step 4. Scan bdc (vc , vcc ) in clockwise order and compute SP Tc (vc , vcc ). If a reverse turn is encountered at some vertex of bdc (vc , vcc ) then goto Step 12. Step 5. Let vm be a vertex of bdc (vcc , v1 ) such that (i) SPc (vc , vm ) and SPcc (v1 , vm ) are non-intersecting, and (ii) SPc (vc , vm+1 ) and SPcc (v1 , vm+1 ) are intersecting. Scan bdc (vcc , v1 ) in clockwise order and extend SP Tc (vc , vcc ) to SP Tc (vc , vm ). If no such vertex vm exists or a reverse turn is encountered before reaching vm then goto Step 12. Step 6. Compute the cross-tangent vi vj between SPc (vc , vm+1 ) and SPcc (v1 , vm ), where vi ∈ SPcc (v1 , vm ) and vj ∈ SPc (vc , vm+1 ). Assign vi as the parent of vj in SP Tcc (v1 , vj ). Concatenate the sub-tree at vj of SP Tc (vc , vm+1 ) as the sub-tree rooted at vj in SP Tcc (v1 , vj ). Step 7. Let vk be a vertex of bdc (v1 , vc ) such that (i) SPc (v1 , vk ) and SPcc (vcc , vk ) are non-intersecting, and (ii) SPc (v1 , vk−1 ) and SPcc (vcc , vk−1 ) are intersecting. Scan bdc (vc , v1 ) in clockwise order and extend SP Tcc (vcc , vc ) to SP Tcc (vcc , vk ). If no such vertex vk exists or a reverse turn is encountered before reaching vk then goto Step 12. Step 8. Compute the cross-tangent vp vq between SPc (v1 , vk ) and SPcc (vcc , vk−1 ), where vp ∈ SPc (v1 , vk ) and vq ∈ SPcc (vcc , vk−1 ). Assign vq as the parent of vp in SP Tc (v1 , vq ). Concatenate the sub-tree at vq of SP Tcc (vcc , vc ) as the sub-tree rooted at vq in SP Tc (v1 , vq ). Step 9. If SP Tc (v1 , vq ) and SP Tcc (v1 , vj ) are overlapping then goto Step 12. Step 10. Extend the first edge of SPc (v1 , vq ) to bdc (vq , vj ) meeting it at a point z. Extend SP Tc (v1 , vq ) to SP Tc (v1 , z) using SP Tcc (vcc , vq ). Extend SP Tcc (v1 , vj ) to SP Tcc (v1 , z) using SP Tc (vc , vj ). Step 11. Output the union of SP Tc (v1 , z) and SP Tcc (v1 , z) as SP T (v1 ) and Stop. Step 12. Report that there is no visibility chord in P and Stop.
3.7 Recognizing Weakly External Visible Polygons
95
Let us discuss the correctness of the algorithm. Steps 1 and 2 identify two vertices of P as vcc and vc in the counterclockwise and clockwise scans, respectively, where vcc ∈ bdcc (v1 , vc ). As there are reverse turns at vcc and vc , one endpoint (say, s) of any visibility chord st in P belongs to bdcc (v1 , vcc ) and the other endpoint t belongs to bdc (v1 , vc ) by Lemma 3.6.5. So, all vertices in bdcc (vcc , vc ) belong to the same sub-polygon of st by Corollary 3.6.6. Therefore, the shortest paths from vcc and vc to any vertex of bdcc (vcc , vc ) must be convex by Corollary 3.6.7, which are checked in Steps 3 and 4. Consider a vertex vm+1 ∈ bdcc (v1 , vcc ) such that there is an eave in SP (v1 , vm+1 ). Since st intersects every eave in SP T (v1 ) by Lemma 3.2.16, v1 and vm+1 must belong to different sub-polygons of st. So, s belongs to bdcc (v1 , vm+1 ) and by Lemma 3.6.9, SP (vc , vm+1 ) makes only left turns. Step 5 locates the edge vm vm+1 by scanning bdc (vcc , v1 ) in clockwise order such that SPcc (v1 , vm ) is convex but SPcc (v1 , vm+1 ) is not convex. Step 6 locates the eave vi vj in SPcc (v1 , vm+1 ) by drawing the cross-tangent between SPcc (v1 , vm ) and SPc (vc , vm+1 ) and extends SP Tcc (v1 , vm ) to SP Tcc (v1 , vj ). Analogously, Steps 7 and 8 construct SP Tc (v1 , vq ). Step 9 checks whether SP Tcc (v1 , vj ) and SP Tc (v1 , vq ) are overlapping. If they are overlapping, P cannot have a visibility chord by Lemma 3.6.11 since either SP (v1 , vcc ) or SP (v1 , vc ) must have two or more eaves. If they are disjoint, then the paths in SP Tcc (v1 , vj ) and SP Tc (v1 , vq ) are the shortest paths in P by Lemma 3.6.10. The algorithm completes the construction of SP T (v 1 ) in Steps 10 and 11. It can be seen that the algorithm runs in O(n) time since the vertices of P are scanned at most four times. We summarize the result in the following theorem. Theorem 3.6.12 The shortest path tree rooted at a vertex of a simple polygon P of n vertices can be computed in O(n) time without the prior knowledge of a visibility chord of P .
3.7 Recognizing Weakly External Visible Polygons In this section, we present an O(n) time algorithm of Bhattacharya et al. [53] for computing a line segment pq outside a given simple polygon P such that P is weakly externally visible from pq. A polygon P is called weakly externally visible if every point on the boundary of P is visible from some point on the convex hull of P (see Figure 3.4(b)). This means that a ray can be drawn from each boundary point of P such that the ray does not intersect the interior of P . In the following, we present a recognition algorithm of P that runs in O(n) time. Step 1. Compute the convex hull of P by the algorithm of Graham and Yao [175] (see Figure 3.30(a)). Let C = (c1 , c2 , ..., ck ) denote the convex hull of P where ci+1 is the next counterclockwise vertex of c1 . Step 2. Scan bd(P ) in counterclockwise order (see Figure 3.30(a)) and compute the
96
Weak Visibility and Shortest Paths
Figure 3.30 (a) The boundary of P is weakly visible from the convex hull edges of P . (b) The boundary of P is weakly visible from both p1 q1 and p2 q2 .
shortest path tree SP Tcc (c1 ) rooted at c1 by the scanning procedure mentioned in Section 3.6.2 as Case 1 and Case 2. Avis and Toussaint [42]. Analogously, scan bd(P ) in clockwise order (see Figure 3.30(b)) and compute SP Tc (c1 ). Step 3. If any reverse turn is encountered during either scan then report that P is not weakly externally visible else report SP Tcc (c1 ) and SP Tc (c1 ). Once we know that P is weakly externally visible, the problem is now to construct a segment pq such that P is also weakly externally visible from pq. Two vertices ci and cj are said to be antipodal if there exists two parallel lines passing through ci and cj such that they do not intersect the interior of P [291]. In the following lemma, we establish a property of pq. Exercise 3.7.1 Prove that there are at most 3m/2 antipodal pairs of vertices in a convex polygon of m vertices [291]. Lemma 3.7.1 If P is weakly externally visible from a line segment p1 q1 , then P is also weakly externally visible from another line segment p2 q2 which passes through a vertex of the convex hull of P . Proof. We prove only for the case when p1 q1 and the convex hull of P are disjoint (see Figure 3.30(b)). Let ci be a vertex of the convex hull of P such that the triangle formed by three segments p1 q1 , p1 ci and q1 ci contains P . Observe that such a vertex ci always exists as P is weakly externally visible from p1 q1 . Translate p1 q1 parallel to itself toward the interior of the triangle till it touches a vertex cj of the convex hull of P . Let p2 ∈ p1 ci and q2 ∈ q1 ci be the endpoints of the translated segment
3.7 Recognizing Weakly External Visible Polygons
97
Figure 3.31 (a) P is weakly externally visible form pq. (b) The points p and q are moved to the points of intersection of the rays and L1 .
passing through cj . It can be seen that P is also weakly externally visible from p2 q2 .
Corollary 3.7.2 The vertices ci and cj are antipodal vertices of P . Suppose a line L1 is given and it passes through a vertex cj of the convex hull of P (see Figure 3.31(a)). Assume that P is weakly externally visible from L 1 . We wish to locate the positions of p and q on L1 closest to cj such that P is weakly externally visible from pq. Let ci be an antipodal vertex of cj such that a line parallel to L1 touches ci . Assign → p to the intersection point of L1 and c−i−c− i+1 . Similarly, assign q to the intersection → point of L1 and c−i−c− i−1 . If P is weakly externally visible from pq, then p and q are located correctly. Observe that the polygonal boundary bd(cj , ci ) is visible from qcj and the remaining polygonal boundary bd(ci , cj ) is visible from pcj . Note that pq satisfies Lemma 3.7.1. Consider the other situation when P is not weakly externally visible from the current pq (see Figure 3.31(b)). This means that pcj cannot see the entire polygonal boundary of bd(ci , cj ) or qcj cannot see the entire polygonal boundary of bd(cj , ci ). Consider the later situation. Move q along L1 away from cj to the point q 0 such that q 0 cj sees the entire polygonal boundary of bd(cj , ci ) (see Figure 3.31(b)). It can be −−−→ seen that q 0 is the intersection point of L1 and v−− m vm−1 , where vm vm−1 is an edge on the polygonal boundary of bd(cj , ci ). Observe that vm−1 is the parent of vm in SP Tcc (cj ), where SP Tcc (cj ) is the union of (i) the sub-tree of SP Tcc (c1 ) rooted at cj , and (ii) the sub-tree of SP Tc (c1 ) rooted at cj . Analogously, p can be moved along L1 away from cj till the point p0 such that p0 cj sees the entire polygonal boundary bd(ci , cj ) (see Figure 3.31(b)). This means that p0 is the intersection point of L1
98
Weak Visibility and Shortest Paths
Figure 3.32 (a) The line L1 is rotated around cj in the counterclockwise direction to L01 . (b) The right envelope (ci , cj ) is the locus of the point q along rays.
−−→ and some − v− k vk+1 , where vk vk+1 is an edge on the polygonal boundary of bd(ci , cj ) and vk+1 is the parent of vk in SP Tc (cj ). The segment p0 q 0 becomes new pq as P is weakly externally visible from p0 q 0 . The above discussion shows how to locate the segment pq on a given line L1 . Let denote another line passing through cj (see Figure 3.32(a)) such that there exists a line parallel to L01 that passes through ci and does not intersect the interior of P . So, L01 can be viewed as the new position of L1 after L1 is rotated around cj (say, in the counterclockwise direction) and ci remains the antipodal vertex of cj with respect −−→ −−−−−→ to L01 . Let p0 (or q 0 ) denote the intersection point of − v− k vk+1 (respectively, vm vm−1 ) 0 0 −−→ with L1 . This rotation from L1 to L1 can also be achieved by moving p along v−− k vk+1 0 0 −−−→ away from vk and q along v−− m vm−1 toward vm such that (i) the new segment p q still passes through cj , and (ii) ci remains the antipodal vertex of cj . Observe that though P is weakly externally visible from pq, P may not be weakly externally visible from p0 q 0 . For example, P is weakly externally visible from p0 q 0 in Figure 3.32(a) but not in Figure 3.32(b). This can happen if the polygonal boundaries of bd(ci , cj ) and bd(cj , ci ) are not weakly visible from p0 cj and q 0 cj , respectively. L01
Suppose q 0 cj cannot see the entire polygonal boundary of bd(cj , ci ) (see Figure 3.32(b)). This means that q must move away from cj along L01 to the intersection −−→ point of L01 with some ray − v− s vs−1 , where vs−1 is the parent of vs in SP Tcc (cj ) and −−→ vs vs−1 is an edge on bd(vm , ci ). Let z2 be the intersection point of v−− s vs−1 and −−−→ v−− m vm−1 . In order to see the entire polygonal boundary of bd(c j , ci ) continuously, q −−−→ −−−−→ must follow v−− m vm−1 toward vm till it reaches z2 and then it has to follow vs vs−1 toward vs . Thus q can be moved along rays through their intersection points which gives the locus of q. In other words, the locus of q is the boundary of the intersection −−−→ −−−−→ of the left half-planes of these rays v−− m vm−1 , vs vs−1 .... emitted from the vertices on
3.7 Recognizing Weakly External Visible Polygons
99
Figure 3.33 (a) P is not weakly externally visible from any segment. (b) The right envelope (ci , cj ) consists of segments ci z1 , z1 z2 ,..., zs−1 zs , zs y.
the polygonal boundary of bd(cj , ci ). Analogously the locus of p is the boundary of −−→ the right half-planes of rays like − v− k vk+1 emitted from the vertices on the polygonal boundary of bd(ci , cj ). The above discussion suggests a method to locate pq passing through cj without any given line like L1 or L01 . Take any antipodal vertex ci of cj . Construct the envelope of the intersection of the left half-planes of the rays by traversing bd(cj , ci ) in clockwise order starting from ci ; call it right envelope (ci , cj ). Analogously, construct the envelope of the intersection of the right half-planes of the rays by traversing bd(ci , cj ) in counterclockwise order starting from ci ; call it left envelope (ci , cj ). We have the following lemma for locating pq. Lemma 3.7.3 Let ci and cj form an antipodal pair of vertices of P . Any segment through cj which connects a point (say, q) of the right envelope (ci , cj ) to a point (say, p) of the left envelope (ci , cj ) is the segment pq from which P is weakly externally visible. Exercise 3.7.2 Prove Lemma 3.7.3. Assume that no pair of points p and q satisfy Lemma 3.7.3 (see Figure 3.33(a)). Then the algorithm considers another antipodal pair and tries to construct pq by constructing left and right envelopes for this antipodal pair. By repeating the process for all antipodal pairs (ci , cj ) of the convex hull of P , the algorithm can locate a segment pq (if it exists) from which P is weakly externally visible. Since there are at most 2n antipodal pairs in P and constructing the left and right envelopes for an antipodal pair takes O(n) time as shown below, the algorithm takes O(n2 ) time in the worst case to construct pq.
100
Weak Visibility and Shortest Paths
Figure 3.34 (a) The current ray intersects the last ray of right envelope (c i , cj ). (b) The current ray intersects an intermediate segment of right envelope (ci , cj ).
Let us explain the procedure for constructing the right envelope (ci , cj ) (see Figure → 3.33(b)). Initialize the right envelope (ci , cj ) by c−i−c− i−1 . Scan the polygonal boundary bd(cj , ci ) in clockwise order starting from ci until a vertex vm is located such that −−−→ vm−1 is the parent of vm in SP Tcc (cj ). Let z1 be the intersection point of − v− m vm−1 − − − → and ci ci−1 . The current right envelope (ci , cj ) is the segment ci z1 followed by − z→ 1 y, where z1 lies on the segment yvm . So the current right envelope (ci , cj ) consists of segments starting for c1 , where the last segment ending at y represents a ray. Assume that the current right envelope (ci , cj ) consists of segments ci z1 , z1 z2 ,..., −−−→ zs−1 zs , zs y. Let v−− m vm−1 be the current ray under consideration. We have the following cases. −−−→ −→ −−−−−→ Case 1. The point zs lies to the left of v−− m vm−1 , and zs y does not intersect vm vm−1 (see Figure 3.33(b)). The right envelope (ci , cj ) remains unchanged. −−−−−→ Case 2. Two rays − z→ s y and vm vm−1 intersect (see Figure 3.34(a)). Call the intersection point as zs+1 . Update the current right envelope (ci , cj ) by replacing zs y by zs zs+1 . Choose a point y, where zs+1 lies on the segment vm y. Append zs+1 y to the right envelope (ci , cj ). −−−→ Case 3. The point zs lies to the right of v−− m vm−1 (see Figure 3.34(b)). Scan the right −−−→ envelope (ci , cj ) from zs till zt is located such that v−− m vm−1 intersect zt zt+1 at a point x. Delete all segments of the right envelope (ci , cj ) from zt+1 zt+2 to zs y. Replace zt zt+1 by zt x. Choose a point y, where x lies on the segment vm y, and append xy to the right envelope (ci , cj ). Once all such vertices vm on bd(cj , ci ) are considered, the procedure has constructed the right envelope (ci , cj ). Analogously, the left envelope (ci , cj ) can be constructed by scanning vertices on the polygonal boundary of (ci , cj ). After con-
3.7 Recognizing Weakly External Visible Polygons
101
structing both envelopes of (ci , cj ) the procedure locates pq, if it exists. Hence, constructing pq for an antipodal pair can be done in O(n) time. Instead of constructing the left and right envelopes in O(n) time for each antipodal pair, both envelopes for all antipodal pairs can be constructed in O(n) as follows. Assume that the algorithm could not find any segment pq passing through cj for its antipodal vertex ci , and the algorithm is currently considering the next antipodal vertex ci−1 of cj . To construct the right envelope (ci−1 , cj ), the algorithm removes those segments from the right envelope (ci , cj ) that are contributed by the rays emitted from the vertices of the polygonal boundary bd(ci−1 , ci ). Observe that these segments, say, ci z1 , z1 z2 ,..., zt−1 zt are consecutive segments starting from −−−→ ci . Assume that zt and zt+1 lie on v−− m vm−1 . Let x be the point of intersection of − − − − − → − − − − − → ci−1 ci−2 and vm vm−1 . So the right envelope (ci−1 , cj ) consists of segments ci−1 x, xzt+1 , zt+1 zt+2 ,..., zs y. To construct the left envelope (ci−1 , cj ), the algorithm scans the polygonal boundary bd(ci−1 , ci ) in counterclockwise order starting from ci−1 and construct a partial left envelope (ci−1 , cj ) up to ci . Let x be the point of intersection of the left envelope (ci , cj ) and the ray, which corresponds to the last segment in the partial left envelope (ci−1 , cj ). The left envelope (ci−1 , cj ) is the concatenation of the partial left envelope (ci−1 , cj ) up to x and the portion of the left envelope (ci , cj ) from x to its end. If ci−2 is also an antipodal vertex of cj , the above method of updating can be used to construct the left and right envelopes (ci−2 , cj ). Otherwise, ci−1 is an antipodal vertex of cj−1 . Analogous method of updating can be used to construct the left and right envelopes (ci−1 , cj−1 ). When the algorithm returns to the antipodal pair ci and cj after going around the boundary once in clockwise order, it can be seen that the total cost of updating both envelopes is proportional to the number of vertices of P . Thus the algorithm constructs both envelopes for all antipodal pairs in O(n) time. In the following, we state the major steps of the algorithm. Step 1. Compute the convex hull of P by the algorithm of Graham and Yao [175] and label the vertices of the convex hull as c1 , c2 , ..., ck in counterclockwise order. Step 2. Scan bd(P ) in counterclockwise order and compute SP Tcc (c1 ). If there is any reverse turn then goto Step 9. Step 3. Scan bd(P ) in counterclockwise order and compute SP Tc (c1 ). If there is any reverse turn then goto Step 9. Step 4. Locate all antipodal pairs of vertices of the convex hull of P and add them in clockwise order to the list of antipodal pairs. Initialize (ci , cj ) by the first antipodal pair in the list. Step 5. Construct the left and right envelope (ci , cj ) and goto Step 7. Step 6. Assign (ci , cj ) by the next antipodal pair of (ci , cj ) in the list of antipodal
102
Weak Visibility and Shortest Paths
pairs. Construct the left and right envelope (ci , cj ) by updating the envelopes of the previous antipodal pair. Step 7. If there is a point p on the left envelope (ci , cj ) that can be connected through cj to a point q on the right envelope (ci , cj ) then report the segment pq and Stop. Step 8. If all antipodal pairs of vertices have not been considered then goto Step 6. Step 9. Report that P is not weakly externally visible from any segment and Stop.
Let us discuss the correctness of the algorithm. The algorithm first computes the convex hull of P in Step 1 and then checks in Steps 2 and 3 whether P is weakly externally visible from the boundary of the convex hull of P by computing SP Tcc (c1 ) and SP Tc (c1 ). Assume that that the given polygon P is weakly externally visible. We know from Lemmas 3.7.1 and 3.7.3 that P is also weakly externally visible from a segment if there is a segment pq and an antipodal pair (ci , cj ) such that pq passes through cj , and p and q are two points on the left and right envelope (ci , cj ). So, the algorithm locates all antipodal pairs of P in Step 4 and then constructs both envelopes of each antipodal pair (ci , cj ) in Steps 5 and 6 until a segment pq is found in Step 7 satisfying Lemmas 3.7.1 and 3.7.3. Hence the algorithm correctly locates a segment pq from which P is weakly externally visible. It has already been shown that the algorithm runs in O(n) time as both envelopes for all antipodal pairs of vertices can be computed in O(n) time. We summarize the result in the following theorem. Theorem 3.7.4 Recognizing a simple polygon P of n vertices weakly externally visible from a segment can be done in O(n) time.
3.8 Notes and Comments We have presented algorithms in Section 3.5 for recognizing a weak visibility polygon P by constructing a chord st inside P . The first algorithm proposed for this problem was given by Ke [212]. However, it has been pointed out by Aleksandrov et al. [16] that Ke’s algorithm is not correct. Ghosh [155] studied the problem of computing the complete and weak visibility polygons of a set Q inside a simple polygon P . He presented O(n + k) algorithms for both of these problems, where k is the number of corner vertices of Q. This problem has been studied by Briggs and Donald [66] for polygon with holes.
3.8 Notes and Comments
103
Exercise 3.8.1 Let P be an n-sided, star-shaped polygon containing a convex set C. Assume that C is given in the form of a k-sided convex polygon where every extreme point of C is a vertex of the convex polygon. Two points of P or C are visible if the line segment joining them lies inside P . Design an O(n + k) time algorithm for computing the complete visibility polygon of P from C. A simple polygon P is said to be a palm polygon if there exists a point z ∈ P such that the shortest path from z to any point y ∈ P makes only left turns or only right turns. Palm polygons were introduced by ElGindy and Toussaint [131], and this class of polygons has been characterized in terms of eaves of shortest paths by Ghosh et al. [164] as follows. Let vi vj be an eave in the shortest path between any two vertices of P . Extend vi vj from vi (or vj ) to bd(P ) meeting it at ui (respectively, uj ). Cut P into two parts by the segment ui vi (or uj vj ). The portion of P not containing vj (respectively, vi ) is called a forbidden region of the eave vi vj . We have the following lemma from Ghosh et al. [164]. Lemma 3.8.1 A simple polygon P is a palm polygon if and only if there exists a point z ∈ P such that z is not in the forbidden region of any eave in the shortest path between any two vertices of P . Using the above characterization, Ghosh et al. [164] presented an O(E) time recognition algorithm for palm polygons where E is the number of visible pairs of vertices in P . Exercise 3.8.2 Design an O(E) time algorithm for recognizing a palm polygon P where E is the number of visible pairs of vertices in P [164]. Let us mention parallel algorithms for weak visibility and shortest path problems considered in this chapter. Consider the problem of computing the shortest path SP (s, t) between two given points s and t inside a simple polygon P . ElGindy and Goodrich [129] and Goodrich et al. [173, 174] showed that SP (s, t) can be computed in O(log n) time using O(n) processors in the CREW-PRAM model of computations. ElGindy and Goodrich also showed that the shortest path tree from a point inside a simple polygon P can be computed in O(log 2 n) time by keeping the number of processors and the model of computation the same. Later, Goodrich et al. showed that the running time can be reduced from O(log 2 n) to O(log n) for this problem. If the triangulation of P is given, the shortest path tree in P can be computed by the algorithm of Hershberger [187] in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations. Note that P can be triangulated in O(log n) time using O(n) processors in the CREW-PRAM model of computations by the algorithm of Yap [345] or Goodrich [171].
104
Weak Visibility and Shortest Paths
Consider the problem of computing the weak visibility polygon of a simple polygon P from a segment inside P . Goodrich et al. [173, 174] designed an algorithm for this problem using their own algorithm for computing the shortest path tree in P . For computing the complete and weak visibility polygons of a set Q inside a simple polygon P of total n vertices, Chandru et al. [69] gave an algorithm for this problem, which also uses the algorithm of Goodrich et al. mentioned above, for computing the shortest path tree in P . Both these algorithms run in O(log n) time using O(n) processors in the CREW-PRAM model of computations. If the triangulation of P is given, both these problems can be solved by the algorithm of Hershberger [187] in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations. Consider the problem of detecting the weak visibility polygon of a simple polygon P from a given edge of P . We know that this problem can be solved using shortest path trees after P is triangulated. Chen [84] showed that without using the triangulation of P and shortest path trees, the problem can be solved in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations. Chen [82] also showed that whether P is weakly visible from an edge can be determined in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations. Once P is found to be weakly visible, triangulating P and computing the shortest path tree in P can be done in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations as shown by Chen [84]. Exercise 3.8.3 Let S be a subset of edges of a polygon P with or without holes. Design a polynomial time algorithm to test whether every internal point of P is visible from some point on an edge of S [152].
4 LR-Visibility and Shortest Paths
4.1 Problems and Results
A simple polygon P is said to be an LR-visibility polygon if there exists two points s and t on the boundary of P such that every point of the clockwise boundary of P from s to t (denoted as L) is visible from some point of the counterclockwise boundary of P from s to t (denoted as R) and vice versa (see Figure 4.1(a)). LRvisibility polygons can be viewed as a generalization of weak visibility polygons (discussed in Chapter 3). We know that a simple polygon P is a weak visibility polygon from a chord if there exists two points s and t on bd(P ) such that (i) s and t are mutually visible, and (ii) every point of the clockwise boundary from s to t is visible from some point of the counterclockwise boundary from s to t and vice versa. If the condition (i) is removed, then it defines LR-visibility polygons, which contains weak visibility polygons as a subclass. It can be seen that if a point moves along any path between s and t inside an LR-visibility polygon, it can see the entire polygon. LR-visibility polygons are also called streets and this class of polygons was first considered while studying the problem of walking in a polygon. For more details, see Icking and Klein [200] and Klein [219]. Like weak visibility polygons, LR-visibility polygons can also be characterized in terms of shortest paths and non-redundant C-polygons. Heffernan [184], and Bhattacharya and Ghosh [48] characterized LR-visibility polygons using shortest paths between vertices of the polygon, and their characterization is similar to the characterization of weak visibility polygons given by Ghosh et al. [163] presented in Section 3.2. It has been observed by Icking and Klein [200] that LR-visibility polygons can be characterized in terms of non-redundant C-polygons. In the next section (i.e., Section 4.2), we state these characterizations of LR-visibility polygons. The LR-visibility polygon inside a simple polygon P for a pair of s and t is the set of all points of P that are visible from some point of SP (s, t). The characterization of Heffernan [184], and Bhattacharya and Ghosh [48] gives a straightforward O(n) 105
106
LR-Visibility and Shortest Paths
Figure 4.1 (a) P is a LR-visibility polygon with respect to s1 and t1 but not with respect to s2 and t2 . (b) The polygon P is walkable but not straight walkable.
time algorithm for computing the LR-visibility polygon inside P . We present this algorithm in Section 4.3. Heffernan [184], and Bhattacharya and Ghosh [48] presented a linear time algorithm for recognizing LR-visibility polygons with respect to a given s and t. The general problem of recognizing LR-visibility polygons is to locate s and t such that the given polygon is an LR-visibility polygon with respect to s and t. For this problem, Tseng et al. [332] presented an O(n log n) time algorithm and Das et al. [101] gave an O(n) time algorithm. In fact, the algorithm of Das et al. [101] locates all pairs of points s and t that the polygon is LR-visible with respect to. In Section 4.4, we present an O(n) time recognition algorithm for LR-visibility polygons, which follows a method similar to the algorithm in Section 3.5.2 for recognizing weak visibility polygons. Bhattacharya and Ghosh [48] presented an O(n) time algorithm for computing the shortest path tree from a vertex for a class of polygons which contains LRvisibility polygons as a subclass. If the algorithm terminates without computing the shortest path tree in a given polygon P , then P is not an LR-visibility polygon. If the algorithm computes the shortest path tree, then P may be an LR-visibility polygon. We present the algorithm of Bhattacharya and Ghosh [48] in Section 4.6. This algorithm is used here as a step in our recognition algorithm presented in Section 4.4 and it is also used in the algorithm for walking in an LR-visibility polygon presented in Section 4.5. The algorithm of Bhattacharya and Ghosh [48] computes the shortest path tree by scanning the boundary of a given polygon P and it does not require a triangulation
4.1 Problems and Results
107
of P as a preprocessing step unlike the algorithm of Guibas et al. [178]. It may be noted that since the class of LR-visibility polygons contains many special classes of polygons such as spiral polygons, star-shaped polygons, weak visibility polygons, monotone polygons, etc., their algorithm can compute the shortest path tree in linear time in any of these special classes of polygons and therefore, triangulating these special classes of polygons is also possible in linear time. Exercise 4.1.1 Assume that a simple polygon P of n vertices is given along with the shortest path tree rooted at some vertex of P . Design an algorithm for constructing a triangulation of P in O(n) time from the shortest path tree. Suppose two police officers have to patrol a street and they walk along the opposite sides of the street. Can two officers proceed in such a way that they are always mutually visible? Formally, assume that a simple polygon P is given with two distinguished vertices s and t. Can two points be moved from s to t, one along the clockwise boundary of P and the other along the counterclockwise boundary of P , such that the line segment connecting them always lies totally inside P ? The points are allowed to backtrack locally but they must arrive at t eventually. A movement subject to these constraints is called a walk. If P admits such a walk (see Figure 4.1(b)), P is called 2-guard walkable (or, simply, walkable) and P is an LR-visibility polygon. Icking and Klein [200] introduced this problem, and presented an O(n log n) time algorithm to test whether P is walkable for a given pair s and t. Later, Heffernan [184] gave an O(n) time algorithm for this problem. One special case arises when the points do not backtrack during their walk. Such a walk is called straight (see Figure 4.2(a)). During a straight walk, the line segment connecting the points sweeps the polygon in an ordered way. To determine whether P is straight walkable for a given pair s and t, Heffernan [184] gave O(n) time algorithm for this problem. Tseng et al. [332] presented an O(n log n) time algorithm for this problem when no pair s and t is given. They also showed within the same time bound how to generate all such pairs of s and t. A straight walkable polygon P is said to be discretely straight walkable if only one of the two points is allowed to move at a time, while the other point remains stationary at a vertex (see Figure 4.2(b)). It has been observed by Arkin et al. [21] that P is discretely straight walkable if only if P has a Hamiltonian triangulation. A simple polygon P is said to have a Hamiltonian triangulation if it has a triangulation whose dual graph is a Hamiltonian path. Such triangulations are useful in fast rendering engines in computer graphics, since visualization of surfaces is normally done via triangulations [21]. It has been shown by Narasimhan [266] that testing discrete straight walkability and computing all discrete straight walkable pairs of s and t can be performed in O(n log n) time. Bhattacharya et al. [51] presented O(n)
108
LR-Visibility and Shortest Paths
Figure 4.2 (a) The polygon P is straight walkable but not discretely straight walkable. (b) The polygon P is discretely straight walkable.
time algorithms for testing all pairs of s and t of P for which P is walkable, straight walkable and discretely straight walkable. In Section 4.5, we present their algorithm for testing whether a simple polygon P is walkable for any pair of boundary points s and t. In the same section, we also present an O(n2 ) time algorithm for constructing a walk between a pair of boundary points s and t of P based on the properties derived by Icking and Klein [200]. Exercise 4.1.2 Let P be an LR-visibility polygon with respect to a given pair of points s and t on the boundary of P . Assume that SP T (s) and SP T (t) are given. Construct a Hamiltonian triangulation of P (if it exists) in O(n) time, where n is the number of vertices of P .
4.2 Characterizing LR-Visibility In this section, we present the characterization of LR-visibility in polygons in terms of shortest paths and non-redundant C-polygons. We start with the characterization of Heffernan [184], and Bhattacharya and Ghosh [48] who used shortest paths between vertices to characterize LR-visibility polygons. For every point z ∈ L, the same chain and the opposite chain of z refer to L and R, respectively. Similarly, for every point z ∈ R, the same chain and the opposite chain of z refer to R and L respectively. In the following theorem, we characterize LR-visibility polygons. Theorem 4.2.1 Let P denote a simple polygon. The following statements are equivalent. (i) P is an LR-visibility polygon with respect to vertices s and t.
4.2 Characterizing LR-Visibility
109
Figure 4.3 (a) Since SP (vi , vj ) and SP (vk , vj ) meet only at vj , vj is visible from the opposite chain of vj . (b) SP (s, vj ) and SP (t, vj ) meet at a vertex vm other than vj .
(ii) Let vi , vj and vk be any three vertices of L (or R) (including s and t) such that they are in clockwise (respectively, counterclockwise) order while traversing L (respectively, R) from s to t. SP (vi , vj ) and SP (vk , vj ) meet only at vj . (iii) For any vertex vj ∈ L (or, vj ∈ R), SP (s, vj ) makes a left turn (respectively, a right turn) at every vertex of L (respectively, R) in the path. Analogously, for any vertex vj ∈ L (or, vj ∈ R), SP (t, vj ) makes a right turn (respectively, a left turn) at every vertex of R (respectively, L) in the path. Proof. Firstly, we show that (i) implies (ii). Since P is an LR-visibility polygon with respect to s and t, vj is visible from some point y of the opposite chain of vj (Figure 4.3(a)). So, the line segment yvj partitions P into two polygons, one containing s and vi , and the other containing t and vk . So, SP (vi , vj ) and SP (vk , vj ) cannot cross the line segment yvj and therefore, they meet only at vj . Secondly, we show (ii) implies (iii). We prove only for the case when vj belongs to L (Figure 4.3(b)). Assume on the contrary that SP (s, vj ) makes a right turn at some vertex vm ∈ L. Consider the convex angle formed by SP (s, vj ) at vm . If the convex angle is facing toward the interior of P , then by triangle inequality SP (s, vj ) does not pass through vm , a contradiction. If the convex angle is facing toward the exterior of P , then SP (s, vj ) and SP (t, vj ) meet at the vertex vm other than vj contradicting (ii) (Figure 4.3(b)). Hence, SP (s, vj ) makes a left turn at vm . Analogous arguments show that SP (t, vj ) makes a right turn at every vertex of L in the path. Thirdly, we show that (iii) implies (i). It suffices to show that any vertex vj of P is visible from some point of the opposite chain of vj (Figure 4.3(a)). We prove only for the case when vj belongs to L. Let zc and zcc be the vertices preceding vj
110
LR-Visibility and Shortest Paths
on SP (s, vj ) and SP (t, vj ) respectively. If zc or zcc belongs to the opposite chain of vj , then the claim holds. So we assume that zc , zcc and vj belong to the same chain. From the condition (iii) we know that SP (s, vj ) makes a left turn at zc and SP (t, vj ) makes a right turn at zcc . It means that extensions of vj zc and vj zcc from zc and zcc , respectively, cannot meet the same chain of vj . So, both extensions meet at points of the opposite chain of vj . Therefore, vj is visible for some point of the opposite chain of vj . Hence, P is an LR-visibility polygon with respect to s and t.
Let us characterize LR- visibility polygons in terms of non-redundant C-polygons as observed by Icking and Klein [200]. We use the same notions used in Section 3.5.2. The clockwise (or, counterclockwise) C-polygon of a vertex vi is said to contain a point z if z lies on the clockwise (respectively, counterclockwise) boundary of the C-polygon. We have the following lemma. Lemma 4.2.2 A simple polygon P is an LR-visibility polygon with respect to boundary points s and t if and only if each non-redundant C-polygon of P contains s or t. Proof. If a non-redundant C-polygon of some vertex vi does not contain s or t, then SP (s, t) does not intersect the bounding chord of the C-polygon. Then v i−1 or vi+1 is not visible form any point of SP (s, t). Therefore, P is not an LR-visibility polygon, which is a contradiction. We now prove the converse. Since every nonredundant C-polygon of P contains s or t, SP (s, t) intersects the bounding chord of every non-redundant C-polygon of P . Therefore, every point of P is visible from some point of SP (s, t). Hence, P is an LR-visibility polygon with respect to s and t. Corollary 4.2.3 If an LR-visibility polygon P has two disjoint C-polygons, then one C-polygon contains s and the other contains t. Corollary 4.2.4 If P has three or more mutually disjoint C-polygons, then P is not an LR-visibility polygon.
4.3 Computing LR-Visibility Polygons In this section, we present an O(n) time algorithm for computing the LR-visibility polygon inside a simple polygon P for a given pair of boundary points s and t. The LR-visibility polygon inside P for a pair s and t is defined as the set of all points of P that are visible from some point of SP (s, t). The algorithm is similar to the algorithm of Guibas et al. [178], presented in Section 3.3.2, for computing the weak visibility polygon of a simple polygon from an internal segment. We assume that
4.3 Computing LR-Visibility Polygons
111
Figure 4.4 All descendants of vi in SP T (s) are not visible from any point of SP (s, t).
P is given as a counterclockwise sequence of vertices v1 , v2 , ..., vn with two marked vertices s and t. In the following lemmas, we present the main idea used in the algorithm. The proofs of the lemmas follow from Theorem 4.2.1. Lemma 4.3.1 Let vi , vj and vm be the three distinct vertices in SP T (s) such that (i) vi is the parent of vj in SP T (s), (ii) vm is the least common ancestor of t and vi in SP T (s), (iii) SP (vm , vi ) makes a left turn at every intermediate vertex in the path, and (iv) SP (s, vj ) makes a right turn at vi (Figure 4.4(a)). If vi ∈ L, then all descendants of vi in SP T (s) are not visible from any point of SP (s, t). Lemma 4.3.2 Let vi , vj and vm be the three distinct vertices in SP T (s) such that (i) vi is the parent of vj in SP T (s), (ii) vm is the least common ancestor of t and vi in SP T (s), (iii) SP (vm , vi ) makes a right turn at every intermediate vertex in the path, and (iv) SP (s, vj ) makes a left turn at vi (Figure 4.4(b)). If vi ∈ R, then all descendants of vi in SP T (s) are not visible from any point of SP (s, t). Lemma 4.3.3 Let vi , vj and vm be the three distinct vertices in SP T (t) such that (i) vi is the parent of vj in SP T (t), (ii) vm is the least common ancestor of s and vi in SP T (t), (iii) SP (vm , vi ) makes a right turn at every intermediate vertex in the path, and (iv) SP (t, vj ) makes a left turn at vi (Figure 4.5(a)). If vi ∈ L, then all descendants of vi in SP T (t) are not visible from any point of SP (s, t). Lemma 4.3.4 Let vi , vj and vm be the three distinct vertices in SP T (t) such that (i) vi is the parent of vj in SP T (t), (ii) vm is the least common ancestor of s and vi in SP T (t), (iii) SP (vm , vi ) makes a left turn at every intermediate vertex in the
112
LR-Visibility and Shortest Paths
Figure 4.5 All descendants of vi in SP T (t) are not visible from any point of SP (s, t).
path, and (iv) SP (t, vj ) makes a right turn at vi (Figure 4.5(b)). If vi ∈ R, then all descendants of vi in SP T (t) are not visible from any point of SP (s, t). Exercise 4.3.1 Prove Lemmas 4.3.1, 4.3.2, 4.3.3 and 4.3.4. Lemmas 4.3.1, 4.3.2, 4.3.3 and 4.3.4 suggest a simple procedure to compute the LR-visibility polygon as follows. Step 1. Compute SP T (s) in P by the algorithm of Guibas et al. [178]. Traverse SP T (s) in depth first order and check the turn at every vertex vi in SP T (s). Step 2. If it is a right turn at vi and vi ∈ L (see Lemma 4.3.1) then (Figure 4.4(a))
Step 2a. Find the descendant of vi in SP T (s) with the largest index j. → Step 2b. Compute the intersection point z of vj vj+1 and − v− k vi , where vk is the parent of vi in SP T (s). Remove the counterclockwise boundary of P from vi to z by inserting the segment vi z.
Step 3. If it is a left turn at vi and vi ∈ R (see Lemma 4.3.2) then (Figure 4.4(b))
Step 3a. Find the descendant of vi in SP T (s) with the smallest index j. → Step 3b. Compute the intersection point z of vj vj−1 and − v− k vi , where vk is the parent of vi in SP T (s). Remove the clockwise boundary of P from vi to z by inserting the segment vi z.
Step 4. Let P 0 denote the remaining portion of P . Compute SP T (t) in P 0 by the algorithm of Guibas et al. [178]. Traverse SP T (t) in depth first order and check the turn at every vertex vi in SP T (t). Step 5. If it is a left turn at vi and vi ∈ L (see Lemma 4.3.3) then (Figure 4.5(a))
4.4 Recognizing LR-Visibility Polygons
113
Step 5a. Find the descendant of vi in SP T (t) with the smallest index j. → Step 5b. Compute the intersection point z of vj vj−1 and − v− k vi , where vk is the parent of vi in SP T (t). Remove the clockwise boundary of P 0 from vi to z by inserting the segment vi z. Step 6. If it is a right turn at vi and vi ∈ R (see Lemma 4.3.4) then (Figure 4.5(b))
Step 6a. Find the descendant of vi in SP T (t) with the largest index j. → Step 6b. Compute the intersection point z of vj vj+1 and − v− k vi , where vk is the parent of vi in SP T (t). Remove the counterclockwise boundary of P from vi to z by inserting the segment vi z.
Step 7. Let P 00 denote the remaining portion of P 0 . Output P 00 as the LR-visibility polygon. The correctness of the algorithm follows from Lemmas 4.3.1, 4.3.2, 4.3.3 and 4.3.4. The algorithm for computing SP T (s) and SP T (t) takes O(n) time [178]. Every vertex of SP T (s) and SP T (t) is traversed once and the remaining operations take constant time. So, the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 4.3.5 The LR-visibility polygon for a given pair of boundary points s and t inside a simple polygon P of n vertices can be computed in O(n) time.
4.4 Recognizing LR-Visibility Polygons In this section, we present an O(n) time algorithm for recognizing LR-visibility polygons. Given a simple polygon P , the problem is to locate two points s and t (if they exist) on bd(P ) such that P is an LR-visibility polygon with respect to s and t. The recognition algorithm follows steps similar to the algorithm for recognizing weak visibility polygons presented in Section 3.5.2. The algorithm uses the characterization of LR-visibility polygons presented in Lemma 4.2.2 and also uses the algorithm of Bhattacharya and Ghosh [48], presented in Section 4.6, for computing the shortest path tree in P by scanning bd(P ). We use the same notions used in Section 3.5.2 for presenting the algorithm here. The algorithm starts by computing SP T (v1 ) by the algorithm of Bhattacharya and Ghosh [48]. By traversing SP T (v1 ), it locates two disjoint critical polygons polycc (vp ) and polyc (vq ) with bounding chords vp wp and vq uq respectively (see Figure 4.6). Then, it computes SP T (vp ), SP T (wp ), SP T (vq ) and SP T (uq ). For each vertex vk of bd(uq , wp ), it tests whether (i) SP (wp , vk ) makes only left turns, and (ii) SP (uq , vk ) makes only right turns. Similarly, for each vertex vk ∈ bd(vp , vq ), it tests whether (i) SP (vp , vk ) makes only right turns, and (ii) SP (vq , vk ) makes only left turns. Note that LR-visibility polygons allow SP (uq , wp ) to pass through a vertex of bd(vp , vq ) and SP (vp , vq ) to pass through a vertex of bd(uq , wp ) (see Figure
114
LR-Visibility and Shortest Paths
Figure 4.6 (a) Locations of s and t on bd(P ) when SP (uq , wp ) and SP (vp , vq ) are disjoint. (b) Locations of s and t on bd(P ) when SP (uq , wp ) and SP (vp , vq ) share vertices.
4.6(b)). It tests whether vk uk and vm wm intersect after locating two critical polygons polycc (vk ) and polyc (vm ) with bounding chords vk uk and vm wm , respectively, where vk ∈ bd(uq , wp ) and uk ∈ bd(wp , vp ), vm ∈ bd(vp , vq ) and wm ∈ bd(wp , vp ). Similarly, it tests whether vz uz and vr wr intersect after locating two critical polygons polycc (vz ) and polyc (vr ) with bounding chords vz uz and vr wr , respectively, where vz ∈ bd(vp , vq ) and uz ∈ bd(vq , up ), vr ∈ bd(uq , wp ) and wr ∈ bd(vq , uq ). Then it performs cascade testing to determine whether (i) bd(uz , wm ) can be included in L, and (ii) bd(uk , wr ) can be included in R. If SP (uq , wp ) and SP (vp , vq ) do not share a vertex (see Figure 4.6(a)), then the algorithm scans bd(wr , uz ) and bd(wm , uk ) in both clockwise and counterclockwise order to compute the final bd(wr , uz ) and bd(wm , uk ). The algorithm reports that P is an LR-visibility polygon with respect to pairs (i) wm and wr , and (ii) uk and uz . In Figure 4.6(a), the final uk is taken as s and the final uz is taken as t. If SP (uq , wp ) and SP (vp , vq ) share a vertex (see Figure 4.6(b)), it locates four vertices t1 , t2 , s1 and s2 as follows. The vertex t1 belongs to bd(wr , uz ) and it is the first vertex in clockwise order from uz whose parent in SP T (wp ) is its next clockwise vertex. If no such vertex exists, t1 is wr . Similarly, the vertex t2 also belongs to bd(wr , uz ) and it is the first vertex in counterclockwise order from wr whose parent in SP T (vp ) is its next counterclockwise vertex. If no such vertex exists, t2 is uz . If t2 does not belong to bd(t1 , uz ), then P is not an LR-visibility polygon. So, we assume that t2 ∈ bd(t1 , uz ). Any point of bd(t1 , t2 ) can be taken as the point t. Analogously, s1 and s2 can be located using SP T (uq ) and SP T (vq ) and then s is chosen appropriately. We summarize the result in the following theorem.
4.5 Walking in an LR-Visibility Polygon
115
Theorem 4.4.1 Two points s and t can be located in O(n) time on the boundary of a simple polygon P of n vertices such that P is an LR-visibility polygon with respect to s and t.
4.5 Walking in an LR-Visibility Polygon In this section, we present an O(n2 ) time algorithm for constructing a walk between a pair of boundary points s and t of a simple polygon P . The algorithm is based on the properties derived by Icking and Klein [200]. We also present an O(n) time algorithm given by Bhattacharya et al. [51] for testing whether or not a simple polygon P is walkable for a given pair of boundary points s and t. We assume that P is given as a counterclockwise sequence of vertices v1 , v2 , ..., vn with two marked vertices s and t. As in Section 3.5.2, for any reflex vertex vi of P , let polyc (vi ) (or polycc (vi )) denote the clockwise (respectively, counterclockwise) C-polygon of vi , where vi ui (respectively, vi wi ) is the bounding chord of polyc (vi ) (respectively, polycc (vi )). Let gc and gcc be two moving points along the boundary of P starting from s such that (i) gc moves along bd(t, s) (denoted as L), and (ii) gcc moves along bd(s, t) (denoted as R). As stated in Section 4.1, P is 2-walkable if the line segment gc gcc lies inside P during the entire movement of gc and gcc (see Figure 4.7(a)). We start with the following lemma from Icking and Klein [200]. Lemma 4.5.1 If a simple polygon P is 2-walkable then P is an LR-visibility polygon. Exercise 4.5.1 Prove Lemma 4.5.1. Using the recognition algorithm presented in Section 4.4, it can be determined whether P is an LR-visibility polygon. If P is an LR-visibility polygon, the recognition algorithm also locates a pair of points s and t on bd(P ). In fact, all pairs of points s and t, for which P is an LR-visibility polygon, can be located by the method presented by Tseng et al. [332]. They have shown that locating a pair of s and t is same as locating two cut points in a 2-cut circular arc problem. Exercise 4.5.2 Let S be a set of n ≥ 2 closed arcs on a unit circle K, where no arc totally contains another arc. Find pairs of intervals ((p, q), (r, s)) in O(n) time such that for every point c1 ∈ (p, q) and c2 ∈ (r, s), each arc of S contains a cut point c1 or c2 [332]. From now on, we assume that P is an LR-visibility polygon. Observe that although P can have several pairs of s and t, P may be 2-walkable only for some pairs of s and t. The algorithm of Bhattacharya et al. [51] starts with a pair of s and t, and during the process of checking, if it encounters the next pair of s and t,
116
LR-Visibility and Shortest Paths
Figure 4.7 (a) The movements of gc and gcc : (i) gc walks to vi , (ii) gcc walks to ui , (iii) gc walks to vj , (iv) gcc walks to uj , (v) gc walks to t and (vi) gcc walks to t. (b) The vertex vk−1 is not visible from vi . (c) The vertices vi and vk form an s-deadlock in P .
it switches to that pair, and continues the process until P is checked for all pairs of s and t. Thus, the algorithm identifies all pairs of s and t on bd(P ) for which P is 2-walkable. Here we consider only one pair of boundary points s and t in the presentation of their algorithm. Suppose, gc starts from s and moves along L as long as it is visible from gcc which is currently waiting at s. Assume that gc has reached a reflex vertex vi (see Figure 4.7(a)) and it cannot move ahead without losing sight of gcc . This means that there is a constructed edge in the visibility polygon V (s) with vi as one of its endpoints. Then, gcc must move along R until the edge vi vi−1 is visible from gcc so that gc can move ahead from vi . This means that gcc must enter into the clockwise C-polygon of vi whose bounding chord is vi ui . Therefore, gcc must walk at least up to ui and it should remain visible from gc while walking from s to ui . If the entire bd(s, ui ) is visible from vi , then gcc can walk to ui without losing sight of gc . If some point of bd(s, ui ) is not visible from vi (see Figure 4.7(b) and Figure 4.7(c)), gcc cannot remain visible from gc while walking from s to ui . This means that there exists a reflex vertex vk ∈ bd(s, ui ) such that vk is visible from vi but either vk+1 or vk−1 is not visible from vi . If vk−1 is not visible from vi (see Figure 4.7(b)), gc has to walk backward till it enters the clockwise C-polygon of vk whose bounding chord is vk uk . So, gc walks backward up to uk and checks whether gcc can walk up to vk . If gcc can walk up to vk without losing sight of gc who is waiting at uk , then gc can move forward after gcc reaches vk . If gcc cannot walk up to vk , then gc walks backward as before until it enters the clockwise C-polygon of another reflex vertex vm ∈ bd(s, vk ). This discussion suggests that instead of gc moving all the way up to vi in greedy manner,
4.5 Walking in an LR-Visibility Polygon
117
Figure 4.8 (a) The entire boundary bd(wj , ui ) is visible from x. (b) There is an s-deadlock in P as vi ui and vk wk have intersected. (c) There is a t-deadlock in P as vj wj and vk uk have intersected.
gc should wait at one endpoint of the bounding chord until gcc reaches the other endpoint. Since all bounding chords in P can be computed, gc and gcc can coordinate their walk as they encounter endpoints of bounding chords. If vk+1 is not visible from vi (see Figure 4.7(c)), gcc cannot walk beyond vk even if gc moves backward toward s. This situation is called s-deadlock. A polygon P is said to have s-deadlock, if there exists two reflex vertices vi ∈ L and vk ∈ R such that the bounding chord vi ui of polyc (vi ) intersects the bounding chord vk wk of polycc (vk ). Analogously, a polygon P is said to have t-deadlock, if there exists two reflex vertices vi ∈ L and vk ∈ R such that the bounding chord vi wi of polycc (vi ) intersects the bounding chord vk uk of polyc (vk ). We have the following theorem from Icking and Klein [200]. Theorem 4.5.2 A simple polygon P is 2-walkable if and only if P does not have an s-deadlock or a t-deadlock. Proof. Assume that P has an s-deadlock formed by the reflex vertices vi ∈ L and vk ∈ R. Therefore, two bounding chords vi ui and vk wk intersect in P by definition. So, vi ∈ bd(wk , s) and vk ∈ bd(s, ui ). Before gc starts walking on the edge vi vi−1 , gcc must reach ui so that gc and gcc remain mutually visible. Similarly, before gcc starts walking on the edge vk vk+1 , gc must reach wk so that gc and gcc remain mutually visible. This is a deadlock and hence, there is no walk between s and t in P . Analogous arguments show that if P has a t-deadlock, there is no walk between s and t in P .
118
LR-Visibility and Shortest Paths
Figure 4.9 (a) The entire boundary bd(ui , wj ) is visible from vi . (b) The vertex vk is visible from vi but not vk−1 . (c) The vertex vk is visible from vi but not vk+1 .
We now prove the converse. By assumption, P does not have an s-deadlock or t-deadlock. We show that there exists a walk from s to t in P . Assume that g c and gcc are currently at two endpoints of a bounding chord. Without loss of generality, assume that gc has walked from s up to a reflex vertex vi ∈ L and gcc has also walked from s up to the point ui ∈ R, where vi ui is the bounding chord of polyc (vi ) (see Figure 4.8). We also assume that they were mutually visible during the walk. They wish to walk to the endpoints of another bounding chord. Let vj ∈ L be the next reflex vertex while traversing from vi to t. Consider the bounding chords vj uj and vj wj of polyc (vj ) and polycc (vj ), respectively. There are three cases that can arise. Case 1. The bounding chord vi ui has intersected both vj uj and vj wj (see Figure 4.8). Case 2. The bounding chord vi ui has intersected vj uj but has not intersected vj wj (see Figure 4.9). Case 3. The bounding chord vi ui has not intersected vj uj and vj wj (see Figure 4.11(a)). Consider Case 1 (see Figure 4.8). This condition suggests that gc must walk ahead from vi to vj while gcc walks backward from ui to wj . We show that gc and gcc can remain mutually visible during this walk. Let x be the point of intersection of vi ui and vj wj . It is obvious that every point of bd(vj , vi ) is visible from x. If every point of bd(wj , ui ) is also visible from x (see Figure 4.8(a)), then gc and gcc can coordinate their walk in such a way that the segment gc gcc always passes through x. We show that every point of bd(wj , ui ) is indeed visible from x. Suppose there is a point z ∈ bd(wj , ui ) which is not visible from x. Since z and x are not mutually visible by assumption, SP (x, z) must pass through at least one reflex vertex vk . If
4.5 Walking in an LR-Visibility Polygon
119
Figure 4.10 (a) There is an s-deadlock in P as vk vm and vm um have intersected. (b) The bounding chords vk vm and vi ui have intersected. (c) The bounding chords vk vm and vi ui have not intersected.
vk ∈ bd(wj , z) (see Figure 4.8(b)), then vi and vk form an s-deadlock in P as vi ui intersects vk wk , a contradiction. If vk ∈ bd(z, ui ) (see Figure 4.8(c)), then vj and vk form a t-deadlock in P as vj wj intersects vk uk , which is a contradiction. Therefore, the entire boundary bd(wj , ui ) is visible from x. Hence gc can walk from vi to vj and gcc can also walk from ui to wj while they remain mutually visible. Thus, gc and gcc can reach the endpoints of another bounding chord. Consider Case 2. We know that ui ∈ bd(uj , wj ) (see Figure 4.9). If the entire boundary bd(ui , wj ) is visible from vi (see Figure 4.9(a)), gcc walks from ui to wj and then gc walks from vi to vj . So, gc and gcc have reached the endpoints of another bounding chord vj wj . Otherwise, if the entire boundary bd(ui , wj ) is visible from vj , gc walks to vj and then gcc walks to wj . Again, gc and gcc are at the endpoints of the bounding chord vj wj . Consider the situation when the entire boundary bd(ui , wj ) is not visible either from vi or from vj (see Figure 4.9(b) and (c)). Let vk ∈ bd(ui , wj ) be the first reflex vertex, while traversing from ui to wj , such that vk is visible from vi but either vk−1 or vk+1 is not visible from vi . If vk−1 is not visible from vi (see Figure 4.9(b)), then gc moves backward from vi to uk while gcc moves forward from ui to vk using the analogous method stated in Case 1. Thus gc and gcc move to the endpoints of another bounding chord vk uk . If vk+1 is not visible from vi (see Figure 4.9(c)), then gc walks to vk and gcc walks to wk . Thus gc and gcc move to the endpoints of another bounding chord vk wk . It may happen that wk does not belong to bd(vj , vi ) (see Figure 4.10). In that case, gc can still walk up to wk if bd(wk , vj ) is entirely visible from vk . Otherwise, the first reflex vertex vm ∈ bd(wk , vj ) can be located while traversing from vj to wk (see Figure 4.10(a)) such that vm is visible from vk but either vm−1 or vm+1 is not visible
120
LR-Visibility and Shortest Paths
Figure 4.11 (a) The bounding chord vi ui has not intersected both vj uj and vj wj . (b) By scanning from s, P is partitioned into sub-polygons using non-intersecting bounding chords of same type. (c) By scanning from t, P is partitioned into similar sub-polygons.
from vk . If vm−1 is not visible from vk , then vm and vk form an s-deadlock in P as the bounding chords vm um and vk wk intersect, which is a contradiction. Consider the other situation when vm+1 is not visible from vk (see Figure 4.10(b) and (c)). If vm wm intersects vi ui (see Figure 4.10(b)), then it becomes Case 1 treating vm as vj . Thus gc and gcc move to the endpoints of another bounding chord vm wm . If vm wm does not intersect vi ui (see Figure 4.10(c)), then wm belongs to bd(ui , vk ). We know that bd(ui , wm ) is entirely visible from vi . So, gcc walks from ui to wm and then gc moves from vi to vm . Thus gc and gcc move to the endpoints of another bounding chord vm wm . Consider Case 3. This is essentially Case 2 as wk must belong to bd(vj , vi ) (see Figure 4.11(a)) otherwise there is an s-deadlock due to the intersection of bounding chords vj uj and vk wk . It can be seen that gc and gcc always walk from the endpoints of a bounding chord to another which has not been considered before. In this process of walking, g c and gcc walk from one clockwise C-polygon containing t to another C-polygon which is contained in the previous C-polygon. Thus, gc and gcc always succeed in reaching t keeping themselves mutually visible as there is no s-deadlock or t-deadlock in P .
The above theorem suggests that before any attempt is made to construct a walk from s to t, it is necessary to test whether P has any s-deadlock or t-deadlock. Let us proceed to test whether P has any s-deadlock. The main idea of the testing procedure given by Bhattacharya et al. [51] is to partition P into sub-polygons using non-intersecting bounding chords of the same type as follows. Scan L from s
4.5 Walking in an LR-Visibility Polygon
121
to t till a reflex vertex vi is located such that ui ∈ R (see Figure 4.11(b)). Continue the scan till another reflex vertex vj is located such that uj ∈ R and vj uj does not intersect vi ui . Treating vj as vi , repeat the process. We have the following lemma for s-deadlock. Lemma 4.5.3 Let Pi denote the sub-polygon of P bounded by two consecutive bounding chords vi ui and vj uj , where vi ∈ L, vj ∈ bd(t, vi ), ui ∈ R and uj ∈ bd(ui , t) (Figure 4.11(b)). If there exists a reflex vertex vk ∈ bd(ui , uj ) such that vk wk intersects vj uj , then P has an s-deadlock formed by vj and vk . Using the above lemma, P can be tested whether there exists an s-deadlock formed by two reflex vertices in any sub-polygon Pi . If no sub-polygon of P has an s-deadlock, P does not have an s-deadlock. Then, the same process is used to test whether P has a t-deadlock. Starting from t (see Figure 4.11(c)), partition P using bounding chords vi ui , vj uj ,... where vi , vj ,... belong to R and ui , uj ,... belong to L. For every sub-polygon bounded by two such consecutive bounding chords vi ui and vj uj , check whether there exists a reflex vertex vk ∈ bd(ui , uj ) forming a t-deadlock with vj . If P does not have s-deadlock or t-deadlock, a walk can be constructed in P for gc and gcc from s to t using Cases 1 and 2 in the proof of Theorem 4.5.2. In the following, we present the major steps of the algorithm under the assumption that P does not have s-deadlock or t-deadlock. Step 1. Locate two points s and t on bd(P ) such that P is an LR-visibility polygon with respect to s and t. Step 2. Traverse L from s to t in clockwise order and partition P into sub-polygons using the non-intersecting bounding chords of clockwise C-polygons. Check whether any sub-polygon has a pair of reflex vertices forming an s-deadlock. Step 3. Traverse R from t to s in clockwise order and partition P into sub-polygons using the non-intersecting bounding chords of counterclockwise C-polygons. Check whether any sub-polygon has a pair of reflex vertices forming a t-deadlock. Step 4. Introduce a point t0 ∈ R arbitrarily close to t. Treat t as a reflex vertex of L and tt0 as the clockwise bounding chord of C-polygon of the reflex vertex t. Also, treat t0 as a reflex vertex of R and tt0 as the counterclockwise bounding chord of the C-polygon of the reflex vertex t0 . Introduce a point s0 ∈ R arbitrary close to s. Treat s as a reflex vertex of L and ss0 as the clockwise bounding chord of the C-polygon of the reflex vertex s. Step 5. Place gc at s and gcc at s0 . Initialize vi by s and ui by s0 . Step 6. (Remark: gc at vi and gcc at ui ). If gc is currently at t and gcc is currently at t0 then goto Step 14. Step 7. Initialize vj by the next counterclockwise vertex of vi . While vj is not a reflex vertex do j := j − 1.
122
LR-Visibility and Shortest Paths
Step 8. If vj wj intersects vi ui then move simultaneously gc and gcc from their present positions to vj and wj respectively, i := j and goto Step 11. Step 9. If vj uj intersects vi ui then Step 9a. Initialize vk by the next counterclockwise vertex of ui . Step 9b. While vk is not a reflex vertex and vk ∈ bd(ui , wj ) do k := k + 1. Step 9c. If vk 6∈ bd(ui , wj ) then move gc from its present position to vj and move gcc from its present position to wj , i := j and goto Step 11. Step 9d. If vk uk intersects vi ui then move simultaneously gc and gcc from their present positions to uk and vk respectively (Figure 4.9(b)), i := k and goto Step 12. Step 9e. If vk wk intersects vj wj then move gcc from its present position to vk , move gc from its present position to wk (Figure 4.10), i := k and goto Step 13. Step 9f. If wk ∈ bd(vj , vi ) then move gcc from its present position to vk , move gc from its present position to wk , i := k and goto Step 13. Step 9g. If uk ∈ bd(vj , vi ) then move gcc from its present position to vk , move gc from its present position to uk , i := k and goto Step 12. Step 9h. Increment k by 1 and goto Step 9b. Step 10. If vj uj does not intersect vi ui (Figure 4.11(a)) then perform Step 9 by considering bd(ui , uj ) in place of bd(ui , wj ). Step 11. If gc is currently at vi and gcc is currently at wi then perform Step 6 to Step 10 starting from the bounding chord vi wi in place of vi ui . Step 12. If gcc is currently at vi and gc is currently at ui then perform steps analogous to Step 6 to Step 11 by locating vj in R and vk in L. Step 13. If gcc is currently at vi and gc is currently at wi then perform Step 12 starting from the bounding chord vi wi in place of vi ui . Step 14. Report the walk of gc and gcc from s to t and Stop. The correctness of the algorithm follows from Theorem 4.5.2. Let us analyze the time complexity of the algorithm. The points s and t on bd(P ) can be located in O(n) time by the recognition algorithm presented in Section 4.4. It has been shown by Bhattacharya et al. [51] that testing for s-deadlock and t-deadlock in Steps 2 and 3 can be done in O(n) (explained later). Remaining steps of the algorithm can take O(n2 ) as gc and gcc can move back and forth along L and R, respectively. Hence the overall time complexity of the algorithm is O(n2 ) time. We summarize the result in the following theorem. Theorem 4.5.4 A walk between two boundary points s and t of a simple polygon P of n vertices can be constructed in O(n2 ) time.
4.5 Walking in an LR-Visibility Polygon
123
Let us explain how the testing for s-deadlock and t-deadlock in P can be done in O(n) time using SP T (s) and SP T (t). Note that SP T (s) and SP T (t) can be computed in O(n) time using the algorithm of Bhattacharya and Ghosh [48] presented in Section 4.6. We present here the procedure of Bhattacharya et al. [51] only for testing s-deadlock in P as the procedure for testing t-deadlock is analogous. Assume that the procedure has located the bounding chord vi ui where vi ∈ L and ui ∈ R. The procedure wishes to locate the first reflex vertex vj by scanning L from vi−1 in clockwise order such that uj ∈ R and the bounding chord vj uj does not intersect vi ui . We have the following lemma. Lemma 4.5.5 Let vi ui be a bounding chord in P , where vi ∈ L and ui ∈ R. Let vj be a reflex vertex in bd(t, vi ) such that vj is the previous vertex of vj−1 on SP (ui , vj−1 ) (Figure 4.11(a)). Then the bounding chord vj uj does not intersect vi ui . Based on the above lemma, the procedure for testing s-deadlock scans L from v i−1 in clockwise order and computes SP (ui , vm ) for every vertex vm until vj is located. It can be seen that SP (ui , vm ) follows SP (ui , t) from ui up to a vertex vq ∈ R and then jumps to a vertex vp ∈ L of SP (t, vm ) and then follows SP (t, vm ) from vp to vm . Note that vp and vm may be the same vertex. For example, vp is vj and vq is vk+2 in SP (ui , vj ) in Figure 4.11(a). It can be seen that vp vq is a tangent from vp ∈ SP (t, vm ) to SP (ui , t) at vq . Since all such tangents vp vq computed until vj is located are ordered from vi ui to vj uj , the time required for computing all these tangents is proportional to the sum of the sizes of bd(vj , vi ) and bd(ui , uj ). In order to locate uj , the procedure scans R from ui in counterclockwise order −−→ until it locates the first vertex vr (see Figure 4.11(a)) such that − v− j−1 vj does not −−→ intersect SP (t, vr ). It can be seen that entire SP (t, vr ) lies to the left of − v− j−1 vj and uj ∈ vr vr−1 . The cost of locating vr is proportional to the size of bd(ui , vr ). For more details on computing the intersection of a ray with the shortest path, see Section 3.5.2. As the sub-polygons are disjoint in P , all sub-polygons can be computed in O(n) time. Once P is partitioned into sub-polygons, the procedure proceeds to test whether there is an s-deadlock in any sub-polygon Pi . We have the following lemma. Lemma 4.5.6 Let Pi denote the sub-polygon of P bounded by two consecutive bounding chords vi ui and vj uj , where vi ∈ L, vj ∈ bd(t, vi ), ui ∈ R and uj ∈ bd(ui , t). If there exists a reflex vertex vk ∈ bd(ui , uj ) (Figure 4.11(b)) such that (i) SP (vj , vk+1 ) and SP (uj , vk+1 ) meet only at vk+1 and (ii) vk is the previous vertex of vk+1 on SP (vj , vk+1 ), then vk wk intersects vj uj . Based on the above lemma, the procedure for testing s-deadlock scans R from uj to ui in counterclockwise order and computes SP (vj , vm ) for every vertex vm ∈ bd(ui , uj ) by drawing tangents, as stated above, in time proportional to the sum of the size of bd(vj , vi ) and bd(ui , uj ). If any reflex vertex vk ∈ bd(ui , uj ) satisfies
124
LR-Visibility and Shortest Paths
Lemma 4.5.6, then P has an s-deadlock. Thus, it can be determined in O(n) whether P has an s-deadlock. We summarize the result in the following theorem. Theorem 4.5.7 Given a simple polygon P of n vertices, it can be determined in O(n) time whether P is 2-walkable between two boundary points s and t.
4.6 Computing Shortest Path Trees using LR-Visibility In this section, we present an O(n) time algorithm of Bhattacharya and Ghosh [48] for computing the shortest path tree from a vertex (say, v1 ) in a simple polygon P if P satisfies the characterization of LR-visibility polygons presented in Theorem 4.2.1. If the algorithm terminates without computing the shortest path tree SP T (v 1 ), it means that P is not an LR-visibility polygon with respect to any pair of boundary points of P . If the algorithm computes SP T (v1 ), P may be an LR-visibility polygon. If P is an LR-visibility polygon, the algorithm always succeeds in computing SP T (v1 ). Like the algorithm of Ghosh et al. [162] presented in Section 3.6.2, the algorithm computes SP T (v1 ) by scanning bd(P ) and it uses pointers and a doubly linked list as its data structures. In presenting this algorithm, we use the same notions of Sections 3.3.1 and 3.6.2. We assume that P is given as a counterclockwise sequence of vertices v1 , v2 , ..., vn . The algorithm starts by computing the visibility polygon V (v1 ) of P from v1 by the algorithm of Lee [230] presented in Section 2.2.1 (see Figure 4.12). It can be seen that if constructed edges of V (v1 ) are used to partition P , they split P into disjoint regions of P . All such regions, except V (v1 ), are called pockets of V (v1 ). Since the vertices of V (v1 ) are visible from v1 , they are children of v1 in SP T (v1 ). So, the remaining task for computing SP T (v1 ) is to compute the shortest path from v1 to each vertex of every pocket. Since the shortest path from v1 to any two vertices vi and vj of different pockets are disjoint, i.e., SP (v1 , vi ) and SP (v1 , vj ) meet only at v1 , the shortest path from v1 to the vertices of one pocket can be computed independent of other pockets of V (v1 ). So, it is enough to state the procedure for computing SP T (v1 ) to all vertices in one pocket. We have the following lemma. Lemma 4.6.1 If P is an LR-visibility polygon with respect to some pair of boundary points s and t, then at most one of s and t can lie in a pocket of V (v1 ). Proof. If both s and t lie in one pocket of V (v1 ), then either the entire L or the entire R lies in the pocket of V (v1 ). If the entire R lies in the pocket, v1 belongs to L. So, there is a point (i.e. v1 ) of L which is not visible for any point of R. So, P is not an LR-visibility polygon, which is a contradiction. Analogous arguments hold if the entire L lies in the pocket.
4.6 Computing Shortest Path Trees using LR-Visibility
125
Figure 4.12 The disjoint regions of P − V (vi ) are pockets of V (v1 ).
Corollary 4.6.2 Let P be an LR-visibility polygon with respect to s and t. If both endpoints of a constructed edge of V (v1 ) belong to either L or R (Figure 4.12), then the entire pocket is weakly visible from the constructed edge. Corollary 4.6.3 Let P be an LR-visibility polygon with respect to s and t. If one endpoint of a constructed edge of V (v1 ) belongs to L and the other belongs to R (Figure 4.12), then the pocket of V (v1 ) contains either s or t. After computing V (v1 ), the algorithm proceeds to compute the shortest paths to vertices of each pocket of V (v1 ) separately. Let vj vj0 be a constructed edge, where vj is a vertex of P and vj0 is some boundary point of P (Figure 4.12). Note that v1 , vj and vj0 are collinear. Without loss of generality, we assume that bd(P ) is traversed from v1 to vj0 in counterclockwise order. So, vj is encountered before reaching vj0 . The boundary of the pocket consists of the counterclockwise boundary of P from v j to vj0 and the segment vj vj0 . The counterclockwise (or clockwise) boundary from a boundary point z to another boundary point z 0 is denoted as bdcc (z, z 0 ) (respectively, bdc (z, z 0 )). Since the shortest path from v1 to any vertex of this pocket passes through vj , it is enough to compute SP T (vj ) in the pocket of V (v1 ) bounded by vj vj0 . The procedure for computing SP T (vj ) scans bdcc (vj , vj0 ) in counterclockwise order starting from vj+1 till it encounters a reverse turn at a vertex vcc or it reaches vj0 . This procedure is similar to the procedure mentioned in Section 3.6.2 as two cases. Assume that SPcc (vj , vj+1 ), SPcc (vj , vj+2 ),..., SPcc (vj , vi−1 ) have been computed 0 ), and the procedure wants to compute SPcc (vj , vi ). For any vertex vm ∈ bdcc (vj , vi−1 let um denote the parent of vm in SP Tcc (vj , vi−1 ), i.e., um is the previous vertex of vm in SPcc (vj , vm ). We have the following two cases.
126
LR-Visibility and Shortest Paths
Figure 4.13 (a) SPcc (vj , vi ) = (SPcc (vj , vk ), vi ). (b) SPcc (vj , vi ) = (SPcc (vj , vi−1 ), vi ). (c) There is a reverse turn at vi−1 .
−− −−−→ Case 1. The vertex vi lies to the left of u i−1 vi−1 (Figure 4.13(a)). −− −−−→ Case 2. The vertex vi lies to the right of u i−1 vi−1 . −−−→ Case 2a. The vertex vi lies to the right of v−− i−2 vi−1 (Figure 4.13(b)). −−−→ Case 2b. The vertex vi lies to the left of v−− i−2 vi−1 (Figure 4.13(c)). −− −−−→ Consider Case 1. Since vi lies to the left of u i−1 vi−1 (see Figure 4.13(a)), SPcc (vj , vi ) makes only right turns. Let vk be the first vertex of SPcc (vj , vi−1 ) → starting from vi−1 such that vi lies to the right of − u− k vk . Therefore, vk becomes the parent ui of vi in SP Tcc (vj , vi ) as vi vk is the tangent from vi to SPcc (vj , vi−1 ). Hence, SPcc (vj , vi ) = (SPcc (vj , vk ), vi ). The region enclosed by vi−1 vi , vi ui and SPcc (ui , vi−1 ) is divided into triangles by extending each edge of SPcc (ui , vi−1 ) to vi−1 vi . −− −−−→ −−−−−→ Consider Case 2a. Since vi lies to the right of both u i−1 vi−1 and vi−2 vi−1 (see Figure 4.13(b)), it means that SPcc (vj , vi ) makes only right turns, and vi−1 is the parent ui of vi in SP Tcc (vj , vi ) as vi vi−1 is the tangent from vi to SPcc (vj , vi−1 ). So, SPcc (vj , vi ) = (SPcc (vj , vi−1 ), vi ). −− −−−→ −−−−−→ Consider Case 2b. Since vi lies to the right of u i−1 vi−1 and to the left of vi−2 vi−1 (see Figure 4.13(c)), SP (vj , vi−1 ) passes through vertices of bdcc (vi , vj0 ) and therefore, SP (vj , vi−1 ) and SPcc (vj , vi−1 ) are not same. The vertex vi−1 is marked as vcc as there is a reverse turn at vi−1 . It can be seen that the above procedure of scanning bdcc (vj , vj0 ) may not reach if Case 2b occurs. Otherwise the procedure has reached vj0 , which means that SP Tcc (vj , vj0 ) has been computed. We have the following lemma. vj0
4.6 Computing Shortest Path Trees using LR-Visibility
127
Figure 4.14 (a) The cross-tangent is drawn between SP (vj0 , vi ) and SP (vj , vi−1 ). (b) The vertex vc belongs to bdcc (vj , vcc ), and SPcc (vj , vi ) and SPc (vj0 , vi ) meet only at vi .
Lemma 4.6.4 If no reverse turn is encountered during the counterclockwise scan of bdcc (vj , vj0 ) (Figure 4.13(a)), then SP Tcc (vj , vj0 ) is same as SP T (vj ). The above lemma suggests that if the scanning procedure does not terminate before reaching vj0 , it has computed SP T (vj ). Otherwise, it has computed SP Tcc (vj , vcc ). This means that (i) SP (vj , vcc ) passes through vertices of bdc (vj0 , vcc+1 ), and (ii) s or t belongs to bdcc (vj , vj0 ) by Corollary 4.6.3. From now on, we assume that the procedure has not reached vj0 . The procedure scans bdc (vj0 , vj ) in clockwise order starting from the next clockwise vertex of vj0 by the analogous procedure of the above counterclockwise scan. We have following lemma. Lemma 4.6.5 If no reverse turn is encountered during the clockwise scan of bdc (vj0 , vj ), then SP Tc (vj0 , vj ) is same as SP T (vj0 ) (Figure 4.14(a)). Exercise 4.6.1 Prove Lemma 4.6.5. The above lemma suggests that if the clockwise scan reaches vj , then it has computed SP T (vj0 ). Otherwise the clockwise scan has located a reverse turn at some vertex vc (see Figure 4.14(b)). If SP T (vj0 ) has been computed, SP T (vj ) can be computed from SP T (vj0 ) using the algorithm of Hershberger [186] presented in Section 5.2. The main step in computing SP T (vj ) from SP T (vj0 ) (see Figure 4.14(a)) is to draw the cross-tangent between SP (vj0 , vi ) and SP (vj , vi−1 ) for every vertex vi ∈ bdcc (vj , vj0 ) starting from vj+1 (see Exercises 3.6.2 and 3.6.3). All crosstangents in the pocket can be drawn in time proportional to the size of SP T (v j0 ).
128
LR-Visibility and Shortest Paths
From now on we assume that the procedure has located vc and vcc , and has computed SP Tc (vj0 , vc ) and SP Tcc (vj , vcc ). Although there are reverse turns at vc and vcc , P can still be an LR-visibility polygon. We have the following two cases. Case A. The vertex vc belongs to bdcc (vj , vcc ) (Figure 4.14(b)). Case B. The vertex vc does not belong to bdcc (vj , vcc ) (Figure 4.15(a)). Consider Case A. The algorithm computes SP T (vj ) by merging SP Tc (vj0 , vc ) and SP Tcc (vj , vcc ). Before we state the procedure for merging, we present the overall approach of the merging procedure in the following lemmas. Lemma 4.6.6 Let vj vj0 be a constructed edge of V (v1 ) in P satisfying Corollary 4.6.3. If vc ∈ bdcc (vj , vcc ), then either s or t belongs to bdcc (vc , vcc ). Proof. We know from Corollary 4.6.3 that either s or t (say, s) must belong to bdcc (vj , vj0 ). If s ∈ bdc (vj0 , vcc+1 ), then there cannot be any reverse turn at vcc as both vcc and vj belong to L. An analogous argument shows that s cannot belong to bdcc (vj , vc−1 ). Hence, s ∈ bdcc (vc , vcc ). Lemma 4.6.7 Let vp and vq be the parents of a vertex vi ∈ bdcc (vc , vcc ) in → SP Tcc (vj , vcc ) and SP Tc (vj0 , vc ), respectively. If vp lies to the left of − v− i vq , then SPcc (vj , vi ) is same as SP (vj , vi ), and SPc (vj0 , vi ) is same as SP (vj0 , vi ). 0 → Proof. If vp lies to the left of − v− i vq (see Figure 4.14(b)), SPcc (vj , vi ) and SPc (vj , vi ) 0 meet only at vi because SPcc (vj , vi ) makes only right turns and SPc (vj , vi ) makes only left turns. So, vi is visible from some point of vj vj0 . By Theorem 4.2.1, SPcc (vj , vi ) is same as SP (vj , vi ) and SPc (vj0 , vi ) is same as SP (vj0 , vi ).
The above lemma suggests that if there exists such a vertex vi ∈ bdcc (vc , vcc ), SP T (vj , vi ) is same as SP Tcc (vj , vi ). Similarly, SP T (vj0 , vi ) is same as SP Tc (vj0 , vi ). For each vertex vk starting from vi+1 in counterclockwise order, draw the crosstangent between SP (vj0 , vk ) and SP (vj , vk−1 ) as stated earlier, which gives SP T (vj ). Consider the other situation when no vertex of bdcc (vc , vcc ) satisfies the above lemma (see Figure 4.15(b)). This means that for every vertex vi ∈ bdcc (vc , vcc ), SP (vj , vi ) passes through vertices of bdc (vj0 , vi ) or SP (vj0 , vi ) passes through vertices of bdcc (vj , vi ). In order to identify all vertices of SP (vj , vi ) and SP (vj0 , vi ), we need the following lemmas. Lemma 4.6.8 For any vertex vi ∈ bdcc (vj+1 , vcc ), all vertices of SPcc (vj , vi ) belong to SP (vj , vi ). Proof. If SPcc (vj , vi ) is same as SP (vj , vi ), then the lemma holds. So, we assume that all edges of SPcc (vj , vi ) do not lie inside P (see Figure 4.15(b)). Consider any edge vk vm of SPcc (vj , vi ) not lying inside P . This edge can be intersected only
4.6 Computing Shortest Path Trees using LR-Visibility
129
Figure 4.15 (a) The vertex vc does not belong to bdcc (vj , vcc ). (b) SP (vj , vi ) and SP (vj0 , vi ) pass through vertices of bdc (vj0 , vi ) and bdcc (vj , vi ) respectively. (c) All points of bdc (zq , zk ) are not visible from R.
by the edges of bdc (vj0 , vi ). So, vk vm in SPcc (vj , vi ) is replaced by SP (vk , vm ) in SP (vj , vi ). Hence, vk and vm remain in SP (vj , vi ). Lemma 4.6.9 For any vertex vi ∈ bdc (vj0 , vc ), all vertices of SPc (vj0 , vi ) belong to SP (vj0 , vi ). Although Lemma 4.6.8 suggests that all vertices of SPcc (vj , vi ) belong to SP (vj , vi ), all edges of SPcc (vj , vi ) may not belong to SP (vj , vi ). In order to compute SP (vj , vi ), the problem is to replace each such edge vk vm of SPcc (vj , vi ) by SP (vk , vm ) (see Figure 4.15(b)). Observe that since vk vm is intersected by edges of bdc (vj0 , vi ), SP (vk , vm ) must pass through some vertices of bdc (vj0 , vi ). Moreover, SP (vk , vm ) may pass through some more vertices of bdcc (vj , vi ) (excluding vk and vm ). Observe that there exists an order in which edges of bdc (vj0 , vi ) intersect edges of SPcc (vj , vi ) in LR-visibility polygons (see Figure 4.15(b)) as shown in the following lemmas. Lemma 4.6.10 Assume that the pocket bounded by the constructed edge vj vj0 of V (v1 ) satisfies Lemma 4.6.6. Let vi be a vertex of bdcc (vc , vcc ). Let z1 , z2 ,..., zp = vi be the points of intersection of bdc (vj0 , vi ) with SPcc (vj , vi ) in the order from vj to vi on SPcc (vj , vi ) (Figure 4.15(b)). Let z0 denote vj . If P is an LR-visibility polygon, then for every intersection point zk , where 0 < k < p, zk belongs to bdc (zk−1 , vi ). Proof. Assume on the contrary that there exist two intersection points z k and zq (Figure 4.15(c)), where 0 < k < q < p, such that (i) zk lies on SPcc (vj , vi ) between vj and zq , and (ii) zk ∈ bdc (zq , vi ). If vi ∈ L or s ∈ bdc (zk , vi ), then all points of bdc (zq , zk ) are not visible from R. So, P is not an LR-visibility polygon, which is
130
LR-Visibility and Shortest Paths
Figure 4.16 (a) All children of vj in SP Tcc (vj , vcc ) are not above vj vj0 . (b) The inward edge xy is entering in the counterclockwise pocket bounded by uw and bdcc (u, w). (c) The inward edge xy is entering in the clockwise pocket bounded by uw and bdc (u, w).
a contradiction. If s ∈ bdc (vj0 , zk ), then s does not belong to bdcc (vc , vcc ), which contradicts Lemma 4.6.6. Lemma 4.6.11 Assume that the pocket bounded by the constructed edge vj vj0 of V (v1 ) satisfies Lemma 4.6.6. Let vi be a vertex of bdcc (vc , vcc ). Let z1 , z2 ,..., zp = vi be the points of intersection of bdcc (vj , vi ) with SPc (vj0 , vi ) in the order from vj0 to vi on SPc (vj0 , vi ). Let z0 denote vj0 . If P is an LR-visibility polygon, then for every intersection point zk , where 0 < k < p, zk belongs to bdcc (zk−1 , vi ). Lemma 4.6.12 Assume that the pocket bounded by the constructed edge vj vj0 of V (v1 ) satisfies Lemma 4.6.6. Let vi be a vertex of bdcc (vc , vcc ). Let vk vm be an −→ edge of SPcc (vj , vi ) where vk ∈ SPcc (vj , vm ). Let x the point of intersection of v−− k vm 0 0 and bdc (vj , vm ) lying on an edge vl vl−1 of bdc (vj , vm ) (see Figure 4.15(b)) such that (i) x does not lie on vk vm , and (ii) x is the first point of intersection while traversing bdc (vj0 , vm ) in clockwise order from vj0 . If P is an LR-visibility polygon, then bdc (vl−1 , vm+1 ) does not intersect the segment xvm . Proof. The proof follows along the line of the proof of Lemma 4.6.10. Lemma 4.6.13 Assume that the pocket bounded by the constructed edge vj vj0 of V (v1 ) satisfies Lemma 4.6.6. Let vi be a vertex of bdcc (vc , vcc ). Let vk vm be an −→ edge of SPc (vj0 , vi ) where vk ∈ SPc (vj0 , vm ). Let x the point of intersection of v−− k vm and bdcc (vj , vm ) lying on an edge vl vl−1 of bdcc (vj , vm ) such that (i) x does not lie on vk vm , and (ii) x is the first point of intersection while traversing bdcc (vj , vm ) in
4.6 Computing Shortest Path Trees using LR-Visibility
131
Figure 4.17 (a) The inward edge xy has intersected the extension ww 0 . (b) The inward edge xy has intersected the ray drawn from u through w. (c) The inward edge xy is updated to the next clockwise edge of xy.
counterclockwise order from vj . If P is an LR-visibility polygon, then bdcc (vl , vm−1 ) does not intersect the segment xvm . The ordered properties of intersection points in the above lemmas suggest a method for locating all edges of bdc (vj0 , vi ) intersecting SPcc (vj , vi ) as follows. Let vj vk be the first edge of SPcc (vj , vi ). Scan bdc (vj0 , vi ) from vj0 until an edge of → −−→ bdc (vj0 , vi ) intersects the current edge vj vk or − v− j vk . If vj vk is intersected, take the next edge of vj vk in SPcc (vj , vi ) as the current edge and repeat the process of checking the intersection. If an edge of bdc (vj0 , vi ) intersects vj vk , then continue the scan until another edge of bdc (vj0 , vi ) intersects vj vk . Once another edge is found intersecting vj vk , continue the scan as before to check for intersection with vj vk or 0 − → v− j vk . This method is used in the merging procedure for locating edges of bd c (vj , vi ) intersecting edges of SPcc (vj , vi ) for all vi using SP Tcc (vj , vcc ). The merging procedure maintains two current edges xy (called an inward edge), and uw (called a lid) and it checks the intersection between the current inward edge and the current lid. The merging procedure starts by assigning vj0 to x, the next clockwise vertex of x on bdc (vj0 , vi ) to y, vj to u, and the next vertex of vj on SPcc (vj , vcc ) to w. The above initialization of xy and uw is correct if all children of −−→ vj in SP Tcc (vj , vcc ) lie on the same side of vj vj0 . If children of vj lie on both sides −−→ of vj vj0 (see Figure 4.16(a)), w is assigned to the last child of vj in counterclockwise −−→ order around vj , lying to the right of vj vj0 . Intuitively, the situation after initialization can be viewed as the inward edge xy entering the pocket induced by uw. In general, there are two situations: either the inward edge xy from bdc (vj0 , vc ) is entering in the counterclockwise pocket bounded
132
LR-Visibility and Shortest Paths
Figure 4.18 (a) The inward edge xy is updated to vk vk−1 . (b) The point z ∈ bdc (y, vcc ). (c) The point z ∈ bdcc (vc , vcc ).
by uw and bdcc (u, w) (see Figure 4.16(b)) or the inward edge xy from bdcc (vj , vcc ) is entering in the counterclockwise pocket bounded by uw and bdc (u, w) (see Figure 4.16(c)). Since these two cases are symmetric, we present the procedure only for the former situation, i.e., the inward edge xy from bdc (vj0 , vc ) is entering the counterclockwise pocket bounded by uw and bdcc (u, w) (see Figure 4.16(b)). Step 1. While xy intersects uw do remove uw from SP Tcc (vj , vcc ) and w := the next clockwise child of u in SP Tcc (vj , vcc ) (see Figure 4.16(b)). Step 2. If xy intersects the extension ww 0 (if it exists) of uw (see Figure 4.17(a)) then u := w, w := the next clockwise child of w in SP Tcc (vj , vcc ) and goto Step 1. → (see Figure 4.17(b)) then u := w, w:= the next vertex Step 3. If xy intersects − uw of w on SPcc (vj , vcc ) and goto Step 1.
− → Step 4. Let y 0 be the next counterclockwise vertex of y. If y 0 lies to the right of uy 0 (see Figure 4.17(c)) then x := y, y := y and goto Step 1. → (see Figure 4.18(a)) then scan the boundary in Step 5. If y 0 lies to the right of − xy counterclockwise order starting from y 0 until an edge vk vk−1 intersecting uy is found, assign vk vk−1 as the inward edge xy and goto Step 1. → Extend uy from y to bd(P ) meeting it Step 6. (Remark: y 0 lies to the left of − xy). at a point z. Assign u as the parent of y in SP Tcc (vj , vcc ).
Step 6a. If z belongs to an edge of bdc (y, vcc ) (see Figure 4.18(b)) then concatenate the sub-tree of SP Tc (vj0 , vc ) rooted at y to SP Tcc (vj , vj0 ) by assigning u as the parent of y, assign the edge containing z as the inward edge xy and goto Step 1. Step 6b. If z belongs to an edge of bdcc (vc , vcc ) (see Figure 4.18(c)) then concate-
4.6 Computing Shortest Path Trees using LR-Visibility
133
Figure 4.19 (a) The point z ∈ bdcc (vj , vc ). (b) The parents of vertices vp−1 , vp−2 ,..., vq+1 in SP Tcc (vj , vj0 ) are yet to be computed.
nate the sub-tree of SP Tc (vj0 , vc ) rooted at y to SP Tcc (vj , vj0 ) by assigning u as the parent of y and goto Step 7. Step 6c. If z belongs to an edge of bdcc (vj , vc ) (see Figure 4.19(a)) then locate → passes between y 00 and its next the child y 00 of y in SP Tc (vj0 , vc ) such that − uy sibling in clockwise order, w := y 00 , u := y, assign the edge containing z as the inward edge xy and call the analogous procedure for checking the intersection of inward edge xy entering into the clockwise pocket induced by uw. Step 7. Let vp vp−1 ,..., vq+1 vq be the consecutive edges such that the parents of intermediate vertices vp−1 , vp−2 ,..., vq+1 in SP Tcc (vj , vj0 ) are not yet computed (see Figure 4.19(b)). Compute the parent of every vertex vi ∈ bdcc (vq+1 , vp−1 ) in SP Tcc (vj , vj0 ) starting from vq+1 by drawing the tangent from vi meeting SPcc (vj , vp ) or SPcc (vj , vi−1 ). If SP Tcc (vj , vj0 ) is not computed completely goto Step 7. Step 8. Output SP Tcc (vj , vj0 ) as SP T (vj ) and Stop. Consider Case B. We know that the vertex vc does not belong to bdcc (vj , vcc ) (Figure 4.15(a)). We have the following lemma. Lemma 4.6.14 Let vj vj0 be a constructed edge of V (v1 ) in P satisfying Corollary 4.6.3. If vc does not belong to bdcc (vj , vcc ), then the parent of vcc in SP T (vj ) is a vertex of bdc (vj0 , vc ) or the parent of vc in SP T (vj0 ) is a vertex of bdcc (vj , vcc ). Proof. Let vp and vq be the parents of vcc and vc in SP T (vj ) and SP T (vj0 ), respectively (see Figure 4.15(a)). Since there is a reverse turn at vcc , vp ∈ bdc (vj0 , vcc+1 ). If vp ∈ bdc (vj0 , vc ), then the lemma holds. So we assume that vp ∈ bdc (vc , vcc+1 ). In
134
LR-Visibility and Shortest Paths
that case, s ∈ bdcc (vj , vp−1 ). It means that there cannot be any reverse turn at any vertex vc in bdc (vj0 , s) as both s and vj0 belong to L, which is a contradiction. So s ∈ bdcc (vj , vcc ) or vp ∈ bdc (vj0 , vc ). Analogous arguments show that s ∈ bdc (vj0 , vc ) or vq ∈ bdcc (vj , vcc ). If s ∈ bdcc (vj , vcc ), then vq must belong to bdcc (vj , vcc ), or if s ∈ bdc (vj0 , vc ), then vp must belong to bdc (vj0 , vc ). Corollary 4.6.15 The boundary bdcc (vj , vcc ) intersects the last edge of SPc (vj0 , vc ) or bdc (vj0 , vc ) intersects the last edge of SPcc (vj , vcc ).
The above corollary suggests that by checking the intersection of bdc (vj0 , vc ) with SPcc (vj , vcc ), the parent of vcc in SP Tcc (vj , vj0 ) can be located. The intersection can be checked by the merging procedure stated as Step 1 to Step 8 in Case A. If the parent of vcc in SP Tcc (vj , vcc ) changes after checking the intersection (i.e. vcc vcc−1 becomes an inward edge), the procedure scans in counterclockwise order from v cc till it finds a new vcc . Again, the merging procedure is used to find the parent of the new vcc . This process of scanning and merging is repeated till SP Tcc (vj , vj0 ) is computed completely. Consider the other situation when the parent of vcc in SP Tcc (vj , vcc ) has not changed after vcc is reached by the merging procedure. In that case, the analogous steps of the merging procedure is used to check the intersection between bdcc (vj , vcc ) with SPc (vj0 , vc ). If the parent of vc changes in SP Tc (vj0 , vc ), the procedure scans in clockwise order from vc till it finds a new vc , and the entire process is repeated with new vc and vcc . If the parent of vc also does not change in SP Tc (vj0 , vc ) after vc is reached by the merging procedure, then P is not an LRvisibility polygon by Lemma 4.6.14. Finally, the procedure gives SP Tcc (vj , vj0 ) or SP Tc (vj0 , vj ). If the procedures gives SP Tc (vj0 , vj ), SP Tcc (vj , vj0 ) can be constructed from SP Tc (vj0 , vj ) by drawing cross-tangents as stated earlier. The correctness of the merging procedure follows from Lemmas 4.6.6, 4.6.10, 4.6.11, 4.6.12, 4.6.13 and 4.6.14. Let us analyze the time complexity of the merging procedure. For each constructed edge vj vj0 , SP Tcc (vj , vcc ) and SP Tc (vj0 , vc ) can be computed in time proportional to the number of vertices of bdcc (vj , vj0 ). The merging procedure considers each edge of SP Tcc (vj , vcc ) and SP Tc (vj0 , vc ) at most twice. Note that all such points z in Step 6 of the merging procedure can be computed using SP Tcc (vj , vcc ) and SP Tc (vj0 , vc ) in a time that is proportional to the sum of sizes of SP Tcc (vj , vcc ) and SP Tc (vj0 , vc ). Therefore, SP T (vj ) can be computed in a time that is proportional to the number of vertices in bdcc (vj , vj0 ). Therefore, the merging takes O(n) time for all pockets of V (v1 ). We summarize the result in the following theorem. Theorem 4.6.16 The shortest path tree from a vertex inside an n-sided simple polygon P can be computed in O(n) time if P is a LR-visibility polygon.
4.7 Notes and Comments
135
4.7 Notes and Comments In the recent years, several on-line algorithms have been designed for LR-visibility polygons (also called streets) in the context of robot path planning. These algorithms are designed for situations where a robot moves in an environment without completely knowing the geometry of the environment, navigating on the basis of local information provided by acoustic, visual or tactile sensors. A natural scenario in robotics is that of searching for a goal in an unknown polygonal region, i.e., a robot with an on-board vision system is placed at a starting point s in a polygon and it must traverse a path to some target point t in the polygon. A problem in the above scenario is to design efficient algorithms which a robot can use to search for the target. Any such algorithm is on-line in the sense that decisions must be made based only on what the robot has seen so far. For target-searching problems (searching a point t from a starting point s), researchers have designed algorithms that minimize the Euclidean distance traveled by a robot in reaching the target point. They have also investigated this problem for streets for which better performance could be obtained. In the spirit of analyzing on-line algorithms by following the concept introduced by Sleator and Tarjan [312] for problems in computer science in general, the efficiency of such algorithms is determined by their competitive ratio: the worst-case ratio of the length of the path from s to t traversed by the on-line algorithm to the length of the Euclidean shortest path between s and t. Klein [219] proposed an on-line algorithm with competitive ratio 1 + 3π/2 for √ the target-searching problem in a street. He also showed for this problem that 2 is the lower bound on the competitive ratio. Since then, several on-line algorithms have been designed improving the upper bound of the competitive ratio [105, 220, 246, 247] and finally, an optimal on-line algorithm has been designed by Icking et al. [202]. For the corresponding problem of minimizing the number of links in the link path between s and t, Ghosh and Saluja [166] proposed an optimal on-line algorithm whose competitive ratio is 1 + 1/m, where m is the link distance between s and t. For the target-searching problem in a generalized street, on-line algorithms were proposed by Datta and Icking [106] and Lopez-Ortiz and Schuierer [247]. There are on-line algorithms also for the target-searching problem in an unknown star-shaped polygon, where t is any point in the kernel of the star-shaped polygon [201, 238, 248].
5 Visibility Graphs
5.1 Problems and Results The visibility graph is a fundamental structure in computational geometry; some early applications of visibility graphs include computing Euclidean shortest paths in the presence of obstacles [249] and in decomposing two-dimensional shapes into clusters [306]. The visibility graph (also called the vertex visibility graph) of a polygon P with or without holes is the undirected graph of the visibility relation on the vertices of P . The visibility graph of P has a node for every vertex of P and an edge for every pair of visible vertices in P . Figure 5.1(b) shows the visibility graph of the polygon in Figure 5.1(a). We sometimes draw the visibility graph directly on the polygon, as shown in Figure 5.1(c). It can be seen that every triangulation of P corresponds to a sub-graph of the visibility graph of P . The visibility graph of a line segment arrangement is defined similarly, where the endpoints of the line segments are represented as the nodes of the visibility graph. Consider the problem of computing the visibility graph of a polygon P (with or without holes) having a total of n vertices. The visible pairs of vertices in P can
Figure 5.1 (a) A polygon. (b) The visibility graph of the polygon. (c) The visibility graph drawn on the polygon.
136
5.1 Problems and Results
137
Figure 5.2 (a) The visibility graph of this polygon with holes has O(n2 ) edges. (b) The visibility graph of this polygon with holes has O(n) edges.
be computed by checking intersections of segments connecting pairs of vertices in P with each polygonal edge of P . This naive method takes O(n3 ) time as in the first algorithm for computing the visibility graph given by Lozano-Perez and Wesley [249]. Lee [229] and Sharir and Schorr [307] improved the time complexity by designing O(n2 log n) time algorithms. Asano et al. [28] and Welzl [339] later developed O(n 2 ) time algorithms for this problem. Since, at its largest, the visibility graph can be of size O(n2 ) (see Figure 5.2(a)), the algorithms of Asano et al. and Welzl are worst-case optimal. In Section 5.3.1, we present the algorithm of Welzl [339]. Exercise 5.1.1 Draw a simple polygon of n vertices whose visibility graph has 2n − 3 edges (including n polygonal edges) [271]. The visibility graph may be much smaller than its worst-case size of O(n2 ) (in particular, it can have O(n) edges (see Figure 5.2(b)) and therefore, it is not necessary to spend O(n2 ) time to compute it. In other words, the lower bound on the time to compute a visibility graph can be expressed as Ω(n2 ), but a more exact lower bound is Ω(E), where E is the number of edges in the visibility graph. Matching this lower bound, Hershberger [186] developed an O(E) algorithm for computing the visibility graph of a simple polygon which we present in Section 5.2. An algorithm that takes time depending on its output size E is called output-sensitive. Overmars and Welzl [278] gave an O(E log n) time, O(n) space algorithm for computing the visibility graph for a polygon with holes. Ghosh and Mount [165] presented O(n log n + E) time, O(E + n) space algorithm for this same problem; we present this algorithm in Section 5.3.2. Keeping the same time complexity, Pocchiola and Vegter [286] improved the space complexity to O(n). Kapoor and Maheshwari [209] proposed another algorithm for this problem for a polygon with h holes that runs
138
Visibility Graphs
in O(h log n + T + E) time, where T is the time for triangulating a polygon. Note that a polygon with h holes can be triangulated in O(n + h log 1+² h) time [43]. Consider the problem of computing the Euclidean shortest path SP (s, t) between two points s and t inside a polygon P having a total of n vertices. If P is a simple polygon, SP (s, t) can be computed in O(n) time by the algorithm of Lee and Preparata [235] (see Section 3.6.1). If P contains holes, SP (s, t) can be computed using the visibility graph of P as follows. Compute the visibility graph of P using the algorithm of Ghosh and Mount [165] in O(n log n + E) time. Represent s as a node in the visibility graph and connect it by edges to those nodes in the visibility graph whose corresponding vertices in P are visible from s. This can be done in O(n log n) time using the algorithm of Asano [27] (see Section 2.3). Similarly, the node corresponding to t is connected to the visibility graph of P . Once the visibility graph of n+2 nodes is constructed, the Euclidean distance between every visible pair of vertices in P are assigned as the weight to the corresponding edge in the visibility graph. Thus a weighted visibility graph is constructed, and using the algorithm of Fredman and Tarjan [143], the shortest path from the node corresponding to s to all nodes in the weighted visibility graph can be computed in O(n log n + E) time. We have the following theorem. Theorem 5.1.1 The Euclidean shortest path between two points inside a polygon P with holes of total n vertices can be computed in O(n log n + E) time, where E is the number of edges in the visibility graph of P . Suppose a partial visibility graph of P is computed such that all edges of SP (s, t) belong to the partial visibility graph. So, SP (s, t) can still be computed from the partial visibility graph using the algorithm of Fredman and Tarjan [143]. It is better to compute such a partial visibility graph of P because it reduces the running time of the algorithm of Fredman and Tarjan [143]. This approach of computing a partial visibility graph of P (also called the tangent visibility graph [285]) has been taken by Rohnert [298] and Kapoor et al. [210]. Rohnert [298] has proposed an O(n+h 2 log h) time algorithm for computing the tangent visibility graph of P , where P contains h convex holes. If the holes in P are non-convex, the graph can still be computed in the same time complexity as shown by Kapoor et al. [210]. We present the algorithm of Rohnert [298] in Section 5.4.1 and the algorithm of Kapoor et al. [210] in Section 5.4.2.
5.2 Computing Visibility Graphs of Simple Polygons In this section, we present the algorithm of Hershberger [186] for computing the visibility graph of a given simple polygon P in O(E) time, where E is the number of edges in the visibility graph of P . We assume that P is given as a counterclockwise sequence of vertices v1 , v2 , . . . , vn .
5.2 Computing Visibility Graphs of Simple Polygons
139
Suppose, for every vertex vi ∈ P , the visibility polygon V (vi ) of P is computed using the algorithm of Lee presented in Section 2.2. For every vertex vj belongs to V (vi ), the corresponding nodes of vi and vj are connected by an edge in the visibility graph of P . We call such segment vi vj as visible segment in P . Since every visible segment vi vj for all i and j in P occurs in two visibility polygons V (vi ) and V (vj ), the union of all visible segments in V (v1 ), V (v2 ),..., V (vn ) gives the visibility graph of P . Since, the algorithm of Lee runs in O(n) time, this process of computing the visibility graph of P by computing V (v1 ), V (v2 ),..., V (vn ) takes O(n2 ) time. Suppose, the shortest path trees SP T (v1 ), SP T (v2 ),..., SP T (vn ) are computed in P instead of computing V (v1 ), V (v2 ),..., V (vn ). Since each visible segment must appear at least in two such trees, the visibility graph of P can also be computed by computing SP T (v1 ), SP T (v2 ),..., SP T (vn ). If these trees are computed independently, this process again takes O(n2 ) time, as the algorithm of Guibas et al. [178] for computing the shortest path tree from a vertex in P takes O(n) time (see Section 3.3.2). It has been shown by Hershberger that SP T (v 1 ), SP T (v2 ),..., SP T (vn ) can be computed in O(E) time. Assume that SP T (vi ) has been computed and the procedure wants to compute SP T (vi+1 ). In order to compute SP T (vi+1 ), it is enough to locate those vertices vj of P such that the parents of vj in SP T (vi ) and SP T (vi+1 ) are different. For the remaining vertices of P , the parents are the same in both SP T (vi ) and SP T (vi+1 ). Hence, the cost of computing SP T (vi+1 ) is same as the cost of locating such vertices vj and their parents in SP T (vi+1 ). We show later that the sum of these costs for computing SP T (vi+1 ) for all i is O(E). In the following lemma, we present the main idea used by the algorithm for locating such vertices vj . Lemma 5.2.1 For every vertex vj of P , the parents of vj in SP T (vi ) and SP T (vi+1 ) are different if and only if vj is visible from some internal point of the edge vi vi+1 . Proof. If vj is visible from some internal point u on vi vi+1 (see Figure 5.3(a)), then both SP (vi , vj ) and SP (vi+1 , vj ) cannot intersect the segment uvj (except at vj ). So, all vertices in SP (vi , vj ) must lie on the clockwise boundary from vi to vj (i.e., bd(vj , vi )). Hence, the parent of vj in SP T (vi ) belongs to bd(vj , vi ). Analogously, all vertices in SP (vi+1 , vj ), including the parent of vj in SP T (vi+1 ), belong to bd(vi+1 , vj ). Therefore, the parents of vj in SP T (vi ) and SP T (vi+1 ) are different. Now we prove the converse. Assume on the contrary that vj is not visible from any internal point of the edge vi vi+1 but the parents of vj in SP T (vi ) and SP T (vi+1 ) are different. Let vp and vq denote the parents of vj in SP T (vi ) and SP T (vi+1 ), → −−→ respectively (see Figure 5.3(a)). Consider − v− j vp and vj vq . If SP (vi , vp ) intersects − → v− j vp other than at vp , then vp cannot be the parent of vj in SP T (vi ). So, SP (vi , vp ) → −−→ does not intersect − v− j vp . Analogously, SP (vi+1 , vq ) does not intersect vj vq (except → at vq ). So, vi and vi+1 lie on opposite sides of the wedge formed by rays − v− j vp and
140
Visibility Graphs
Figure 5.3 (a) The vertex vj is visible from an internal point u of vi vi+1 . (b) There are three types of vertices in V (vi vi+1 ).
− → v− j vq . Therefore, the wedge intersects vi vi+1 . Hence vj is visible from some internal point u of vi vi+1 , which is a contradiction. The above lemma suggests that the parents of those vertices of P , that do not belong to the weak visibility polygon V (vi vi+1 ) of P from vi vi+1 , remain unchanged while computing SP T (vi+1 ) from SP T (vi ). This means that once SP T (vi+1 ) is computed within V (vi vi+1 ), the entire SP T (vi+1 ) has been computed. The task is now to compute SP T (vi+1 ) within V (vi vi+1 ) using the structure of SP T (vi ). Observe that there can be three types of vertices in V (vi vi+1 ) (see Figure 5.3(b)): (i) the vertices of V (vi vi+1 ) that are visible from some internal point of vi vi+1 satisfying Lemma 5.2.1, (ii) the vertices of V (vi vi+1 ) that are only visible from vi (if vi is a reflex vertex), and (iii) the vertices of V (vi vi+1 ) that are only visible from vi+1 (if vi+1 is a reflex vertex). For vertices of type (ii), the shortest path from vi+1 to any such vertex passes through vi . So, the sub-tree rooted at vi in SP T (vi ) containing vertices of type (ii) and their descendants becomes the sub-tree of SP T (vi+1 ) with vi+1 as the parent of vi . For vertices of type (iii), the sub-tree rooted at vi+1 in SP T (vi ) becomes the sub-tree of SP T (vi+1 ). The parent of vertices of type (i) in SP T (vi+1 ) can be computed using the shortest path map of SP T (vi ) as follows (see Figure 5.4(a)). It can be seen that SP T (vi ) partitions the internal region of P into funnels, where the edges of P are the bases of funnels. The apex of a funnel F with base vj vj+1 is the least common ancestor (say, vk ) of vj and vj+1 in SP T (vi ). So, SP (vk , vj ) and SP (vk , vj+1 ) are two sides of F . For more details on the properties of a funnel, see Section 3.6.1. If F is not a triangle, then extend each edge of SP (vk , vj ) and SP (vk , vj+1 ) to vj vj+1 and insert the extension points on vj vj+1 . It can be seen that these extensions partition F into
5.2 Computing Visibility Graphs of Simple Polygons
141
Figure 5.4 (a) The shortest path map SP M (vi ) gives the right constructed edges of V (vi vi+1 ). (b) The segment xvk is the tangent from x to SP (vi+1 , y).
triangles. Similarly, partition all funnels in P into triangles and it gives the shortest path map of SP T (vi ) (denoted as SP M (vi )). The extensions of the sides of a funnel are called extension edges of SP M (vi ). We know that only the endpoints of a constructed edge of V (vi vi+1 ) lie on bd(P ), and one of them is a vertex of P . For a constructed edge vp q, if vp precedes q in clockwise order on the boundary of V (vi vi+1 ), then we say vp q is a left constructed edge and a right constructed edge (see Figure 5.4(a)), otherwise. We have the following observation. Lemma 5.2.2 The right and left constructed edges of V (vi vi+1 ) are extension edges of SP M (vi ) and SP M (vi+1 ), respectively. Exercise 5.2.1 Prove Lemma 5.2.2. The above lemma suggests that the right constructed edges of V (vi vi+1 ) can be identified from SP M (vi ). However, the left constructed edges of V (vi vi+1 ) are not readily available as SP M (vi+1 ) is yet to be constructed. So the task is to construct SP M (vi+1 ), which can be done by traversing SP M (vi ) and using Lemma 5.2.1 as follows. Assume that the procedure has computed SP T (vi+1 ) up to a vertex or point y by traversing bd(P ) in counterclockwise order starting from vi+1 . Initially, y is vi+1 . Let x denote the current vertex or point under consideration. If vi+1 is a convex vertex, x is initialized to the next counterclockwise vertex or point of vi+1 on bd(P ). Otherwise, x is initialized to the endpoint of the extension edge of SP M (vi ) whose other endpoint is vi+1 . So, the segment xy is partially or totally an edge of P , or a right constructed edge of V (vi vi+1 ). If x is a vertex, then z denotes the parent
142
Visibility Graphs
Figure 5.5 (a) The visible segment uvm is the cross-tangent between SP (vi , x) and SP (vi+1 , y). (b) The vertex x is not a leaf of SP T (vi ).
of x in SP T (vi ). Otherwise, zx denotes the extension edge of SP M (vi ). We have following steps for computing SP T (vi+1 ) and SP M (vi+1 ) for vertices of type (i). Step 1. Scan SP (vi+1 , y) starting from y until a vertex vk is reached such that xvk is either the tangent from x to SP (vi+1 , y) (Figure 5.4(b)) or z lies to the left of − → (Figure 5.5(a)). xv k → then Step 2. If z lies to the left of − xv k
Step 2a. Draw the cross-tangent uvm between SP (vi , z) and SP (vi+1 , vk ) where u ∈ SP (vi , z) and vm ∈ SP (vi+1 , vk ) (Figure 5.5(a)).
Step 2b. Add uu0 as an extension edge of SP M (vi+1 ), where u0 is the intersection → point of − v− m u and xy. Step 2c. Connect the sub-tree of SP T (vi ) rooted at u (along with the map) to SP T (vi+1 ) by assigning vm as the parent of u. Step 2d. Extend each edge of SP (vm , y) to xy to form the extension edges of SP M (vi+1 ). Step 2e. Assign u to y and goto Step 7.
Step 3. Extend each edge of SP (vk , y) to xy to form extension edges of SP M (vi+1 ). Step 4. If x is a point or a leaf of SP T (vi ) then assign vk as the parent of x in SP T (vi+1 ), assign x to y and goto Step 7. Step 5. Add the extension edge xw of SP M (vi ) as an extension edge of SP M (vi+1 ) (Figure 5.5(b)). Step 6. Connect the sub-tree of SP T (vi ) rooted at x (along with the map) to SP T (vi+1 ) by assigning vk as the parent of x. Assign w to y.
5.3 Computing Visibility Graphs of Polygons with Holes
143
Step 7. Assign the next counterclockwise vertex or point of y on bd(P ) to x. If x is not vi then goto Step 1. Step 8. Assign vi+1 as the parent of vi . Remove from bd(P ) the endpoints of the extension edges of SP M (vi ) that are on the boundary of V (v1 vi+1 ) and Stop. Once SP T (v1 ) is computed, the above procedure can be used to compute V (v1 v2 ), SP T (v2 ), V (v2 v3 ), SP T (v3 ),..., V (vn−1 vn ), SP T (vn ). Using the algorithm of Guibas et al. [178] (see Section 3.3.2), SP T (v1 ) can be computed in O(n) time. The correctness of the algorithm follows from Lemmas 5.2.1 and 5.2.2. We analyze the time complexity of the algorithm. Consider a visible segment vj vk . It is obvious that vj vk appears as an edge in SP T (vj ) and SP T (vk ). Let vj vj0 and vk vk0 denote the two extension edges of vj vk , where vj0 ∈ vp vp+1 and vk0 ∈ vq vq+1 . So, vj vk appears as an edge in at least two trees among SP T (vp ), SP T (vp+1 ), SP T (vq ) and SP T (vq+1 ). Therefore, the algorithm considers a visible segment and its extension edges at most four times while computing tangents inside a weak visibility polygon. Hence, the overall time complexity of the algorithm is O(E). We summarize the result in the following theorem. Theorem 5.2.3 The visibility graph of a simple polygon P can be computed in O(E) time, where E is the number of edges in the visibility graph of P .
5.3 Computing Visibility Graphs of Polygons with Holes 5.3.1 Worst-Case: O(n2 ) Algorithm In this section, we present the algorithm of Welzl [339] for computing the visibility graph of a set S of n disjoint line-segments in O(n2 ) time. The endpoints of the line-segments s1 , s2 , . . . , sn are marked as v1 , v2 , . . ., v2n , where v2i−1 and v2i are endpoints of si . Any segment vi vj is said to be a visible segment if vi vj does not intersect any line-segment in S. We know that the visibility polygon V (vi ) from each vertex vi can be computed in O(n log n) time by the algorithm of Asano [27] presented in Section 2.3. Once V (vi ) is known, then all visible segments with vi as one endpoint are also known. Hence, the visibility graph of S can be computed in O(n2 log n) time. Welzl [339] has shown that V (vi ) can be computed in O(n) time once slopes of all segments between vi and all other endpoints in S are given in the sorted angular order around vi . We show later that this sorted angular order for all vertices can be computed in O(n2 ). Let Li denote the list of all segments connecting vi with every other endpoint of S. Assume that the segments in Li are given in the counterclockwise angular order around vi . The problem is to identify those segments in Li that are visible segments. Let sk be the first line-segment in S intersected by the ray emanating from vi in the vertical direction downward (see Figure 5.6(a)). In other words, s k is the current
144
Visibility Graphs
Figure 5.6 (a) The vertical ray is drawn from each endpoint of line-segments of S. (b) The segment vi vj is not a visible segment.
line-segment visible from vi in the direction vertically downward from vi . Let ui denote the current point on the boundary of V (vi ) visible from vi . Initialize ui by the intersection point of sk and the downward vertical ray from vi . In general, let vi vj be the next counterclockwise segment of vi ui in Li . Without loss of generality, we assume that vj+1 is the other endpoint of vj of the same line-segment in S. We have the following cases. Case 1. The segment vi vj intersects sk (Figure 5.6(b)). Case 2. The segment vi vj does not intersect sk . Case 2a. The vertex vj+1 is the vertex vi (Figure 5.7(a)). → Case 2b. The vertex vj+1 lies to the left of v−− i vj (Figure 5.7(b)). → Case 2c. The vertex vj+1 lies to the right of v−− i vj (Figure 5.7(c)). In Case 1, vi vj is not a visible segment. So, sk remains the same and the intersection point of vi vj and sk is assigned to ui . Consider Case 2. We know that vi vj is a visible segment (see Figure 5.7). If vi vj itself is a line-segment in S → (i.e., Case 2a), then it is not a new visible segment and the intersection point of − v− i vj and sk is assigned to ui . Otherwise, vi vj is added to the list of visible segments of → vi . If vj+1 lies to the left of v−− i vj (i.e., Case 2b), then vj vj+1 becomes the current visible line-segment in place of sk and vj becomes the current ui . If vj+1 lies the → −−→ right of − v− i vj (i.e., Case 2c), locate the line-segment sm intersecting vi vj such that the intersection point on sm is the closest to vi among all other intersection points → −−→ on − v− i vj . If vi vj does not intersect any line-segment in S, we assume that there is a line-segment sn+1 at infinity and sm is sn+1 . Once the testing of vi vj is over, the algorithm takes the next counterclockwise segment of vi ui in Li and proceeds as before. This process of rotation at vi is repeated till all segments in Li have been
5.3 Computing Visibility Graphs of Polygons with Holes
145
Figure 5.7 (a) The vertex vj+1 is the vertex vi . (b) The vertex vj is visible from vi . (c) The segment vj vj+1 is the line-segment sk .
considered. It can be seen that each vi vj of Li can be tested in O(1) time provided locating sm in Case 2c can also be done in O(1) time. We have the following observation. Lemma 5.3.1 Let vi vj be the next segment of vi ui in the counterclockwise order around vi , where ui is a point on the current visible line-segment sk of vi (Figure 5.7(c)). If vj is an endpoint of sk , then the next visible line-segment sm of vi is the → current visible line-segment of vj in the direction − v− i vj . The above lemma suggests that if the current visible line-segment in the direction − → v− v i j is known for all vj at the time of processing Li , then each vi vj of Li can be tested in O(1) time. Suppose, starting from the initial vertical direction, the algorithm has → also processed all segments in Lj up to a segment vj vp where − v− i vj is lying between vj vp and its next segment in Lj . In that case sm is the current visible line-segment of vj . So, vj vp should be processed before processing vi vj , which suggests an order of processing. It can be seen that the segments in Li and Lj can be merged into one list, say Lij , according to their angle with the initial vertical directions at vi and vj respectively. Then, the rotation can be done at either vi or vj depending upon the next segment in Lij . In the same way, a combined merged list L can be constructed by merging L1 , L2 , . . . , L2n . We call L as the order of rotation for S. The merging of 2n sorted lists having n elements in each list takes O(n2 log n) time using pair-wise merging. This can be improved to O(n2 ) by computing L directly from S without going through merging, using duality of lines and points as shown in the following lemma.
146
Visibility Graphs
Lemma 5.3.2 Let D denote the set of all segments between any two endpoints of n line-segments in S. The order of rotation for the segments in D can be constructed in O(n2 ) time. Proof. Let A be the arrangement of 2n lines which is the dual to the configuration of endpoints v1 , v2 , . . . , v2n . This means that every endpoint vi = (ai , bi ) is mapped to a line Ti with equation y = ai x + bi . We know that every intersection point wij = (aij , bij ) in A of two lines Ti and Tj corresponds to the line y = −aij x + bij passing through vi and vj . Hence, the direction of every segment in D with slope k corresponds to an intersection in A with x-coordinate −k and vice versa. Consider all intersection points on Ti in the order along Ti . It can be seen that this order is same as the angular order around vi of all segments in D with endpoint vi . For any two consecutive intersection points wij and wik on every Ti , a direction can be assigned from wij to wik if wij is to the right of wik . Let G represent an acyclic directed graph, where every intersection point in A is represented as a node in G and every direction assigned in A is represent as a corresponding directed edge in G. It has been shown by Chazelle et al. [77] and Edelsbrunner et al. [120] that G can be constructed from A in O(n2 ) time. Once G is constructed, topological sorting of G gives the order of rotation for S, which can also be computed in O(n2 ) time (see Kozen [221]). In the following, we state the major steps of the algorithm. Step 1. Compute the order of rotation for all segments between any two endpoints of the given n line-segments in S. Step 2. Traverse the order of rotation and test whether the current segment v i vj in the order is a visible segment. Step 3. Output the visibility graph of S. The correctness of the algorithms follows from Lemmas 5.3.1 and 5.3.2. We summarize the result in the following theorem. Theorem 5.3.3 The visibility graph of a set of n disjoint line-segments can be computed in O(n2 ) time. Exercise 5.3.1 Design an algorithm for computing the visibility graph of a polygon with holes with a total of n vertices in O(n2 ) time.
5.3.2 Output-Sensitive: O(n log n + E) Algorithm In this section, we present an O(n log n + E) time algorithm given by Ghosh and Mount [165] for computing the visibility graph of a polygon P with holes, where n
5.3 Computing Visibility Graphs of Polygons with Holes
147
Figure 5.8 (a) The edges of vi are on the opposite side of li . (b) Both edges of vi are on the left of li . (c) Both edges of vi are on the right of li .
and E are the number of vertices and edges of the visibility graph of P , respectively. This algorithm uses four key ideas. The first is a plane-sweep triangulation of P . The second is the funnel sequence of every edge in the triangulation of P . The third is the funnel sequence enhanced with appropriate data structures, which is called the enhanced visibility graph. The final one is the fast traversal of the enhanced visibility graph to locate visible segments in P . Plane-Sweep Triangulation Let us present the procedure for plane-sweep triangulation of P . This triangulation procedure can be viewed as the generalization of the algorithm described by Mehlhorn [257] for triangulating a simple polygon. We assume that the interior of P lies to the left of every edge of P . This means that the outer boundary of P has counterclockwise orientation and the boundaries of holes have clockwise orientation. Like any plane-sweep algorithm, the vertices of P are sorted by increasing order of their x-coordinates. Let v1 , v2 , . . . , vn be the sorted list of the vertices of P . For every vertex vi , draw the vertical line li through vi . It can be seen that l1 and ln do not intersect any polygonal edge except at v1 and vn , respectively (see Figure 5.8(a)). Remaining vertical lines l2 , l3 , . . . , ln−1 intersects some polygonal edges and the intersection points on each line li can be ordered along li . The order of polygonal edges corresponding to their intersection points on li is called the vertical ordering of li . The vertical ordering on each line li can be computed (or updated) by sweeping a vertical line over P from left to right by stopping at each vertex vi . It starts by constructing the vertical ordering of l1 by inserting both polygonal edges incident at v1 . The clockwise edge of v1 is inserted above the counterclockwise edge of v1 in the vertical ordering of l1 . Assume that vertical ordering of l1 , l2 , . . . , li−1 have been
148
Visibility Graphs
computed and the sweep-line has currently stopped at vi . If two edges incident at vi are on the opposite side of li (see Figure 5.8(a)), the vertical ordering of li is the same as li−1 , except that the edge incident on vi in the vertical ordering of li−1 is replaced by the other edge of vi in the vertical ordering of li . If both edges incident on vi are on the left of li (see Figure 5.8(b)), then remove both edges of vi from the vertical ordering of li−1 to obtain the vertical ordering of li . If both edges incident on vi are on the right of li (see Figure 5.8(c)), then locate two edges e and e0 by binary search in the vertical ordering of li−1 such that e is the nearest edge above vi and e0 is the nearest edge below vi . Insert two edges incident on vi between e and e0 in the vertical ordering of li−1 to obtain the vertical ordering of li . Note that if no such edge e (or e0 ) exists, it means that two edges of vi are inserted at the top (respectively, bottom) of the vertical ordering of li−1 . For more details on plane-sweep techniques, see Preparata and Shamos [291]. While updating the vertical ordering of li from li−1 , the triangles can be added to the existing triangulation Ti−1 (of the polygonal region Pi−1 ) to form the triangulation Ti , by adding diagonals between vi and the vertices on the outer boundary of Ti−1 that are visible from vi . As before, we have three situations. Consider the first situation when two edges of vi are on opposite sides of li (see Figure 5.9(a)). Let vj be the vertex such that the edge vj vi is in the vertical ordering of li−1 . Let vp vq be the nearest edge below (or above) vj vi such that there are an odd (respectively, even) number of edges below (respectively, above) vj vi in the vertical ordering of li−1 , where vp is to the left of li . To construct Ti , add diagonals between vi and the vertices on the boundary of Ti−1 (facing vi ) between vj and vp , that are visible from vi . Observe that the boundary of Ti−1 between vj and vp (say, chain(vj , vp )) is convex. Starting from vj , traverse chain(vj , vp ) until a vertex vt is reached such that vt vi is a tangent to chain(vj , vp ). Diagonals are added from vi to all vertices of chain(vj , vt ). Note that the new triangles form one connected sequence about vi and they are called the interior triangles of vi . The edges of chain(vj , vt ) are called windows of vi as vi can see vertices of Pi−1 only through these windows. Note that some of these windows may be polygonal edges. Consider the second situation when both edges of vi are on the left of li (see Figure 5.9(b)). Let vm vi and vk vi be two edges of vi , where vm vi is above vk vi in the vertical ordering of li−1 . Treating vm vi and vk vi separately as vj vi , add diagonals to construct Ti from Ti−1 as stated above. Observe that the new triangles form two connected sequences about vi , one is above vm vi and the other is below vk vi . Note that if vi is same as vn , then Ti is same as Ti−1 and Ti is the triangulation of the entire polygon P . Consider the third situation when both edges of vi are on the right of li (see Figure 5.9(c)). Let vp vq and vj vk be the nearest edge below and above vi in the vertical ordering of li , where vp and vj lie on the left of li . If there are an odd number of edges below vi in the vertical ordering of li , then construct Ti from Ti−1 by adding
5.3 Computing Visibility Graphs of Polygons with Holes
149
Figure 5.9 Diagonals are added between vi and the visible vertices on the boundary of Ti−1 .
diagonals between vi and the visible vertices of chain(vj , vp ) on the boundary of Ti−1 as stated earlier. Observe that the new triangles form one connected sequence about vi . It can be seen that diagonals can be added in time proportional to the number of diagonals in Tn , which is O(n). The vertical ordering can be maintained in a height-balanced tree. Therefore, searching in the vertical ordering for nearest edges on both sides of the current vertex vi takes O(log n) time. Since there are n vertical orderings, the time taken to update vertical orderings is O(n log n). Sorting of n vertices takes O(n log n) time. We have the following theorem. Theorem 5.3.4 Using plane-sweep techniques, a polygon P with holes with a total of n vertices can be triangulated in O(n log n) time. Exercise 5.3.2 Given n line segments in the plane, design an O(n log n) time algorithm for detecting whether there is an intersection between any two segments using vertical orderings [291]. The Funnel Sequence Before we define the structure and properties of a funnel sequence, we explain the need for a funnel structure. As defined in earlier sections, a segment vi vj is called a visible segment if it lies inside P . We start with the following observations. Lemma 5.3.5 Let vi and vj be two vertices of P such that j < i. If vj vi is a visible segment, then vj is weakly visible from a window of vi . Proof. It can be seen that the segment joining vj and vi intersects one of the windows of vi and therefore, vj is weakly visible from a window of vi .
150
Visibility Graphs
Figure 5.10 (a) The unique funnel (with vq as the apex and vs vt as the base) contains the segment zvq . (b) Two funnels sharing a single apex vq with common base vs vt .
Lemma 5.3.6 Let vi and vj be two vertices of P such that j < i. If vj is not weakly visible from a window of vi , then the segment vj vi does not lie inside P . The above lemmas suggest that in order to locate all such visible segments v j vi in P , it is enough to consider those vertices of Pi−1 that are weakly visible from windows of vi . Once weakly visible vertices of Pi−1 are known, they can be tested for visibility from vi . After this process of testing for visibility has been carried out for all vertices of P in sorted order, all visible segments between the vertices in P are located. Let us explain the structure of the funnel sequence. Let vs vt be a window of vi . Let vq be a vertex of Pi−1 that is weakly visible from some point z on vs vt . So, the segment zvp lies inside P . The lower chain of vq with respect to vs vt is defined as the unique convex chain from vq to vs inside P (see Figure 5.10(a)) such that the region enclosed by this chain and by the segments zvq and zus does not contain any hole. The upper chain of vq with respect to vs vt is defined analogously. The region of P bounded by these two chains and vs vt is called a funnel. The vertex vq is called the apex of the funnel and vs vt is called the base of the funnel. The upper and lower chains are also referred to as upper and lower sides of the funnel. Unlike funnels that arise in polygons without holes (see Section 3.6), there may be several funnels sharing a single apex with common base in a polygon with holes. In Figure 5.10(b), one funnel goes below the hole in the middle and the other funnel goes above it. These apexes may be viewed as being distinct vertices occupying the same physical location in the polygon. Consider all vertices of P that are visible from a vertex vq . Let u0 , u1 , ..., um be the clockwise sequence of vertices around vp that are visible from vq , where vq u0
5.3 Computing Visibility Graphs of Polygons with Holes
151
and vq um are edges of P . For every pair of adjacent vertices uj−1 and uj (see Figure 5.10(b)), there is a unique edge e of P that can be seen from vq looking between these vertices. Thus there is a unique funnel with apex vq such that its base is e, its upper chain starts with vq uj−1 and its lower chain starts with vq uj . Hence, a funnel is uniquely determined by the first (directed) segment vq uj of its lower chain. As a consequence of this, we have the following lemma. Lemma 5.3.7 The total number of funnels in the visibility graph of P with E undirected edges is at most 2E. For a given window vs vt of vi , let F N L(vs vt ) denote the set of all funnels with vs vt as their common base. Since the apexes of these funnels are assumed to be on the left of vs vt , these funnels are also on the left of vs vt . We have the following observation. Lemma 5.3.8 If vq is the apex of a funnel F in F N L(vs vt ) and vq vp is the first segment on the lower chain of F , then the region of F contains another funnel with vp as the apex. Proof. The proof follows from the convexity of funnels. The above observation suggests that if we consider the apex vp as the parent of the apex vq , then the lower chains of all funnels in F N L(vs vt ) form a tree rooted at vs and each path from the root to a leaf in this tree is a convex chain that makes only counterclockwise turns (see Figure 5.11(a)). We call this tree the lower tree for vs vt . Analogously, the upper tree rooted at vt consists of the upper chains of all funnels in F N L(vs vt ) (see Figure 5.11(b)). Note that each path from the root to a leaf in the upper tree makes only clockwise turns. We differentiate vertices from apexes because a vertex can appear many times as an apex in F N L(vs vt ) but each apex appears only once. Consider the clockwise preorder traversal of the lower tree rooted at v s . It can be seen that the sequence of this traversal gives a natural linear ordering on the funnels of F N L(vs vt ), whose first element is the degenerate funnel with apex at vs , and whose last element is the degenerate funnel with apex at vt . We call this clockwise ordering of funnels as the funnel sequence for vs vt . Similarly, a natural linear ordering on the funnels of F N L(vs vt ) can be obtained by considering the clockwise postorder traversal of the upper tree rooted at vt . We have the following observation. Lemma 5.3.9 The linear orders on F N L(vs vt ) arising from a clockwise preorder traversal of the lower tree and a clockwise postorder traversal of the upper tree are the same.
152
Visibility Graphs
Figure 5.11 (a) The lower tree rooted at vs . (b) The upper tree rooted at vt .
Exercise 5.3.3 Prove Lemma 5.3.9. The Enhanced Visibility Graph Once F N L(vs vt ) is computed for the window vs vt of vi , for every vertex vj of F N L(vs vt ), it can be tested to determine whether vj vi is a visible segment. It can be seen that if vj vi is a visible segment, then the segment vj vi lies inside the region bounded by the triangle 4vs vt vi and the funnel F in F N L(vs vt ) with the apex vj and the base vs vt . This means that the segment vj vi lies between two first segments of F and this criteria can be used for testing whether vj vi is a visible segment. Observe that there may be vertices in F N L(vs vt ) that are not visible from vi . If such vertices are also traversed, then the running time of the algorithm cannot be output sensitive. In order to keep the running time of the algorithm proportional to the number of visible segments, all vertices of F N L(vs vt ) cannot be traversed during the process of locating such visible segments vj vi . This difficulty can be overcome using the enhanced visibility graph for vi−1 , which is the union of the enhanced visibility graph for vi−2 and all visible segments vk vi−1 where vk ∈ Pi−2 , with a few pointers at vk and vi . These pointers are used in traversing only those vertices of F N L(vs vt ) that form visible segments with vi . Note that these visible vertices of vi form sequences of consecutive vertices on the sides of the funnels in F N L(vs vt ) due to the convexity of the funnels. Let us define these pointers for visible segments incident on a vertex vq in the entire visibility graph of P . Let u0 , u2 , ..., um be the clockwise sequence of vertices around vq that are visible from vq in P , where vq u0 and vq um are edges of P (see Figure 5.12). For any uj , let CCW (vq uj ) denote the counterclockwise successor of vq uj . This means that CCW (vq uj ) is the next counterclockwise visible segment of vq uj around vq , which is vq uj−1 . Analogously, the clockwise successor CW (vq uj ) of
5.3 Computing Visibility Graphs of Polygons with Holes
153
Figure 5.12 The pointers CCW (vq uj ), CW (vq uj ), CCX(uj vq ), CX(uj vq ) and REV (uj vq ) are shown in the figures.
vq uj is vq uj+1 . The counterclockwise extension of vq uj , denoted as CCX(uj vq ), is ◦ → defined as follows (see Figure 5.12(a)). Rotate − v− q uj counterclockwise by 180 about − − → vq . During the rotation, if vq uj remains entirely inside the interior of P locally about vq , then the extension is the very next visible segment incident on vq after the 180◦ rotation. Otherwise, there is no counterclockwise extension of vq uj (see Figure 5.12(b)). The clockwise extension CX(uj vq ) of vq uj is defined analogously → by rotating − v− q uj clockwise around vq (see Figure 5.12(c)). Finally, the reversal REV (uj vq ) of (directed) segment vq uj is the (directed) segment uj vq . We observe that the enhanced visibility of P , consisting of funnel structures for every edge of the triangulation of P equipped with the pointers mentioned above for each visible segment of P , permits traversal of the lower and upper trees, which is proved in the following lemma. Lemma 5.3.10 Let vp vq be a directed segment in the lower tree (or upper tree) for a window vs vt of vi in the enhanced visibility graph of Pi−1 such that vp is the parent of vq . The following relatives of vp and vq in the lower tree (respectively, upper tree) can be computed in constant time: (i) the parent of vp , (ii) the extreme clockwise and counterclockwise children of vq , and (iii) the clockwise and counterclockwise siblings of vq . Proof. We prove the lemma only for the lower tree as the proof for the upper tree is analogous. We know that vp vq is the first segment of a funnel F with apex vq and vs vt as the base (see Figure 5.13(a)). Let vl vp be the next segment of vp vq on the same side of F . So, vl is a parent of vp in the lower tree. To prove (i), it is enough to show that vp vl is the same as CX(vq vp ) (i.e., CW (REV (vq vp )). If CX(vq vp ) is not vp vl , it means that vp vq belongs to both sides of F and therefore, the line
154
Visibility Graphs
Figure 5.13 (a) Locating the next edge on the same side of a funnel F . (b) Locating the children of vq in the lower tree.
segment joining vq with any point of the base of F does not lie inside F , which is a contradiction. Hence, vp vl is same as CX(vq vp ). To prove (ii), let CCW (vq vp ) be vq vk (see Figure 5.13(b)). So, vq vk is the first segment on the other side of F , and vk is a parent of vq in the upper tree. It can be → −−→ seen that all children of vq in the lower tree lie between − v− p vq and vk vq because for 0 any child vj , the funnel F with vj as the apex must contain F by Lemma 5.3.8. So, CCX(vp vq ) is the edge connecting vq with one of its extreme children. The edge connecting vq with its other extreme child is CW (CCX(vk vq )). To prove (iii), observe that CW (vp vq ) is the edge connecting vp with the clockwise sibling of vq . A symmetric statement holds for the counterclockwise sibling of vq .
Corollary 5.3.11 Clockwise and counterclockwise traversals of the lower and upper trees in the enhanced visibility graph of Pi−1 can be executed in time proportional to the number of vertices in the trees. Corollary 5.3.12 A funnel in the enhanced visibility graph of Pi−1 can be traversed in time proportional to the number of vertices in the funnel. Traversal of Enhanced Visibility Graph The enhanced visibility graph of P can be build up by successively incorporating visible segments of each vertex vi with the enhanced visibility graph of Pi−1 . Assume that the enhanced visibility graph of Pi−1 has been computed and the algorithm wants to locate all visible segments vj vi , where j < i. For every window vs vt of vi , the algorithm traverses F N L(vs vt ) in the enhanced visibility graph of Pi−1 to
5.3 Computing Visibility Graphs of Polygons with Holes
155
Figure 5.14 (a) The apex vj is weakly visible from both vs vi and vt vi . (b) The apex vj is weakly visible only from vs vi . (c) The apex vj is weakly visible only from vt vi .
locate such vertices vj that can be seen from vi through window vs vt . We have the following observation. Lemma 5.3.13 Let vj be the apex of a funnel in F N L(vs vt ), where vs vt is a window of vi . The apex vj is visible from both edges vs vi and vt vi if and only if vj is visible from vi . Corollary 5.3.14 If vj is visible from vi , then all vertices in the lower and upper chains of the funnel with apex vj are also visible from vi . The above lemma suggests that the visible segments from vi can be added to only those apexes in F N L(vs vt ) that are weakly visible from both vs vi and vt vi ; they are referred to as visible apexes. Adding a visible segment from vi to a visible apex vj amounts to splitting this funnel F into two funnels Fs and Ft (see Figure 5.14(a)), where Fs is for F N L(vs vi ) and Ft is for F N L(vi vt ). The lower chain of Fs is the lower chain of F , and the upper chain of Fs is only the visible segment vj vi . On the other hand, the lower chain of Ft is the visible segment vj vi , and the upper chain of Ft is the upper chain of F . Consider the situation when the apex vj is weakly visible only from vs vi (see Figure 5.14(b)). Let vi vk be the tangent from vi to the upper chain of F . So, vk vi splits F into two funnels Fs and Ft . The lower chain of Fs is the lower chain of F and the upper chain of Fs is the upper chain of F between the apex vj and vk and the visible segment vk vi . On the other hand, the lower chain of Ft is the visible segment vj vi , and the upper chain of Ft is the upper chain of F between vk and vt . If the apex vj is weakly visible only from vt vi , the new funnels Fs and Ft can be defined analogously (see Figure 5.14(c)). This procedure of splitting a funnel is referred as S P LIT .
156
Visibility Graphs
Figure 5.15 (a) SPLIT is called for the window vs vt of vi . (b) SPLIT is called for the window vk vp of vi .
The recursive procedure S P LIT traverses the lower tree rooted at v s in the linear order (see Lemma 5.3.9 for this order) from vs to vt in F N L(vs vt ), and it locates the next visible apex in F N L(vs vt ) from the current visible apex. Initially, vs is the current visible apex as S P LIT (vs vt vi ) is called for 4vs vt vi . Let vj be the next vertex of vs in the linear order (see Figure 5.15(a)). Assume that vj is a visible apex. So, the segments from vi to all vertices of the upper chain between vj and vt are visible segments by Corollary 5.3.14 and therefore, they can be added to the enhanced visibility graph of Pi−1 . For every such visible segment vk vi , S P LIT (vs vt vi ) adds the pointers CW (vk vi ), CCW (vk vi ), CX(vi vk ), CCX(vi vk ). It is shown later that the cost of adding these pointers for every visible segment can be amortized to O(1) time. Each edge vk vp in the upper chain between vj and vt can be viewed as a window of vi (see Figure 5.15(a)) and therefore, S P LIT (vs vt vi ) calls S P LIT (vk vp vi ) for each vk vp . Note that if any vk vp happens to be a polygonal edge, S P LIT is not called for this edge as it does not serve as a window of vi . Consider any recursive call S P LIT (vk vp vi ) (see Figure 5.15(b)). We know that vk vp is a window of vi , vp is the parent of vk in the upper tree rooted at vt and vk vp is not a polygonal edge. We also know the pointers of vk vp and vk vi . The task is to locate the next visible apex of vk in the linear order. Let vj be the next vertex of vk in the linear order. We have the following cases. Case 1. The vertex vj is a visible apex (Figure 5.15(b)). Case 2. The vertex vj is not a visible apex and it lies to the right of 5.16(a)). Case 3. The vertex vj is not a visible apex and it lies to the left of 5.16(b)).
→ v−− i vk (Figure → v−− i vk (Figure
5.3 Computing Visibility Graphs of Polygons with Holes
157
Figure 5.16 The next vertex vj of vk in the linear order is not a visible apex.
In Case 1, S P LIT (vk vp vi ) carries out its task for this funnel with visible apex vj as stated above for S P LIT (vs vt vi ). Consider Case 2. Let vm be the next visible apex of vk in the linear order (see Figure 5.16(a)). Note that there may be several vertices between vk and vm in linear order and they are not visible from vi . This means that once vj is found not to be visible from vi , S P LIT (vk vp vi ) has to “jump” from vj to vm in O(1) amortized time. It can be seen that the vertex vm lies in upper chain between vj and vp as vi vm is the tangent from vi to the upper chain of the funnel with apex vj . So, S P LIT (vk vp vi ) traverses the upper chain from vp toward vj till it locates vm . Note that all vertices from vp to vm in the path are visible from vi . Observe that this traversal from vp toward vj in the upper chain can be done by using the pointer CX successively as vk and vj are two consecutive vertices in the linear order. Note that the vertices from vj to the previous vertex of vm in linear order, which form the sub-tree of upper tree rooted at vm , are visible only from vs vi and therefore, they are incorporated in F N L(vs vi ). In case vp and vm are same, then no vertex of Pi−1 is visible from vi through window vk vp . Exercise 5.3.4 Let Fk and Fj be two funnels of F N L(vs vt ) with apexes vk and vj , respectively, such that vj is the next apex of vk in the linear order of F N L(vs vt ). Prove that the region (which is called a hourglass) bounded by (i) the lower chain of Fk , (ii) the visible segment vk vj , (iii) the upper chain of Fj , and (iv) the window vt vs , does not contain any hole. Consider Case 3. Locate the first sibling (say, vq ) of vj in the clockwise order in → the lower tree such that vq lies to the right of − v− i vk (see Figure 5.16(b)). If no such → vertex vq exists, i.e., all siblings of vj lie to the left of − v− i vk , then the next clockwise sibling of vk in the lower tree is the vertex vq . If vk does not have a clockwise sibling, then take the parent of vk in the lower tree and check its next clockwise sibling. By
158
Visibility Graphs
repeating this process, vq can be located. If vq is same as vp , then no vertex of Pi−1 is visible from vi through window vk vp . So, we assume that vp is not same as vq . This implies that the visible segment connecting vq and its parent in the lower tree has intersected vk vp . We have the following two sub-cases. Case 3a. The vertex vq is a visible apex. Case 3b. The vertex vq is not a visible apex (see Figure 5.16(b)). Consider Case 3a. The vertex vq is the next visible apex vm of vk and S P LIT (vk vp vi ) has located vm . Then, S P LIT (vk vp vi ) carries out its task for this funnel with visible apex vq as stated earlier. It can be seen that the vertices between vk and vq in the linear order are vertices that are visible only from vi vt and therefore, they are incorporated in F N L(vi vt ). Consider Case 3b. The next visible apex vm lies in the upper chain between vq and vp as vm vi is the tangent from vi to the upper chain. Observe that vk and vq are not adjacent vertices in the linear order and therefore, the upper chain from v p toward vq cannot be traversed to locate vm using the pointer CX successively as in Case 2. Let vh be the previous vertex of vq in the linear order. Let vl be the parent of vh in the upper tree. Observe that vl is visible from vi and it lies in the upper chain between vm and vp . So, all vertices in the upper chain between vl and vp are visible from vi and all vertices from vl to vm in the upper chain are also visible from vi . The upper chain from vl to vp can be traversed using the parent pointer in the upper tree successively. The upper chain from vl to vq can now be traversed using the pointer CX successively as vh and vq are adjacent vertices in the linear order. This traversal toward vq stops once vm is found and hence, S P LIT (vk vp vi ) has located vm . It can be seen that the vertices between vk and vq in the linear order, which form the sub-tree of the lower tree rooted at vk , are visible only from vi vt and therefore, they are incorporated in F N L(vi vt ). Similarly, the vertices between vh and vm in the linear order, which form the sub-tree of the upper tree rooted at vm , are visible only from vi vs and therefore, they are incorporated in F N L(vs vi ). We have the following lemma. Lemma 5.3.15 The recursive procedure S P LIT (vs vt vi ) correctly locates all vertices of Pi−1 that are visible from vi through window vs vt . Exercise 5.3.5 Prove Lemma 5.3.15. Once S P LIT (vs vt vi ) is executed, F N L(vs vt ) splits into the lower funnel sequence F N L(vs vi ) and the upper funnel sequence F N L(vi vt ). It can be seen that SPLIT produces two such funnel sequences for each window of vi . All lower funnel sequences are concatenated to form one lower funnel sequence for vi and this can be done easily as a funnel sequence is maintained in a doubly linked list which permits
5.3 Computing Visibility Graphs of Polygons with Holes
159
Figure 5.17 (a) The vertices u0 , u2 , . . . , um are visible from vi . (b) Figure shows the visible segments and their extensions in the sorted angular order around vk .
concatenation in O(1) time. Similarly, all upper funnel sequences are concatenated to form one upper funnel sequence for vi . The Overall Algorithm We present the overall algorithm for computing the enhanced visibility graph of Pn . We assume that the vertices of P are numbered v1 , v2 , . . . , vn from left to right in the sorted order. Compute the enhanced visibility graph of P1 and initialize the index i by 2. We have the following steps for computing the enhanced visibility graph of Pn . Step 1. Add vi to Pi−1 . Step 2. For each convex chain u0 , u1 , . . . , um of vertices of Pi−1 visible to vi (Figure 5.17(a)), add diagonals u0 vi , u1 vi , . . . , um vi to form the triangulation of Pi . Step 3. For each window uj−1 uj of vi , call S P LIT (uj−1 uj vi ). Step 4. Concatenate the lower funnel sequences F N L(u0 vi ), F N L(u1 vi ), . . ., F N L(um−1 vi ) to form F N L(u0 vi ). Step 5. Concatenate the upper funnel sequences F N L(vi u1 ), F N L(vi u2 ), . . ., F N L(vi um ) to form F N L(vi um ). Step 6. If i 6= n then i := i + 1 and goto Step 1.
Step 7. Output the enhanced visibility graph of Pn and Stop.
The correctness of the algorithm essentially follows from Theorem 5.3.4 and Lemma 5.3.15. Let us analyze the time complexity of the algorithm. We know from Theorem 5.3.4 that P can be triangulated in O(n log n) time. In the following, we show that all visible segments in P can be computed in O(E) time.
160
Visibility Graphs
Consider the cost of adding visible segments to the enhanced visibility graph of Pi−1 by the recursive procedure S P LIT (uj−1 uj vi ). The cost consists of two parts. The first part is the time taken to locate the visible segments and the second part is the time taken to add pointers to these visible segments. Since S P LIT (uj−1 uj vi ) moves from one visible apex to the next visible apex in F N L(uj−1 uj ), the time taken in the first part is proportional to the number of visible segments located by S P LIT (uj−1 uj vi ). For estimating the time taken in the second part, we need a particular data structure at each vertex of P . The algorithm maintains a doubly linked adjacency list for each vertex vk of P such that the visible segments incident on vk and their extensions are stored in the sorted angular order around vk (see Figure 5.17(b)). Consider any visible segment vk vi added by S P LIT (uj−1 uj vi ), where k < i. Since vk is a visible apex of some funnel F with base uj−1 uj , the first segment in the lower (or upper) chain of F is CW (vk vi ) (respectively CCW (vk vi )). So, the pointers CW (vk vi ) and CCW (vk vi ) can be added in O(1) time. It can be seen that the extensions of CX(vi vk ) and CCX(vi vk ) are two neighbors of vk vi at vk . So, the position of vk vi in the angular order at vk has to be located among the extensions of the visible segments incident on vk that are lying between CW (vk vi ) and CCW (vk vi ) (see Figure 5.17(b)). We show later that the cost of searching for locating the position of vk vi at vk can be amortized to O(1) time. Let us now look at the cost of adding all such visible segments vk vi at vi . It can be seen that the procedure S P LIT inserts visible segments at vi according to their position in the sorted angular order at vi . Therefore, their extensions are also in sorted angular order around vi . Hence every visible segment vk vi and its extension can be inserted in the linked list at vi in amortized O(1) time. So, we can conclude that the cost of the second part for adding all pointers to a visible segment is O(1) time. Let us now calculate how two neighbors of a visible segment vk vi among the extension of visible segments incident at vk can be located in amortized O(1) time. Let m and d be the numbers of extensions of visible segments incident on vk that are lying between CW (vk vi ) and CCW (vk vi ), and between vk vi and CCW (vk vi ) respectively. So, the position of vk vi can be located in min(log d, log(m − d)) using binary search from both directions. It has been shown in Section 3.6.1 how to carry out this search using finger search trees. However, the same binary search can also be carried out using SPLIT-FIND operation developed by Gabow and Tarjan [146] once integers (i.e. the slopes of visible segments incident on vk ) are stored in the data structure at vk . If this cost is added over all visible segments in P , we get the following recurrence, T (m) = max1≤d≤m−1 [T (d) + T (m − d) + O(min(log d, log(m − d)))].
It has been shown in Section 3.6.1 by induction on m that T (m) is O(m). Therefore, the time required to locate the position of vk vi among the extensions is amortized O(1). Hence, the total time taken by the algorithm to locate all visible seg-
5.4 Computing Tangent Visibility Graphs
161
Figure 5.18 (a) SP (s, t)=(s, u1 , u2 , u3 , u4 , t) consists of tangents and polygonal edges. (b) Four tangents can be constructed between two convex holes Hi and Hj .
ments in P and add pointers to these visible segments is O(E). We summarize the result in the following theorem. Theorem 5.3.16 The visibility graph of a polygon P with holes with a total of n vertices can be computed in O(n log n + E) time and O(E + n) space, where E is the number of edges in the visibility graph of P .
5.4 Computing Tangent Visibility Graphs 5.4.1 Convex Holes: O(n + h2 log h) Algorithm In this section, we present an O(n + h2 log h) time algorithm given by Rohnert [298] for computing the tangent visibility graph inside a convex polygon P with h convex holes with a total of n vertices. This graph contains all those edges of the visibility graph of P that are relevant in computing the Euclidean shortest path SP (s, t) between two given points s and t inside P . A line segment vi vj is called a tangent between two convex holes, where vertices vi and vj belong to different holes, if the line passing through vi and vj meets the holes only at vi and vj . Let SP (s, t)=(s, u1 , ..., uk , t). Observe that (i) su1 is a tangent from s to some vertex u1 of a convex hole, (ii) uk t is a tangent from t to some vertex uk of a convex hole, and (iii) for any edge ui ui+1 , ui ui+1 is either an edge of a convex hole or a tangent between two convex holes (Figure 5.18(a)). This observation helps in defining the tangent visibility graph of P . Let G be the partial visibility graph of P such that s, t and every vertex of holes in P are represented as nodes in G and two nodes wi and wj are connected by an edge in G if and only if (i) the corresponding vertices of wi and wj are mutually
162
Visibility Graphs
visible in P , and (ii) the segment corresponding wi wj in P is an edge of P or a tangent between two convex holes or a tangent from s or t to some convex hole. The graph G is called the tangent visibility graph of P . Then the length of these edges and tangents in P are assigned as weights to their corresponding edges in G. Since there can be at most four tangents between two convex holes (Figure 5.18(b)) and there are h holes, the total number of tangents between convex holes can be at most O(h2 ). So, the number of edges in G is O(n + h2 ). Running the algorithm of Fredman and Tarjan [143] on G, SP (s, t) can be computed in O(n log n + h 2 ) time. Assuming h2 greater than n, the running time for computing SP (s, t) can also be written as O(n + h2 log n). Observe that the tangents from s (or t) to convex holes can be computed from the visibility polygon of P from s (respectively, t) in O(n) time. The visibility polygons of P from s and t can be computed by the algorithm of Asano [27] in O(n + h log h) time (see Section 2.3). Let us explain how to construct tangents between convex holes H1 , H2 , . . . , Hh . The algorithm of Rohnert first constructs four tangents between each pair of convex holes and then checks whether or not these tangents are lying inside P . Let Hi and Hj be two convex holes of P (Figure 5.18(b)). Let pi ∈ Hi and pj ∈ Hj denote the closest pair of points between Hi and Hj . Draw the line L perpendicular to the segment pi pj . Let qi ∈ Hi be the furthest point of Hi from L. The clockwise and counterclockwise boundaries of Hi from qi to ui are referred to as the upper and lower chains of Hi , respectively. Analogously, let qj ∈ Hj be the furthest point of Hj from L. The clockwise and counterclockwise boundaries of Hj from qj to uj are referred to as the lower and upper chains of Hj , respectively. Tangents are drawn between the lower chain of Hi and the upper chain of Hj , between the lower chains of Hi and Hj , between the upper chains of Hi and Hj , and between the upper chain of Hi and the lower chain of Hj . It has been shown by Edelsbrunner [116] that these four tangents between Hi and Hj can be drawn in O(log ni + log nj ) time, where ni and nj are the number of vertices of Hi and Hj , respectively. So, the total time required to compute four tangents between O(h2 ) pairs of convex holes is bounded by O(h2 log(n/h)). Exercise 5.4.1 Prove that the sum of (log ni + log nj ) for 1 ≤ i, j ≤ h and i 6= j is O(h2 log(n/h)), where n = n1 + n2 + . . . + nh . After constructing four tangents between every pair of holes in P , it is tested whether these tangents lie inside P . If we test for intersection of each tangent with every polygonal edge, the naive method takes O(nh2 ) time. We show that this can be improved to O(h2 log h) time as follows. Observe that the lower chain of Hi for Hj is different from the lower chain of Hi for another hole Hk as the closest points between Hi and Hj are different from that of Hi and Hk . Two tangents between Hi and Hj touching the lower chain of Hi are called lower tangents of Hi for Hj . In Figure 5.18(b), va vb and vc vd are two lower tangents of Hi for Hj . The other
5.4 Computing Tangent Visibility Graphs
163
Figure 5.19 (a) Tangent tk between holes Hi and Hm has intersected hole Hj . (b) Lower diagonals of holes for Hi are drawn as segments (d1 , d2 , . . . , d6 ) along with the ray drawn from vl−1 through vl . Lower tangents of Hi are (t1 , t2 , . . . , t12 ) in counterclockwise order.
two tangents touching the upper chain of Hi are called upper tangents of Hi for Hj . So there are 2(h − 1) lower tangents (or upper tangents) of H i in P . The segment connecting two vertices of Hj touched by the lower tangents of Hi is called the lower diagonal of Hj for Hi . The segment vb vd in Figure 5.18(b) is the lower diagonal of Hj for Hi . The upper diagonal of Hj for Hi is defined analogously. In the following lemma, we state how to identify the lower tangents of Hi that are lying inside P . Lemma 5.4.1 Let va vb and vc vd be the lower tangents of Hi for Hj (Figure 5.19(a)), where (i) va and vc are vertices of Hi , (ii) vb and vd are vertices of Hj , and (iii) Hj → lies to the left of − v− a vb . Let tk be a lower tangent of Hi for a hole Hm where m 6= j. The tangent tk intersects Hj if and only if tk intersects the lower diagonal vb vd of Hj . Exercise 5.4.2 Prove Lemma 5.4.1. Corollary 5.4.2 If any lower tangent tk of Hi intersects Hj , then the vertex of tk belonging to Hi lies in the counterclockwise boundary from va to vc . The above lemma and its corollary suggest a procedure for identifying lower tangents of Hi (for all i) lying inside P . Traverse the boundary of Hi in counterclockwise order starting from any vertex vl of Hi , and at each vertex vp of Hi , add the lower tangents of Hi incident at vp to the ordered list Li according to their counterclock−−→ wise angle at vq with the clockwise edge of Hi at vp . Consider v−l−1 vl , where vl−1 is the next clockwise vertex of vl in Hi (see Figure 5.19(b)). Compute the intersection −−→ points of v−l−1 vl with the lower diagonal of every hole for Hi and sort these diagonals − − − → along vl−1 vl according to the distance of their intersection points from vl . Construct a balanced binary tree T with nodes representing these diagonals and if a diagonal
164
dj is the left child −−→ v−l−1 vl lies between closest to vl along active diagonals.
Visibility Graphs
of the diagonal dk in T , then the intersection point of dj with −−→ vl and the intersection point of dk with v−l−1 vl . So the diagonal − − − → vl−1 vl is the leftmost leaf of T . The diagonals in T are called
Let Li = (t1 , t2 , . . . , tf ). Starting from t1 , consider each tangent tk of Li . Let dm denote the lower diagonal of some hole (say, Hq ) for Hi such that tk is a lower tangent from Hi to Hq . We have the following two cases. Case 1. The diagonal dm is a node in T . Case 2. The diagonal dm is not a node in T . Consider Case 1. If dm is not the diagonal in the leftmost leaf of T , then remove tk from Li because tk has intersected the lower diagonal in the leftmost leaf of T . Remove the node of T containing dm from T as dm is no longer an active edge and balance T . Consider Case 2. Insert dm as a node in T such that tk intersects only the diagonals in the left sub-tree of dm in T . Balance T . If dm is not the leftmost leaf of T , then remove tk from Li as tk intersects the lower diagonal in the leftmost leaf of T . In the following, we state the major steps of the algorithm for computing the tangent visibility graph G of P . Step 1. Compute the visibility polygons of P from s and t by the algorithm of Asano [27] and traverse them to locate the tangents from s and t to the holes of P . Step 2. Draw the four tangents between every pair of holes in P . Step 3. For every hole Hi of P do Step 3a. Traverse the boundary of Hi in counterclockwise order and form the ordered list Li of all lower tangents of Hi in the order they are incident at Hi . Step 3b. Traverse the ordered list Li and remove the tangents in Li that are intersected by any diagonal of a hole in P . Step 3c. Traverse the boundary of Hi in clockwise order and form the ordered list Ri of all upper tangents of Hi in the order they are incident at Hi . Step 3d. Traverse the ordered list Ri and remove the tangents in Ri that are intersected by any diagonal of a hole in P . Step 3e. Output the remaining tangents in Li and Ri . Step 4. Form the tangent visibility graph G and Stop. The correctness of the algorithm follows from Lemma 5.4.1 and its corollary. Let us analyze the time complexity of the algorithm. We know that Step 1 takes O(n + h log h) time and Step 2 takes O(h2 log(n/h)). Steps 3a and 3c are problems of sorting and they can be performed in O(h log h) time. Insert or delete operations in T take O(log h) time as the size of the tree T is at most h. Since there are 4(h−1)
5.4 Computing Tangent Visibility Graphs
165
Figure 5.20 (a) The vertices of the relative convex hull of Hi are v1 , v2 , v3 , v4 , v5 , v6 and v7 . (b) SP (s, t) passes through edges of relative convex hulls of holes and tangents between holes.
such operations in T for the lower and upper tangents of Hi , Steps 3b and 3d can be performed in O(h log h). Hence the overall time complexity of the algorithm is O(n + h2 log h). We state the results in the following theorems. Theorem 5.4.3 The tangent visibility graph of a polygon P with h convex holes with a total of n vertices can be computed in O(n + h2 log h) time. Theorem 5.4.4 The Euclidean shortest path between two given points inside a polygon P with h convex holes with a total of n vertices can be computed in O(n + h2 log n) time.
5.4.2 Non-Convex Holes: O(n + h2 log h) Algorithm In this section, we present an O(n + h2 log h) time algorithm given by Kapoor et al. [210] for computing the tangent visibility graph inside a polygon P with h nonconvex holes and a total of n vertices. This graph contains a subset of edges of the visibility graph of P , relevant for computing the Euclidean shortest path SP (s, t) between two given points s and t inside P (see Section 5.4.1). We assume that holes H1 , H2 , . . . , Hh inside P are arbitrary simple polygons. Suppose the convex hull of every hole is computed and each of these convex hulls lies inside P . Then the problem of computing the tangent visibility graph in P is reduced to that of computing the tangent visibility graph in a polygon containing only convex holes. Therefore, the algorithm of Rohnert [298] stated in Section 5.4.1 can be used to solve the problem.
166
Visibility Graphs
Figure 5.21 (a) The dual graph GT of the triangulation of P after including s and t. (b) All triangles corresponding to the nodes of degree 1 in GT are removed from the triangulation of P .
In general, convex hulls of holes do not lie inside P . Suppose the relative convex hull of every hole is computed (see Figure 5.20(a)). The relative convex hull of a hole Hi is the smallest perimeter polygon containing Hi . In other words, for any convex hull vertex vj of Hi , the region enclosed by the shortest path from vj inside P that goes around Hi and terminates at vj is called the relative convex hull of Hi . Observe that SP (s, t) passes through the edges of relative convex hulls of holes and tangents between holes (see Figure 5.20(b)). So, the tangent visibility graph G can be constructed such that (i) the edges of relative convex hulls of holes, (ii) tangents from s and t to holes, and (iii) tangents between holes, are represented as edges in G. Once G is constructed, the algorithm of Fredman and Tarjan [143] can be used on G for computing SP (s, t). The algorithm of Kapoor et al. starts by triangulating P in O(n + h log 1+² h) time by the algorithm of Bar-Yehuda and Chazelle [43]. Let Ts and Tt denote the triangles containing s and t, respectively. Connect s and t to all three vertices of Ts and Tt , respectively. Let T denote the resulting triangulation and let GT denote the dual graph of T (Figure 5.21(a)). For more details on the dual graph of a triangulation, see Section 1.4. We have the following observation on G T . Lemma 5.4.5 The dual graph GT is a planar graph with O(n) nodes, O(n) edges and h + 1 faces (including the outer face), and at least one of three nodes of G T incident on each of s and t has degree 3. It can be seen that SP (s, t) does not pass through a triangle if the degree of the corresponding node of the triangle in GT is one. So, all nodes in GT corresponding to such triangles are deleted from GT . Two polygonal edges forming the sides of
5.4 Computing Tangent Visibility Graphs
167
Figure 5.22 (a) The corridor is a hourglass bound by va vb , SP (va , vc ), vc vd and SP (vb , vd ). (b) The corridor consists of two funnels with bases va vb and vc vd , and the shortest path between the apexes of these two funnels.
each of these triangles are replaced by the third edge of the triangle, which is treated as a polygonal edge for the subsequent computation. This process is repeated until all remaining nodes in GT have degree 2 or 3 (see Figure 5.21(b)). The triangles corresponding to the nodes of degree 3 in GT are called junction triangles. If all junction triangles are removed from P , P is divided into simple polygons which are called corridors. Corridors are sleeves in P because the nodes in GT corresponding to the triangles in a corridor have degree 2. Let C be a corridor bounded by the triangulating edges va vb and vc vd of two different junction triangles (see Figure 5.22). Since no triangle inside C is a junction triangle, two vertices of va , vb , vc and vd belong to one hole and other two vertices belong to another hole. Without loss of generality, we assume that va and vc belong to one hole and vb and vd belong to another hole. Since C is a sleeve, the algorithm of Lee and Preparata [235] (see Section 3.6.1) can be used to compute SP (v a , vc ) and SP (vb , vd ). We have the following two cases. Case 1. SP (va , vc ) and SP (vb , vd ) are disjoint (Figure 5.22(a)). Case 2. SP (va , vc ) and SP (vb , vd ) are not disjoint (Figure 5.22(b)). Consider Case 1. Since SP (va , vc ) and SP (vb , vd ) are disjoint, the segment va vb , SP (va , vc ), the segment vc vd and SP (vb , vd ) form a hourglass (see Figure 5.22(a)). Replace the polygonal boundary of C between va and vc by SP (va , vc ) in P . Analogously, replace the polygonal boundary of C between vb and vd by SP (vb , vd ) in P . Consider Case 2. Since SP (va , vc ) and SP (vb , vd ) are not disjoint, the union of SP (va , vc ) and SP (vb , vd ) forms two funnels with bases va vb and vc vd , and a path
168
Visibility Graphs
connecting the apexes of the funnels (see Figure 5.22(b)). Add these two funnels in P and remove the polygonal boundaries of C from P between va and vc and between vb and vd . Observe that the edges in the path between the two apexes of the funnels in a corridor are represented as edges in G as SP (s, t) can use these edges. This process is carried out for all corridors in P . Let P 0 be the polygon obtained from P after the above-mentioned modifications. Let Hi be any hole in P . In P 0 , Hi is a convex polygon or the boundary of Hi is a convex chain. So, the algorithm of Rohnert [298] stated in Section 5.4.1 can be used to compute tangents in P 0 between convex boundaries of holes. In the following, we state the major steps of the algorithm for computing the tangent visibility graph G of P . Step 1. Triangulate P by the algorithm of Bar-Yehuda and Chazelle [43]. Connect s and t to all three vertices of the triangles containing them. Form the dual graph GT . Step 2. While GT has a node of degree 1 do remove the triangle corresponding to the node from the triangulation of P . Step 3. Generate corridors by removing junction triangles from P . Step 4. Construct two funnels or a hourglass for each corridor in P and use them to replace the corridor. Step 5. Compute the tangents between the convex chains of every pair of holes by the algorithm of Rohnert [298]. Step 6. Form the tangent visibility graph G and Stop. The correctness of the algorithm directly follows from the properties of SP (s, t) and the dual graph of a triangulation of P . Let us analyze the time complexity of the algorithm. The algorithm of Bar-Yehuda and Chazelle [43] for triangulating P in Step 1 takes O(n + h log1+² h) time. Since GT can be constructed in O(n) time from the triangulation of P , Step 1 takes O(n + h log 1+² h) time. Steps 2 and 3 take O(n) time. Since the corridors are disjoint and the time for computing the shortest paths between two pairs of vertices in a corridor is proportional to the number of vertices in a corridor, the time required in Step 4 to replace all corridors in P by funnels and hourglasses is O(n). Since there can be at most h convex boundaries of holes in the modified polygon P 0 , the algorithm of Rohnert in Step 5 runs in O(h2 log h) time. Hence the tangent visibility graph G can be computed in O(n + h2 log h) time. We state the results in the following theorems. Theorem 5.4.6 The tangent visibility graph of a polygon P with h non-convex holes with a total of n vertices can be computed in O(n + h2 log h) time.
5.5 Notes and Comments
169
Theorem 5.4.7 The Euclidean shortest path between two given points inside a polygon P with h non-convex holes with a total of n vertices can be computed in O(n + h2 log n) time.
5.5 Notes and Comments Goodrich et al. [173, 174] have given the only parallel algorithm for computing visibility graphs of simple polygons. Their algorithm computes the visibility graph by exploiting a duality relationship between a visibility graph and intersections of segments, and runs in O(log n) time using O(n log n + E/ log n) processors in the CREW-PRAM model of computations, where E is the number of edges of the visibility graph. There is no parallel algorithm for computing visibility graphs of polygons with holes. In the beginning of this chapter, we have shown how visibility graphs help in computing the Euclidean shortest path SP (s, t) between two given points s and t inside a polygon P with holes. SP (s, t) can also be computed without computing the visibility graph of P partially or totally. Using the ‘continuous Dijkstra’ paradigm, Mitchell [259] presented an O(n1.5+² ) time algorithm for computing SP (s, t). Using the same paradigm, Hershberger and Suri [189] first presented an O(n log 2 n) time algorithm for computing SP (s, t) and then improved the time complexity of their algorithm to O(n log n) [192], which is optimal. Recently, Wein et al. [338] showed that a short and smooth path from s to t in P can be constructed by combining the visibility graph with the Voronai diagram of P . The path may not be SP (s, t) but it keeps a fixed amount of clearance with holes in P wherever possible. Euclidean shortest paths in a polygon are also called geodesic paths. The length of a geodesic path between two points is called the geodesic distance of the path. The geodesic diameter of a simple polygon P is the maximum geodesic distance among all pairs of vertices of P . The geodesic diameter can be computed in O(n) time by the algorithm of Hershberger and Suri [191]. The geodesic center of a simple polygon P is a point in P which minimizes the maximum geodesic distance to any point in P ; such a point can be located in O(n log2 n) time by the algorithm of Pollack et al. [288]. Earlier, Asano and Toussaint [31] proposed an O(n4 log n) time algorithm for this problem. It is still open whether the problem can be solved in O(n) time [260]. For related problems on geodesic paths, see the review article of Mitchell [260]. Let us mention some results on shortest paths in L1 metric. For any two points p = (xp , yp ) and q = (xq , yq ), the distance between p and q in Lm metric is defined by (|xp − xq |m + |yp − yq |m )1/m . So, the length of a polygonal path in Lm metric is the sum of the lengths in Lm metric of edges in the path. A polygonal path is called a rectilinear path if each edge of the path is parallel to a coordinate axis. Observe that the length of a rectilinear path is the same in both L1 and L2 metric.
170
Visibility Graphs
The problem of computing a shortest rectilinear path in L1 metric in polygons P has been studied by several researchers including Clarkson [92], de Rezende et al. [109], Larson and Li [225] and Mitchell [258]. Clarkson et al. [92] showed a method for constructing a sparse graph which contains a shortest rectilinear path between any two vertices of P . Then a shortest rectilinear path in P can be computed from the sparse graph treating it as the visibility graph of P . Their algorithm runs in O(n log2 n) time and O(n log n) space. Using the ‘continuous Dijkstra’ paradigm, Mitchell [258] improved the time complexity by showing that a shortest rectilinear path in P can be computed in O(n log n) time and O(n) space. Exercise 5.5.1 Let Q be a set of m points inside a simple polygon P of n vertices. Design an algorithm to identify all pairs of points of Q that are mutually visible in P in O(n + m log m log mn + k log m) time, where k is the total number of visible pairs [44]. Consider the problem of locating the closest visible pair of vertices between two disjoint simple polygons P and Q. The problem is to locate two vertices u ∈ P and v ∈ Q such that the segment uv does not intersect the interior of P or Q. Take a convex polygon C containing both P and Q and compute the visibility graph of C treating P and Q as holes in C. The problem of closest visible pair can now be solved by locating the shortest edge of the visibility graph connecting a vertex u of P with a vertex v of Q, and the entire process can be done in O(n log n + E), where n is the total number of vertices of P and Q. The problem can directly be solved without computing the visibility graph. If both P and Q are convex polygons, the problem can be solved in O(n) time by the algorithms of Chin et al. [88], McKenna and Toussaint [255] and Toussaint [329]. If either P or Q is a convex polygon, the problem can also be solved in O(n) time by the algorithm of Chin et al. [88]. If both P and Q are non-convex polygons, Wang and Chan [337] gave an O(n log n) time algorithm for this problem. Later, optimal O(n) time algorithms for this problem were given by Aggarwal et al. [13], and Hershberger and Suri [191]. Following the method of Aggarwal et al. [13], Hsu et al. [199] designed a parallel algorithm for this problem. Using a different method, Amato [19] also gave a parallel algorithm for this problem and the method of this algorithm gives another O(n) time optimal sequential algorithm for this problem. Exercise 5.5.2 Design an O(n) time algorithm for computing the closest visible pair of vertices between two disjoint convex polygons P and Q of total n vertices [88, 255]. Exercise 5.5.3 Design an O(n log n) time algorithm for computing the closest visible pair of vertices between two disjoint non-convex polygons P and Q of total n vertices [337].
6 Visibility Graph Theory
6.1 Problems and Results
In the previous chapter we discussed how to compute the visibility graph of a polygon P with or without holes. Consider the opposite problem: let G be a given graph. The problem is to determine whether there is a polygon P whose visibility graph is the given graph G. This problem is called the visibility graph recognition problem. The problem of actually drawing one such polygon P is called the visibility graph reconstruction problem. The visibility graph recognition and reconstruction problems are long-standing open problems. So far, only partial results have been achieved. It has been shown by Everett [133] that visibility graph reconstruction is in PSPACE. This is the only upper bound known on the complexity of either problem. Ghosh [154] presented three necessary conditions in 1986 for recognizing visibility graphs of simple polygons under the assumption that a Hamiltonian cycle of the given graph, which corresponds to the boundary of the simple polygon, is given as input along with the graph. It has been pointed out by Everett and Corneil [133, 135] that these conditions are not sufficient as there are graphs that satisfy the three necessary conditions but they are not visibility graphs of any simple polygon. These counter-examples can be eliminated once the third necessary condition is strengthened. It has been shown by Srinivasraghavan and Mukhopadhyay [314] that the stronger version of the third necessary condition proposed by Everett [133] is in fact necessary. On the other hand, the counter-example given by Abello et al. [4] shows that the three necessary conditions of Ghosh [154] are not sufficient even with the stronger version of the third necessary condition. In a later paper by Ghosh [157], another necessary condition is identified which circumvents the counter-example of Abello et al. [4]. These four necessary conditions are presented in Section 6.2.1. It has been shown more recently by Streinu [316, 317] that these four necessary conditions are also not sufficient. 171
172
Visibility Graph Theory
In Section 6.2.2, we present the algorithm given by Ghosh [157] for testing his first two necessary conditions which runs in O(n2 ) time. The time complexity for checking the other two necessary conditions is not known. Earlier, Everett [133] gave an O(n3 ) time algorithm for testing the first necessary condition. Let us state other results on the problems of recognizing and reconstructing visibility graphs for special classes of simple polygons. The earliest result is from ElGindy [126] who showed that every maximal outerplanar graph is a visibility graph of a simple polygon, and he suggested an O(n log n) algorithm for reconstruction. If all reflex vertices of a simple polygon occur consecutively along its boundary, the polygon is called a spiral polygon. Everett and Corneil [133, 134] characterized visibility graphs of spiral polygons by showing that these graphs are a subset of interval graphs, which leads to an O(n) time algorithm for recognition and reconstruction. We present their characterization and recognition algorithm in Section 6.4.1. Choi et al. [89] characterized funnel-shaped polygons called towers and they gave an O(n) time recognition algorithm. Visibility graphs of towers have also been characterized by Colley et al. [95] and they have shown that visibility graphs of towers are bipartite permutation graphs with an added Hamiltonian cycle. We present their characterization and their O(n) time recognition algorithm in Section 6.4.2. If the internal angle at each vertex of a simple polygon is either 90◦ or 270◦ , then the polygon is called a rectilinear polygon. If the boundary of a rectilinear polygon is formed by a staircase path with two other edges, the polygon is called a staircase polygon. Visibility graphs of staircase polygons have been characterized by Abello et al. [1]. Lin and Chen [243] have studied visibility graphs that are planar. The above-mentioned results show that there are characterizations of visibility graphs for some special classes of polygons. However, the problem of characterizing visibility graphs of arbitrary simple polygons is still an open problem. Ghosh has shown that visibility graphs do not possess the characteristics of perfect graphs, circle graphs or chordal graphs. On the other hand, Coullard and Lubiw [97] have proved that every triconnected component of a visibility graph satisfies 3-clique ordering. This property suggests that structural properties of visibility graphs may be related to well-studied graph classes, such as 3-trees and 3-connected graphs. Everett and Corneil [133, 135] have shown that there is no finite set of forbidden induced sub-graphs that characterize visibility graphs. Abello and Kumar [2, 3] have suggested a set of necessary conditions for recognizing visibility graphs. However, it has been shown in [157] that this set of conditions follow from the last two necessary conditions of Ghosh. The efforts to characterize the visibility graphs are presented in Section 6.3. Let us mention some of the later approaches on the visibility graph reconstruction problem. Abello and Kumar [3] studied the relationship between visibility graphs
6.1 Problems and Results
173
and oriented matroids, Lin and Skiena [244] studied the equivalent order types, and Streinu [316, 317] and O’Rourke and Streinu [274] studied psuedo-line arrangements. The reconstruction problem with added information has been studied by Coullard and Lubiw [97], Everett et al. [137, 138] and Jackson and Wismath [203]. There are other types of visibility graphs. Vertex-edge visibility graphs are graphs that represent the visibility relationship between the vertices and edges of a polygon. O’Rourke and Streinu [275] studied the properties of vertex-edge visibility graphs which are presented in Section 6.6. A one-directional variation of this graph was studied earlier by Fournier and Montuno [142]. E dge-edge visibility graphs are graphs indicating which edges see which edges; these have been studied by O’Rourke [271] and Srinivasaraghavan and Mukhopadhyay [315]. Point visibility graphs are infinite visibility graphs, where each point of a polygon is represented as a vertex of the graph. This graph has been studied by Bremner [64], Bremner and Shermer [65] and MacDonald and Shermer [251], The representation of visibility graphs has been studied by Agarwal et al. [7], Kant [208] and Tamassia and Tollis [325]. The segment visibility graph is a graph whose 2n vertices represent the endpoints of n disjoint segments and whose edges represent visible segments between the endpoints (see Figure 6.15(a)). Everett et al. [136] have characterized those segment visibility graphs that do not have K5 , the complete graph of 5 vertices, as a minor. This characterization leads to a polynomial time algorithm for recognizing this special class of segment visibility graphs. We present their characterization in Section 6.5. Segment visibility graphs have also been studied for different problems under various conditions by Andreae [20], Hoffmann and Toth [196, 197], Kirkpatrick and Wismath [218], O’Rourke and Rippel [273], Rappaport [292], Rappaport et al. [293], Shen and Edelsbrunner [308], and Wismath [340, 341]. Exercise 6.1.1 Draw n disjoint line segments whose segment visibility graph has 5n − 4 edges (including n given segments) [308]. Let us consider the standard graph-theoretic problems on visibility graphs. The minimum dominating set problem in visibility graphs corresponds to the art gallery problem in polygons. Lee and Lin [231] showed that the problem is NP-hard. Independent sets in visibility graphs are known as hidden vertex sets. Shermer [309] proved that the maximum hidden vertex set problem on visibility graphs is also NP-hard. If the Hamiltonian cycle corresponding to the boundary of the simple polygon is given as an input along with the visibility graph, Ghosh et al. [167] showed that it is possible to compute in O(nE) time the maximum hidden vertex set in the visibility graph of a very special class of simple polygons called convex fans,
174
Visibility Graph Theory
where n and E are the number of vertices and edges of the input visibility graph of the convex fan, respectively. We present this algorithm in Section 6.8. Hidden vertex sets have also been studied by Eidenbenz [124, 125], Ghosh et al. [163] and Lin and Skiena [244]. In visibility graphs of simple polygons, the problems of finding a minimum vertex cover and a maximum dominating set are NP-hard as shown by Lin and Skiena [244]. Everett [133] proved that the problem of determining whether the visibility graphs of two polygons with holes are isomorphic is isomorphic-complete. This problem remains isomorphic-complete even for the visibility graphs of two simple polygons as shown by Lin and Skiena [244]. In Section 6.9, we discuss isomorphic visibility graphs and similar polygons. The problem of computing the maximum clique in the visibility graph is not known to be NP-hard. Observe that the maximum clique in a visibility graph corresponds to the largest empty convex polygon inside the corresponding polygon. Ghosh et al. [167] have recently presented an O(n2 E) time algorithm for computing the maximum clique in the visibility graph of a simple polygon, under the assumption that the Hamiltonian cycle in the visibility graph corresponding to the boundary of the polygon is given along with the visibility graph as an input. We present the algorithm of Ghosh et al. [167] in Section 6.7.
6.2 Recognizing Visibility Graphs of Simple Polygons 6.2.1 Necessary Conditions In this section, we present the four necessary conditions of Ghosh [157] for recognizing visibility graphs of simple polygons. During the presentation of these conditions, we have included the counter-examples given by Everett and Corneil [133, 135], Abello et al. [4] and Streinu [316, 317]. Given a graph G and a Hamiltonian cycle C of G, the recognition problem is to determine if G is the visibility graph of a simple polygon P whose boundary corresponds to the cycle C. This problem is easier than the actual recognition problem as the edges of G that correspond to the boundary edges of P have already been identified. We assume that the vertices of G are labeled with v1 , v2 , . . . , vn and the cycle C = (v1 , v2 , . . . , vn ) is in counterclockwise order. A cycle is a simple and closed path in G. An edge in G connecting two non-adjacent vertices of a cycle is called a chord of the cycle. A cycle u1 , u2 , . . . , uk in G is said to be ordered if the vertices u1 , u2 , . . . , uk follow the order in C. The Hamiltonian cycle C is an ordered cycle of all n vertices in G. We make the following observations on the structure of an ordered cycle.
6.2 Recognizing Visibility Graphs of Simple Polygons
175
Figure 6.1 (a) The blocking vertex for the invisible pair (v4 , v6 ) is v5 . (b) There is no blocking vertex for the invisible pair (v2 , v5 ).
Necessary condition 1. Every ordered cycle of k ≥ 4 vertices in a visibility graph has at least k − 3 chords. Proof. Since an ordered cycle of k vertices in a visibility graph of a simple polygon P corresponds to a sub-polygon P 0 of k vertices in P , the ordered cycle has at least k − 3 chords in the visibility graph as P 0 requires k − 3 diagonals for triangulation of P 0 . A pair of vertices (vi , vj ) in G is a visible pair (or invisible pair) if vi and vj are connected (respectively, not connected) by an edge in G. Without loss of generality, we assume i is always less than j for an invisible pair (vi , vj ). For any two vertices vi and vj in G, the vertices from vi to vj on C, including vi and vj , in clockwise and counterclockwise order are called the upper and lower chain of (vi , vj ), respectively. The vertices from vi to vj on C in counterclockwise order are also referred to as chain(vi , vj ). A vertex va is a blocking vertex for an invisible pair (vi , vj ) if no two vertices vk ∈ chain(vi , va−1 ) and vm ∈ chain(va+1 , vj ) are connected by an edge in G. Since the line of sight between vi and vj in P can be blocked using va , va is called a blocking vertex. In Figure 6.1(a), v5 is the blocking vertex for the invisible pair (v4 , v6 ). On the other hand, the invisible pair (v2 , v5 ) in Figure 6.1(b) does not have any blocking vertex and therefore, this graph is not a visibility graph of any simple polygon. Intuitively, blocking vertices are meant to correspond to reflex vertices of the polygon. However, all blocking vertices in G may not be reflex vertices in P . On the other hand, the reflex vertices in P are always blocking vertices in G as they introduce pockets on the boundary of P with the property that every pair of pockets are not mutually visible (see Figure 6.2(a)). This observation suggests the following necessary condition.
176
Visibility Graph Theory
Figure 6.2 (a) No two pockets are mutually visible. (b) Two invisible pairs (v i , vj ) and (vk , vl ) are separable with respect to a blocking vertex va .
Necessary condition 2. Every invisible pair in a visibility graph has at least one blocking vertex. Proof. For an invisible pair (vi , vj ), the Euclidean shortest path in P between vi and vj makes turns at one or more reflex vertices, and each of these reflex vertices is a blocking vertex for (vi , vj ) in G. The above proof suggests that an invisible pair (vi , vj ) can have more than one blocking vertex as the Euclidean shortest path in P between vi and vj may turn at more than one reflex vertex. It means that blocking vertices in the lower chain or upper chain of an invisible pair form a chain of consecutive reflex vertices in P (see Figure 6.2(a)). This observation leads to the following lemmas on the structure of blocking vertices. Lemma 6.2.1 Let va and vb be the blocking vertices in the lower chain (or upper chain) for an invisible pair (vi , vj ), where i < a < b < j (Figure 6.2(a)). Vertices va and vb are also blocking vertices for the invisible pairs (vi , vb ) and (va , vj ), respectively. Lemma 6.2.2 Let va and vb be the blocking vertices in the lower chain (or upper chain) for invisible pairs (vi , vb ) and (va , vj ), respectively, where i < a < b < j (Figure 6.2(a)). Vertices va and vb are also blocking vertices for the invisible pair (vi , vj ). The above lemmas suggest that it is sufficient to consider only those invisible pairs in G which have one blocking vertex in the lower chain or one blocking vertex in the upper chain or one blocking vertex in each chain. Henceforth, we consider only such invisible pairs of G and they are called minimal invisible pairs.
6.2 Recognizing Visibility Graphs of Simple Polygons
177
Figure 6.3 (a) The visibility of separable invisible pairs (v2 , v7 ) and (v4 , v7 ) cannot be simultaneously blocked by the blocking vertex v3 . (b) This graph was proposed by Everett and Corneil as a counter-example to Ghosh’s earlier conjecture for sufficiency.
Exercise 6.2.1 Let va and vb be the blocking vertices of G in the lower and upper chains of a minimal invisible pair (vi , vj ) respectively. If there is an edge in G connecting a vertex of chain(va+1 , vb−1 ) to another vertex of chain(vb+1 , va−1 ), then prove that both va and vb are reflex vertices in the polygon [157]. Let va be a blocking vertex in G for two invisible pairs (vi , vj ) and (vk , vl ) (see Figure 6.2(b)). Consider the situation when the Hamiltonian cycle C is traversed from va in counterclockwise order. If vk and vl are encountered before vi and vj during the traversal, then (vi , vj ) and (vk , vl ) are called separable with respect to va . In Figure 6.3(a), v3 is the blocking vertex for both invisible pairs (v2 , v7 ) and (v4 , v7 ). Since (v2 , v7 ) and (v4 , v7 ) are separable with respect to v3 and v3 is the only blocking vertex, v3 cannot simultaneously block the visibility of both (v2 , v7 ) and (v4 , v7 ). We have the following necessary conditions. Necessary condition 3. Two separable invisible pairs in a visibility graph must have distinct blocking vertices. Proof. Let va be the only blocking vertex for two separable invisible pairs (vi , vj ) and (vk , vl ). We prove only for the case when va belongs to the lower chain of (vi , vk ) (see Figure 6.2(b)). Observe that va is a reflex vertex in P because the visibility in P between vi and vj as well as between vk and vl can only be blocked by va . Since the sub-polygons of P corresponding to ordered cycles vi , va , vj , . . . , vi and va , vk , . . . , vl , va are disjoint, va cannot simultaneously block the visibility between vi and vj and between vk and vl in P .
178
Visibility Graph Theory
Ghosh conjectured in the earlier version of his work [154] that if G satisfies these three necessary conditions, G is the visibility graph of a simple polygon P . However, it is not true for the graph in Figure 6.3(b). It can be seen that this graph satisfies the three necessary conditions of Ghosh. On the other hand, blocking vertices v 2 and v4 cannot block simultaneously the visibility between three invisible pairs (v1 , v8 ), (v3 , v8 ) and (v5 , v8 ). Therefore, the graph is not the visibility graph of any simple polygon. This counter-example to Ghosh’s earlier conjecture was given by Everett and Corneil [133, 135]. An assignment is a mapping from vertices of G to minimal invisible pairs in G such that: • a vertex assigned to any minimal invisible pair must be one of its blocking vertices, • every minimal invisible pair has been assigned by one of its blocking vertices, and
• if a vertex va is assigned to a minimal invisible pair (vi , vj ), then va is also assigned to every minimal invisible pair (vk , vm ) where vk ∈ chain(vi , va−1 ) and vm ∈ chain(va+1 , vj ). Everett [133] proposed the following stronger version of Necessary condition 3, which is in fact necessary as shown by Srinivasraghavan and Mukhopadhyay [314]. Necessary condition 30 . There is an assignment in a visibility graph such that no blocking vertex va is assigned to two or more minimal invisible pairs that are separable with respect to va . Exercise 6.2.2 Prove Necessary condition 30 . Abello et al. [4] gave another counter-example as shown in Figure 6.4(a) to Ghosh’s earlier conjecture of sufficiency [154]. This graph satisfies Necessary conditions 1 and 2, and there exists an unique assignment of blocking vertices v1 , v2 , v5 and v8 to all minimal invisible pairs in G as follows. The vertex v1 is assigned to (v2 , v9 ) and (v2 , v10 ), the vertex v2 is assigned to (v1 , v3 ) and (v1 , v4 ), the vertex v5 is assigned to (v1 , v6 ), (v2 , v6 ), (v3 , v6 ), (v4 , v6 ), (v4 , v7 ) and (v4 , v8 ), and the vertex v8 is assigned to (v1 , v7 ), (v2 , v7 ), (v5 , v9 ), (v6 , v9 ), (v7 , v9 ) and (v7 , v10 ). This assignment shows that no blocking vertex is assigned to two or more of its separable invisible pairs and therefore, this graph also satisfies Necessary condition 3 0 . However, the graph is not the visibility graph of any simple polygon. Consider the ordered cycle (v1 , v2 , v4 , v5 , v8 , v9 , v1 ) in the same graph of Figure 6.4(a). Let P 0 be the sub-polygon corresponding to this ordered cycle. Observe that the blocking vertices v1 , v2 , v5 , v8 are reflex vertices in P 0 . Therefore, there are four reflex vertices in P 0 with a total of six vertices, which is not possible. This observation suggests the following necessary condition.
6.2 Recognizing Visibility Graphs of Simple Polygons
179
Figure 6.4 (a) Abello et al. gave this graph as a counter-example to Ghosh’s earlier conjecture for sufficiency. (b) Streinu gave this graph as a counter-example to Ghosh’s new conjecture for sufficiency.
Necessary condition 4. Let D be any ordered cycle of a visibility graph. For any assignment of blocking vertices to all minimal invisible pairs in the visibility graph, the total number of vertices of D assigned to the minimal invisible pairs between the vertices of D is at most |D| − 3. Proof. Assume on the contrary that there is an assignment in the visibility graph which maps |D| − 2 or more vertices of D to the minimal invisible pairs that are between the vertices of D. Let P 0 be the sub-polygon which corresponds to D. Since every blocking vertex va is assigned to some minimal invisible pair between vertices of D, va is a reflex vertex in P 0 . So, the sum of internal angles of P 0 is more than (|D| − 2)180◦ contradicting the fact that the sum of internal angles of any simple polygon of |D| vertices is (|D| − 2)180◦ . Ghosh again conjectured in [157] that these four necessary conditions (1, 2, 3 0 , and 4) are sufficient to recognize the visibility graphs of simple polygons.. Recently, Streinu [316, 317] has given a counter-example to his new conjecture by providing the graph shown in Figure 6.4(b). This graph can be viewed as five symmetric ordered cycles each sharing an edge with the ordered cycle (v1 , v5 , v9 , v13 , v17 ) in the middle. This graph satisfies all four necessary conditions but it is not the visibility graph of any simple polygon. It is not clear whether either another necessary condition is required to circumvent this counter-example or there is a need to strengthen the existing necessary conditions. We hope that the visibility graph recognition problem will be settled in the near future.
180
Visibility Graph Theory
Figure 6.5 (a) The graph does not satisfy Necessary condition 1. (b) The vertices v a and vk are two consecutive visible vertices of va+1 .
6.2.2 Testing Necessary Conditions: O(n2 ) Algorithm We present an O(n2 ) time algorithm of Ghosh [157] for testing his first two necessary conditions (see Section 6.2.1), where n is the number of vertices of the given graph G. As in the previous section, we assume that the vertices of G are labeled with v1 , v2 , . . . , vn and the Hamiltonian cycle C = (v1 , v2 , . . . , vn ) is in counterclockwise order. We also assume that G is stored in an adjacency matrix. We use the notions and definitions of Section 6.2.1 in presenting the algorithm. It can be seen that Necessary condition 1 can be tested by checking the number of chords in every ordered cycle in G. As the number of vertices in an ordered cycle varies from 4 to n, visibility graphs have an exponential number of ordered cycles. Hence, this naive algorithm for testing Necessary condition 1 is an exponential-time algorithm. Consider any three vertices vi , vj and vk of G, where vk ∈ chain(vj , vi ). If (vi , vj ) and (vi , vk ) are visible pairs in G and (vi , vl ) is an invisible pair for every vl ∈ chain(vj+1 , vk−1 ), then vj and vk are called consecutive visible vertices of vi in G. For example, v6 and v4 are consecutive visible vertices of v1 in Figure 6.5(a). Intuitively, vj and vk are two consecutive vertices on the boundary of the visibility polygon of P from vi . We have the following lemma. Lemma 6.2.3 If the given graph G satisfies Necessary condition 1, then any two consecutive visible vertices of every vertex in G are connected by an edge in G. Proof. Let vj and vk be two consecutive visible vertices of vi . If (vj , vk ) is a visible pair in G, then the lemma holds. So, we assume that (vj , vk ) is an invisible pair and vk ∈ chain(vj , vi ). Let D be an ordered cycle of minimum number of vertices in G such that D passes through vk , vi , vj and vertices of chain(vj , vk ). Since (vj , vk ) is an invisible pair, |D| ≥ 4. Moreover, there is no diagonal between vertices on D
6.2 Recognizing Visibility Graphs of Simple Polygons
181
because D is the smallest ordered cycle. Since D is an ordered cycle without any diagonal, G does not satisfy Necessary condition 1, which is a contradiction. Hence (vj , vk ) is a visible pair in G. Consider the graph in Figure 6.5(a). This graph does not satisfy Necessary condition 1 as there is an ordered cycle (v1 , v3 , v5 , v7 ) without any diagonal. On the other hand, the graph satisfies the condition that any two consecutive visible vertices of every vertex are connected by an edge. Observe that there is no blocking vertex for invisible pairs (v1 , v5 ) and (v3 , v7 ). Therefore, the graph does not satisfy Necessary Condition 2. We have the following lemma. Lemma 6.2.4 If the given graph G satisfies the condition that any two consecutive visible vertices of every vertex in G are connected by an edge in G, but G does not satisfy Necessary condition 1, then G fails to satisfy Necessary condition 2. Exercise 6.2.3 Prove Lemma 6.2.4. For testing Necessary condition 1, the above lemmas suggest that it is enough to check whether or not any two consecutive visible vertices of every vertex in G are adjacent in G. Since G is stored in an adjacency matrix, the time required to check this condition for any vertex is O(n). For every invisible pair (vi , vj ) in G, Necessary condition 2 can be tested by checking whether there exists a blocking vertex va in the lower (or upper) chain of (vi , vj ). Since this checking for each invisible pair in G can be performed in O(n2 ) time, and the number of invisible pairs in G can be O(n2 ), this naive method takes O(n4 ) time. Using another approach, the time complexity for checking Necessary condition 2 can be improved to O(n2 ). The new approach is to locate those invisible pairs in G that can be blocked by a particular vertex va . We have the following lemma. Lemma 6.2.5 Let vk and va be two consecutive visible vertices of va+1 in G (Figure 6.5(b)). For every vertex vl ∈ chain(vk+1 , va−1 ), va is a blocking vertex for the invisible pair (va+1 , vl ). Corollary 6.2.6 If vk is the next clockwise vertex of va in C (i.e., k = a − 1), then va is not a blocking vertex for any invisible pair in G. Corollary 6.2.7 If va is a blocking vertex for any invisible pair in G, then one of the vertices of such an invisible pair belongs to chain(vk+1 , va−1 ). The above lemma suggests a method for locating all invisible pairs in G that can be blocked by va by traversing C in counterclockwise order starting from va+1 . At va+1 , the procedure takes two consecutive visible vertices va and vk of va+1 (see
182
Visibility Graph Theory
Figure 6.5(b)). A variable span for va is maintained which is initialized by k. So, va is a blocking vertex for all invisible pairs (va+1 , vl ), where vl ∈ chain(vspan+1 , va−1 ). Let vm and va be two consecutive visible vertices of va+2 in G. If vm belongs to chain(vspan , va−1 ), assign m to span. So, va is a blocking vertex for all invisible pairs (va+2 , vl ), where vl ∈ chain(vspan+1 , va−1 ). This process is repeated till span becomes a − 1. Thus, all invisible pairs in G can be located whose va is a blocking vertex. In the following, we state the major steps of the algorithm for testing Necessary conditions 1 and 2. The variables i is initialized by 1. Step 1. For each of the consecutive visible vertices vm and vk of vi in G, if (vm , vk ) is not a visible pair in G then goto Step 8. Step 2. Initialize j by i + 1. Initialize span by the index of some vertex which is adjacent to vj . Step 3. Initialize l by i − 1. While (vl , vj ) is an invisible pair in G and vl ∈ chain(vspan+1 , vi ), assign vi as a blocking vertex to (vl , vj ) and l := l − 1.
Step 4. If vl ∈ chain(vspan+1 , vi ) then span := l.
Step 5. If (vi−1 , vj+1 ) is an invisible pair in G then j := j + 1 and goto Step 3. Step 6. If i 6= n then i := i + 1 and goto Step 1.
Step 7. If every minimal invisible pair in G has a blocking vertex then report that G satisfies Necessary conditions 1 and 2 and goto Step 9. Step 8. Report that G does not satisfy Necessary conditions 1 and 2.
Step 9. Stop. The correctness of the testing algorithm follows from Lemmas 6.2.3, 6.2.4 and 6.2.5. Let us analyze the time complexity of the algorithm. Step 1 takes O(n) time as G is stored in an adjacency matrix. Let qi denote the number of invisible pairs located in Step 3 for vi . It can be seen that all invisible pairs in G, which can be blocked by vi , are located in time proportional to qi . Since Step 3 is executed for all vertices of G, blocking vertices for all invisible pairs in G can be located in time proportional to (q1 + q2 + . . . + qn ). If G has only minimal invisible pairs, then this sum is bounded by O(n2 ) as each invisible pair is consider once for its upper chain and once for its lower chain. Consider the situation when G has invisible pairs that are not minimal. In such a situation, (q1 + q2 + . . . + qn ) may not be bounded by O(n2 ) as the same invisible pair (vl , vj ) is considered once for each of its blocking vertices. This repetition can be avoided by restricting the variable l in Step 3 up to the blocking vertex located last. Thus, all of the invisible pairs in G that are not minimal are also considered at most twice. Hence, Necessary conditions 1 and 2 can be tested in O(n 2 ) time. We have the following theorem.
6.3 Characterizing Visibility Graphs of Simple Polygons
183
Figure 6.6 (a) The vertices v2 , v8 , v4 , v10 and v6 have formed a chordless cycle. (b) The vertices v2 , v6 , v5 , v4 and v8 have formed a chordless cycle.
Theorem 6.2.8 Given a graph G of n vertices and a Hamiltonian cycle in G, Necessary conditions 1 and 2 can be tested in O(n2 ) time.
6.3 Characterizing Visibility Graphs of Simple Polygons As mentioned in Section 6.1, the problem of characterizing visibility graphs of simple polygons is still an open problem in spite of the efforts made by several researchers over the last two decades. In this section, we present the properties and counterexamples that have evolved out of the studies of Ghosh [154, 157], Coullard and Lubiw [97], Everett and Corneil [133, 135] and Abello and Kumar [2, 3] in their attempts to characterize visibility graphs of simple polygons. Special Classes of Graphs Necessary conditions presented in Section 6.2.1 show that visibility graphs of simple polygons have natural structures. It appears from Ghosh’s Necessary condition 1 that visibility graphs may fall into one of the well known special classes of graphs, e.g., perfect graphs, circle graphs, or chordal graphs. However, Ghosh [154, 157] has found counter-examples in all cases. In the following, we present these counter-examples. We say that a graph G0 is a sub-graph of another graph G if G0 consists of a subset of vertices and edges of G. If G0 consists of a subset of vertices V 0 of G and all edges of G between these vertices in V 0 , then G0 is called an induced sub-graph of G0 . If all vertices of an induced sub-graph G0 of G are adjacent to each other, then G0 is called a clique. The chromatic number of a graph G is the smallest number of colors required to color vertices of G such that two vertices of every edge in G have
184
Visibility Graph Theory
different colors. An undirected graph G is called a perfect graph [170] if for every induced sub-graph G0 of G (including G itself), the size of the maximum cardinality clique of G0 is the chromatic number of G0 . Consider the visibility graph G of a simple polygon shown in Figure 6.6(a). Let be the induced sub-graph of G formed by the vertices v2 , v8 , v4 , v10 and v6 . It can be seen that the vertices v2 , v8 , v4 , v10 and v6 have formed an odd cycle without chord in G0 . Therefore, the chromatic number of G0 is not equal to the size of the maximum clique in G0 . Hence, G is not a perfect graph. Note that this cycle is an unordered cycle in G. G0
An undirected graph G is called a chordal graph if every cycle having four or more vertices has a chord [170]. The above counter-example also shows that visibility graphs of simple polygons are not chordal graphs as the visibility graph contains an unordered cycle v2 , v8 , v4 , v10 and v6 without a chord. Consider a simple polygon such that its visibility graph G does not have any unordered cycle of four or more vertices without a chord. In that case, G is a chordal graph because by Necessary Condition 1 in Section 6.2.1, every ordered cycle of four or more vertices in G has a chord. Therefore, visibility graphs of this class of simple polygons are chordal graphs. On the other hand, any chordal graph having a Hamiltonian cycle may not be the visibility graph of a simple polygon. For example, the graph in Figure 6.1(b) is a chordal graph but the graph is not the visibility graph of a simple polygon. We state this observation in the following lemma. Lemma 6.3.1 If every unordered cycle of four or more vertices in the visibility graph of a simple polygon has a chord, then the visibility graph is a chordal graph. A simple polygon P is called a fan if there is a vertex in P which can see all other vertices of P . Such a vertex of P is called a fan vertex. Note that a fan is a starshaped polygon but a star-shaped polygon need not be a fan. If the internal angle at a fan vertex is convex, the polygon is called a convex fan. Visibility graphs are not perfect graphs even for convex fans. Consider the convex fan shown in Figure 6.6(b). Since the vertices v2 , v6 , v5 , v4 and v8 have formed an odd cycle without a chord, the visibility graph of a convex fan is not a perfect graph. An undirected graph G is called a circle graph [68, 145] if every vertex of G can be represented as a chord of a circle C such that two chords in C intersect if and only if the corresponding vertices are adjacent in G. A graph H is not a circle graph if there exists a vertex in H which is adjacent to all vertices of any cycle having five or more vertices [68]. In the visibility graph of the convex fan shown in Figure 6.6(b), the vertex v1 is adjacent to all vertices of the cycle v2 , v6 , v5 , v4 and v8 . Hence, visibility graphs of simple polygons are not circle graphs. We state these facts in the following lemma.
6.3 Characterizing Visibility Graphs of Simple Polygons
185
Lemma 6.3.2 Visibility graphs of simple polygons do not belong to the union of perfect graphs and circle graphs. Clique Ordering A graph G is 3-connected if there is no set of fewer than three vertices whose removal disconnects G. In other words, there exists three or more disjoint paths in G between any two vertices of G. A 3-clique ordering of a graph G is an ordering of vertices of G (say, v1 , v2 , . . . , vn ) such that the first three vertices (i.e., v1 , v2 and v3 ) form a clique and for every vertex vi for i > 3, there exists a clique of three vertices vj , vk and vl such that (i) vj , vk and vl are adjacent to vi in G, and (ii) j < i, k < i and l < i. We have the following condition from Coullard and Lubiw [97]. Lemma 6.3.3 Each 3-connected component of the visibility graph of a simple polygon has a 3-clique ordering starting from any 3-clique. Although the above property shows some structure in the visibility graph of a simple polygon, it does not lead to the characterizing of a visibility graph as any graph satisfying this condition is not necessarily the visibility graph of a simple polygon [4, 97, 135]. Exercise 6.3.1 Draw a graph G such that (i) G satisfies Lemma 6.3.3 and (ii) G is not the visibility graph of any simple polygon.
Forbidden Induced Sub-graphs A graph H is said to be forbidden for a class of graphs if H is not an induced sub-graph of any graph in this class. The readers may know that the planar graphs can be characterized in terms of forbidden induced sub-graphs. In the same spirit, Everett and Corneil [133, 135] have asked the following question: is there a finite set of forbidden induced sub-graphs that characterize visibility graphs? They have shown that there is no such set that characterize visibility graphs. We start with a lemma of Everett and Corneil [133, 135], which follows from Necessary condition 1 of Ghosh presented in Section 6.2.1. Lemma 6.3.4 Let H be a graph containing an ordered chordless cycle of length at least 4 for every Hamiltonian cycle in H. Then, H is a forbidden induced sub-graph of visibility graphs of simple polygons. Consider the graph in Figure 6.7(a), which is known as Gr¨otsch graph. It can be seen that this graph is a forbidden induced sub-graph of a visibility graph as it
186
Visibility Graph Theory
Figure 6.7 (a) Gr¨otsch graph. (b) A variation of Gr¨otsch graph.
satisfies Lemma 6.3.4. This graph can be shown to be minimal using an exhaustive search by considering all induced sub-graphs of this graph. Starting from a variation of this graph which is obtained by replacing the outer cycle of Gr¨otsch graph by an inner cycle (see Figure 6.7(b)), Everett and Corneil have suggested a method for constructing an infinite family of minimal forbidden sub-graphs of visibility graphs. For more details of this construction, see [133, 135]. We state the result in the following lemma. Lemma 6.3.5 There exists an infinite family of minimal forbidden induced sub-graphs of visibility graphs of simple polygons. Euclidean Shortest Paths Abello and Kumar [2, 3] have introduced a class of graphs called quasi-persistent graphs, which is equivalent to the class of graphs satisfying Necessary conditions 1 and 2 of Ghosh [154, 157] presented in Section 6.2.1. This equivalence also suggests that this class of graph can be recognized by the testing algorithm of Ghosh for Necessary conditions 1 and 2 (see Section 6.2.2). Abello and Kumar [2, 3] have suggested four necessary conditions for quasipersistent graphs to be visibility graphs of simple polygons. Their first necessary condition, which is called locally-inseparable, is essentially same as Necessary Condition 30 presented in Section 6.2.1. The second, third and fourth necessary conditions correspond to the properties of Euclidean shortest paths between vertices in a simple polygon. Here we state these three necessary conditions of Abello and Kumar [2, 3] under the assumption that the given graph G is a quasi-persistent graph. We follow the same notions used in Section 6.2.1 for presenting these conditions. For an invisible pair (vi , vj ) in G and an assignment β of blocking vertices to invisible
6.4 Recognizing Special Classes of Visibility Graphs
187
pairs in G, an occluding path between vi and vj under β (denoted as pathβ (vi , vj )) is defined as the path from vi to vj in G consisting of vertices assigned by β such that only the adjacent vertices in the path is connected by an edge in G. Necessary condition 2. If a quasi-persistent graph G can be realized as a simple polygon under an assignment β of blocking vertices to invisible pairs in G, then for every invisible pair (vi , vj ) in G, pathβ (vi , vj ) is the same as pathβ (vj , vi ) in the reverse order. Necessary condition 3. If a quasi-persistent graph G can be realized as a simple polygon under an assignment β of blocking vertices to invisible pairs in G, and if vk ∈ pathβ (vi , vl ) and vl ∈ pathβ (vk , vj ), then vk , vl ∈ pathβ (vi , vj ). Necessary condition 4. If a quasi-persistent graph G can be realized as a simple polygon under an assignment β of blocking vertices to invisible pairs in G, and if vp ∈ pathβ (vi , vj ) is a blocking vertex of (vi , vj ), then for all vk on chain(vi , vp ) and vl on chain(vp , vj ), vp ∈ pathβ (vk , vl ). We know from Lemma 3.2.5 that the Euclidean shortest path in a simple polygon is unique and it follows from the fact that the sum of the internal angles of a simple polygon of n vertices is (n − 2)180◦ . Therefore, the above three conditions of Abello and Kumar, which correspond to the uniqueness property of Euclidean shortest paths, naturally follow from Ghosh’s Necessary condition 4. Exercise 6.3.2 Prove that Necessary conditions 2, 3 and 4 of Abello and Kumar follow from Ghosh’s Necessary condition 4 [157].
6.4 Recognizing Special Classes of Visibility Graphs 6.4.1 Spiral Polygons: O(n) Algorithm In this section, we present an O(n) time algorithm of Everett and Corneil [133, 134] for recognizing visibility graphs of spiral polygons. Given a graph G, the recognition problem is to determine whether G is the visibility graph of a spiral polygon S. The recognition algorithm is based on their characterization of visibility graphs of spiral polygons as interval graphs, which we also present in this section. It may be noted that although visibility graphs of simple polygons are not perfect graphs (see Lemma 6.3.2), it is not true for all special classes of polygons such as spiral polygons. We assume that the vertices of G are labeled with v1 , v2 , . . . , vn . In a spiral polygon, all reflex vertices occur consecutively along its boundary. So, the problem of recognizing the visibility graph of a spiral polygon Sn is to identify
188
Visibility Graph Theory
Figure 6.8 (a) A spiral polygon S7 . (b) The visibility graph G of S7 . (c) A non-spiral polygon Q.
a Hamiltonian cycle C = (v1 , v2 , . . . , vn ) (in counterclockwise order) in the given graph G such that there exists two special vertices vi and vj in Sn with the property that vi , vi+1 , . . ., vj are convex vertices in Sn and vj+1 , vj+2 , . . ., vi−1 are reflex vertices in Sn . A spiral polygon S7 is shown in Figure 6.8(a) and its visibility graph G is shown in Figure 6.8(b). Consider the non-spiral polygon Q in Figure 6.8(c). It can be seen that the visibility graph of Q is also G. However, the boundary of Q corresponds to another Hamiltonian cycle C = (v1 , v2 , v6 , v5 , v4 , v3 , v7 ) in G. So, the choice of a Hamiltonian cycle in G is crucial in recognizing the visibility graph of a spiral polygon. Let L denote the boundary of Sn from vi to vj (including vi and vj ) containing a convex chain of vertices vi , vi+1 , . . ., vj (see Figure 6.9). Similarly, let R denote the boundary of Sn from vj to vi (including vi and vj ) containing reflex vertices vj+1 , vj+2 , . . ., vi−1 . Suppose vi is removed from Sn by adding the diagonal vi+1 vi−1 in Sn . This gives another spiral polygon Sn−1 . If the angle at vi−1 is convex in Sn−1 (see Figure 6.9(a)), then L in Sn−1 consists of vertices vi−1 , vi+1 , vi+2 , . . ., vj and R in Sn−1 consists of vj , vj+1 , . . ., vi−1 . Note that the role of vi−1 in Sn−1 is the same as the role of vi in Sn . In the other situation, the angle at vi−1 in Sn−1 is reflex (see Figure 6.9(b)). Therefore, L in Sn−1 consists of vertices vi+1 , vi+2 , . . ., vj and R in Sn−1 consists of vj , vj+1 , . . ., vi−2 , vi+1 . Note that the role of vi+1 in Sn−1 is same as the role of vi in Sn . If this process of deletion is carried out recursively on Sn (see Figure 6.9(c)), we get a numbering of vertices of Sn starting from vi in the order they are removed from the polygon. Observe that the similar process of deletion can also be carried out starting from vj in Sn . The diagonals that are used to construct Sn−1 , Sn−2 , . . . , S3 along with the boundary of Sn form a Hamiltonian triangulation of Sn as the dual of this triangulation is a path. We have the following lemmas.
6.4 Recognizing Special Classes of Visibility Graphs
189
Figure 6.9 (a) The angle at vi−1 in Sn−1 is convex. (b) The angle at vi−1 in Sn−1 is reflex. (c) The vertices are numbered in the order they are deleted.
Lemma 6.4.1 There exists a Hamiltonian triangulation for every spiral polygon. Lemma 6.4.2 In a spiral polygon, there exists two vertices vi and vj such that the vertices of the polygon visible from either vi or vj form a clique in the visibility graph of the polygon. The above properties can be used for deriving properties in visibility graphs of spiral polygons. A vertex vk in a graph is called simplicial if the adjacent vertices of vk in the graph form a clique. The adjacent vertices of any vertex vk in a graph are called neighbors of vk . Locate a simplicial vertex vk in G and mark it as u1 . Construct the graph G − {u1 } by removing the vertex u1 from G and all edges incident on u1 in G. Again, locate a simplicial vertex vp in G − {u1 } such that vp is a neighbor of u1 in G, and mark it as u2 . Construct the graph G − {u1 , u2 } by removing the vertex u2 from G − {u1 } and all edges incident on u2 in G − {u1 }. Repeat this process until all vertices are numbered. If the given graph G is the visibility graph of a spiral polygon, then this process of deletion always succeeds due to Lemma 6.4.1. Any ordering of vertices {u1 , u2 , . . . , un } of G is called a perfect vertex elimination scheme if each ui is simplicial in the induced sub-graph G − {u1 , u2 , . . . , ui−1 }. A graph is called chordal if it has no chordless cycle of length greater than or equal to 4 [170]. We have the following lemmas. Lemma 6.4.3 The visibility graph of a spiral polygon admits a perfect vertex elimination scheme. Lemma 6.4.4 A graph is chordal if and only if it has a perfect vertex elimination scheme [144].
190
Visibility Graph Theory
Figure 6.10 (a) A spiral polygon S. (b) The visibility graph of S is drawn as an interval graph with the ordering of maximal cliques {c1 , c2 , c3 , c4 , c5 }.
Lemma 6.4.5 The visibility graph of a spiral polygon is a chordal graph. Proof. Proof follows from Lemmas 6.4.3 and 6.4.4. Consider three mutually non-adjacent vertices vp , vq and vk in G. If vp , vq and vk cannot be ordered such that every path in G from the first vertex vp to the third vertex vk passes through a neighbor of the second vertex vq , then vp , vq and vk are called an asteroidal triple in G. We have the following lemma. Lemma 6.4.6 A graph G is an interval graph if and only if G is a chordal graph containing no asteroidal triple [240]. Consider a graph G that can be represented as a set of intervals of a linearly ordered set such that (i) every vertex of G is represented as a distinct interval and (ii) two intervals overlap if and only if their corresponding vertices are connected by an edge in G. The graph G is called an interval graph [170]. Figure 6.10(a) shows a spiral polygon and its visibility graph is drawn in Figure 6.10(b) as an interval graph. We have the following necessary condition. Necessary condition 1. If G is the visibility graph of a spiral polygon S, then G is an interval graph. Proof. We know from Lemma 6.4.5 that G is a chordal graph. Let vp , vq and vk be any three pairwise non-adjacent vertices of G. Consider the sub-graph G 0 of G which corresponds to a Hamiltonian triangulation T (S) of S. By Lemma 6.4.1, T (S) always exists. Since the dual of T (S) is a path, vp , vq and vk can always be ordered in such a way that any path in G0 between the first and the third vertex (say, vp and vk , respectively) must pass through vertices of G corresponding to a triangle in
6.4 Recognizing Special Classes of Visibility Graphs
191
T (s), one of whose vertices is vq . Therefore, G does not have any asteroidal triple. Hence, G is an interval graph by Lemma 6.4.6. Exercise 6.4.1 Design a linear time algorithm for recognizing interval graphs [59]. Using the recognition algorithm of Booth and Lueker [59], it can be tested in O(n) time whether the given graph G is an interval graph. From now on, we assume that G is an interval graph. A clique in G is called maximal if it is not a sub-graph of any other clique of G. In the following lemma, we present a property on the ordering of maximal cliques in an interval graph, which is used to identify vertices of G belonging to L or R. Lemma 6.4.7 For every vertex vk of an interval graph, the maximal cliques of the graph can be linearly ordered such that the maximal clique containing v k occur consecutively [169]. During the process of testing for interval graphs, the algorithm of Booth and Lueker [59] computes an ordering of maximal cliques {c1 , c2 , . . . , cm }. Figure 6.10(b) shows an ordering of maximal cliques {c1 , c2 , . . . , c5 } in the visibility graph for a spiral polygon S. A vertex vl ∈ ci for all i is called a conductor of a clique ci , if vl also appears in the clique ci+1 . It can be seen that for any three consecutive vertices vk−1 , vk and vk+1 in either R or L, the middle vertex vk is a conductor in G. Moreover, if vk−1 ∈ ci and vk+1 ∈ cj in the ordering of maximal cliques in G, then vk belongs to all maximal cliques between ci and cj by Lemma 6.4.7. In order to find a Hamiltonian cycle C in G which corresponds to the boundary of a spiral polygon, we have to find an order of conductors in G from c1 to cm and then split the conductors according to their own properties so that one part forms L and the other part forms R. We have the following observations on the conductors that belong to R = (vj , vj+1 , . . . , vi−1 , vi ). Lemma 6.4.8 The vertex vi belongs only to the first maximal clique c1 in G and the vertex vj belongs only to the last maximal clique cm in G. Corollary 6.4.9 The vertices vi and vj are not conductors in G. Lemma 6.4.10 If G is the visibility graph of a spiral polygon, then (i) each maximal clique in G has at most two vertices of R, (ii) all vertices in R − {vi , vj } are conductors in G, and (iii) every maximal clique in G has a vertex of R and a vertex of L. Corollary 6.4.11 If two vertices of R belong to any maximal clique, then one of them can be a conductor of that clique.
192
Visibility Graph Theory
It can be seen that the path between vi to vj in G corresponding to R is a path where no two non-adjacent vertices in the path is connected by an edge in G. In other words, vk ∈ R is the sole blocking vertex for the minimal invisible pair (vk−1 , vk+1 ). For the definition of a blocking vertex, see Section 6.2.1. An induced path in G between vertices vi and vj covers an interval graph G if (i) vi ∈ c1 and vj ∈ cm , (ii) all vertices in the path excluding vi and vj are conductors in G, and (iii) the path contains only one conductor from each maximal clique between c1 and cm−1 . An induced path in the graph of Figure 6.10(b) is the path formed by v1 , v10 , v9 , v8 , and v7 . We have the following lemma. Lemma 6.4.12 If G is the visibility graph of a spiral polygon, then an induced path in G, which corresponds to R in the spiral polygon, covers G. Proof. Proof follows from Lemma 6.4.8 and Corollaries 6.4.9 and 6.4.11. Let us consider the path in G that corresponds to L. It can be seen that v4 ∈ L is a conductor of c3 in the graph shown in Figure 6.10(b) but v3 ∈ L is not a conductor of c3 . So, v3 must precede v4 in L. Let bi denote the conductors of ci , i.e., bi is the set of vertices that belong to both ci and ci+1 . In the interval graph of Figure 6.10(b), b1 = {v2 , v3 , v10 }, b2 = {v3 , v4 , v10 }, b3 = {v4 , v5 , v9 }, b4 = {v6 , v8 }. Note that if |bi | < 2 for 1 ≤ i ≤ m − 1, then G does not have any Hamiltonian cycle. A path in an interval graph G is called straight if (i) all vertices of ci − bi precedes the vertices of bi in the path, where 1 ≤ i ≤ m and, (ii) all vertices of ci − bi−1 succeeds the vertices of bi−1 in the path, where 1 ≤ i ≤ m. For any vertex vk in G, let low(vk ) denote the smallest index clique containing vk . Similarly, high(vk ) denotes the largest index clique containing vk . We have the following lemma. Lemma 6.4.13 If G is the visibility graph of a spiral polygon, then a path in G which corresponds to either L or R is straight. Corollary 6.4.14 If there is no edge in G between any two non-adjacent vertices in a straight path in G, then the path corresponds to R. Corollary 6.4.15 (i) For every vertex vk of L in G, low(vk ) ≤ low(vk+1 ) and high(vk ) ≤ high(vk+1 ). (ii) For every vertex vk of R in G, low(vk ) ≤ low(vk−1 ) and high(vk ) ≤ high(vk−1 ). Consider a vertex vk in G such that low(vk ) < high(vk ) − 1 (see Figure 6.11). Consider another vertex vp such that low(vk ) < low(vp ) and high(vp ) < high(vk ). Intuitively, the interval of vp is properly contained in the interval of vk in the interval graph G. It can be seen that if (i) low(vp ) = high(vp ) (see Figure 6.11(a)) or (ii) vp belongs to L (see Figure 6.11(b)), then G cannot be the visibility graph of a spiral
6.4 Recognizing Special Classes of Visibility Graphs
193
Figure 6.11 (a) The vertex vp belongs to only one clique. (b) The vertex vp must belong to R.
polygon. Such a vertex vp is called overlaying vertex. Note that the second condition suggests a way to identify some vertices of G that must belong to R. Observe that if there exists such a vertex vp with respect to vk , then vp must belong to R provided low(vp ) 6= high(vp ) (see Figure 6.11(b)). However, for every reflex vertex vp in R, there may not always be a corresponding vertex vk . So, using this condition, not all reflex vertices of R may be identified. We have the following lemma. Lemma 6.4.16 If G is the visibility graph of a spiral polygon, then G does not have any overlaying vertex. The above three lemmas constitute the following necessary condition. Necessary condition 2. If G is the visibility graph of a spiral polygon S, then (i) an induced path in G, which corresponds to R in S, covers G, (ii) a path in G, which corresponds to L of S, is straight, and (iii) G does not have any overlaying vertex. Exercise 6.4.2 Prove Necessary condition 2. Assume that the given graph G has satisfied Necessary Conditions 1 and 2, and some vertices of R (say, u2 , u3 , . . . , uq−1 ) have been identified. Take any vertex from c1 − b1 as u1 . Take any vertex from cm − bm−1 as uq . So, u1 is vi and uq is vj . Let U = (u1 , u2 , . . . , uq ). Assume that for any vertex ui ∈ U , low(ui ) ≤ low(ui+1 ) and high(ui−1 ) ≤ high(ui ), i.e., the vertices of U are ordered in the same way they are identified. Observe that if any two vertices of U are conductors of the same clique, then G is not the visibility graph of a spiral polygon by Corollary 6.4.11. If every pair of two consecutive vertices of U are connected by an edge in G, then the
194
Visibility Graph Theory
path formed by U corresponds to R. So, we assume that no two vertices of U are connected by an edge in G. In order to identify other vertices of R, straight paths satisfying Corollary 6.4.14 from u1 to u2 , u2 to u3 , . . ., uq−1 to uq have to be constructed so that these paths contain the remaining vertices of R. To construct such a path between u i and ui+1 for all i, a depth-first search (DFS) method [221] starting from ui can be used to construct such a path to ui+1 . To ensure that the path constructed by DFS satisfies Corollary 6.4.14, the next vertex vk−1 is chosen by DFS from the current vertex vk satisfies the conditions that The path constructed in this manner is added between ui and ui+1 . By concatenating these paths, the entire path in G, which corresponds R, is constructed. The remaining vertices of G are added to L preserving the order of ci − bi precedes bi in L for all i. Once the paths corresponding to R and L are identified, the reverse order of the perfect vertex elimination scheme can be used to construct spiral polygons S3 , S4 , . . . , Sn . For more details of this polygon construction, see [133, 134]. We have the following theorem. Theorem 6.4.17 A graph G is the visibility graph of a spiral polygon if and only if G satisfies Necessary conditions 1 and 2. Exercise 6.4.3 Let G be a given graph satisfying Necessary conditions 1 and 2. Design a polynomial-time algorithm for drawing a spiral polygon such that G is its visibility graph [133, 134]. In the following, we state the major steps of the algorithm for identifying two paths in the given graph G, which correspond to L and R of an n-sided spiral polygon. Step 1. Using the algorithm of Booth and Lueker [59], construct an interval graph representation of G and compute the ordered set of maximal cliques {c1 , c2 , . . . , cm }.
Step 2. Construct the ordered set of conductors {b1 , b2 , . . . , bm−1 }.
Step 3. For every vertex vk of G, compute low(vk ) and high(vk ). Step 4. Check whether the paths in G are straight. Step 5. Check whether G has any overlaying vertex.
Step 6. Locate the ordered set of those vertices U of G that must belong to R. Step 7. Construct a straight path between two consecutive vertices of U using the modified DFS and concatenate these paths to form the path corresponding to R. Step 8. Construct another path in G, corresponding to L, consisting of the remaining vertices of G in the proper order. Step 9. Report both paths which correspond to L and R. Step 10. Stop.
6.4 Recognizing Special Classes of Visibility Graphs
195
Let us analyze the time complexity of the algorithm. Step 1 takes O(n) time as the recognition algorithm of Booth and Lueker [59] runs in O(n) time. Since the number of maximal cliques in a chordal graph is proportional to n [213], we use this fact in our analysis of the remaining steps. Since the total number of conductors in G is n − 2 and a maximal clique is considered twice, Step 2 takes O(n) time. For every vertex vk of ci in the order from c1 to cm , assign i to high(vk ). If vk does not belong to ci−1 or vk belongs to c1 , then assign i also to low(vk ). Considering each maximal clique once in the order, Step 3 can be performed in O(n) time. Step 4 and Step 5 can also be performed in O(n) time using the order of the cliques. Constructing two paths corresponding to L and R in Steps 7 and 8 take O(n) time as DFS runs in O(n) time [221]. Hence, the overall time complexity of the recognition algorithm is O(n). We summarize the result in the following theorem. Theorem 6.4.18 The visibility graph of a spiral polygon of n vertices can be recognized in O(n) time.
6.4.2 Tower Polygons: O(n) Algorithm In this section, we present an O(n) time algorithm of Colley et al. [95] for recognizing visibility graphs of tower polygons. Given a graph G, the recognition problem is to determine if G is the visibility graph of a tower polygon F . Their recognition algorithm is based on the characterization that visibility graphs of tower polygons are bipartite permutation graphs with an added Hamiltonian cycle. We assume that the vertices of G are labeled with v1 , v2 , . . . , vn . A tower polygon F is a simple polygon formed by two reflex chains of vertices with only one boundary edge connecting two convex vertices (see Figure 6.12(a)). The polygon F is also called a funnel. The convex vertex of F shared by two reflex chains is called the apex of F and the edge connecting two convex vertices of F is called the base of F . Let vj denote the apex of a tower polygon F (see Figure 6.12(a)). Let vi and vi+1 denote the other two convex vertices of F . Let us denote two reflex chains of vertices of F as R1 and R2 , where R1 = (vj , vj+1 , . . ., vi ), R2 = (vi+1 , vi+2 , . . ., vj ), and vertices in R1 and R2 are in counterclockwise order. Let V1 and V2 denote the vertices, excluding vj , of R1 and R2 , respectively. It can be seen that vj is always visible from some point z on the boundary edge vi vi+1 . Since V1 and V2 are on opposites sides of zvj , every visible segment in F connecting a vertex of V1 to a vertex of V2 intersects zvj . We have the following properties on V1 and V2 in F . Lemma 6.4.19 If a vertex vp of V1 (or V2 ) is visible from two vertices vl and vm of V2 (respectively, V1 ), then vp is also visible from all vertices of V2 (respectively, V1 ) between vl and vm (Figure 6.12(a)).
196
Visibility Graph Theory
Figure 6.12 (a) A tower polygon F . (b) A permutation graph and its geometric representation.
Corollary 6.4.20 If a vertex vp of V1 (or V2 ) is visible from a vertex vl of V2 (respectively, V1 ), then vp is also visible from the next clockwise or counterclockwise vertex of vl on the boundary of F . Lemma 6.4.21 Assume that vp ∈ V1 is visible from vm ∈ V2 and vq ∈ V1 is visible from vl ∈ V2 (i.e., vp vm and vq vl are visible segments). If vq is a vertex of R1 between vp and vi and if vm is a vertex of R2 between vl and vi+1 , then segments vp vl and vq vm lie inside F (Figure 6.12(a)). Let us state a property of bipartite permutation graphs which corresponds to Lemma 6.4.21. Let V = {1, 2, . . . , n} denote the vertex set of a graph H. The graph H is a permutation graph if there is a permutation π of V such that for every pair of vertices u < w, (u, w) is an edge in H if and only if π(u) > π(w) [132, 284]. Figure 6.12(b) shows the permutation of vertices of a permutation graph. A graph is a bipartite graph if its vertices can be partitioned into two sets such that there is no edge of the graph connecting vertices of the same set. A graph is called a bipartite permutation graph if it is both bipartite and a permutation graph [61]. A strong ordering of a bipartite graph B with vertex sets V1 and V2 is an ordering of V1 and V2 such that if there are edges (u, w 0 ) and (u0 , w) in B, where u, u0 ∈ V1 , u < u0 , w, w0 ∈ V2 and w < w0 , then B has also edges (u, w) and (u0 , w0 ). We have the following lemma. Lemma 6.4.22 A bipartite graph is a permutation graph if and only if it has a strong ordering [313]. Let us look at the geometric structures of a tower polygon F in the light of bipartite permutation graphs. For all of the consecutive vertices vm and vm+1 of −−−→ V2 , let um denote the intersection point of R1 and v−− m vm+1 . It can be seen that for any three consecutive points um−1 , um and um+1 , the point um lies between um−1
6.4 Recognizing Special Classes of Visibility Graphs
197
Figure 6.13 (a) A tower polygon F with extension of edges of R1 and R2 . (b) The geometric representation of the permutation of V1 ∪ V2 of F .
and um+1 on R1 . By extending each edge of R2 , locate the position of um on R1 for every vertex vm of V2 . Construct the merged order of vertices of V1 ∪ V2 for R1 by traversing R1 from vi to vj in the clockwise order and by inserting each vertex vm of V2 in the merged order according to the position of um on R1 . For the tower polygon in Figure 6.13(a), the merged order of vertices for R1 is 6, 5, 4, 7, 3, 8, 2, 9, 10 and 11. Similarly, by extending the edges of R1 to R2 , the merged order of vertices of V1 ∪ V2 for R2 can be constructed by traversing R2 from vi+1 to vj in counterclockwise order. For the tower polygon in Figure 6.13(a), the merged order of vertices for R2 is 7, 8, 9, 6, 10, 5, 11, 4, 3 and 2. The geometric representation of these two merged lists for the tower polygon in Figure 6.13(a) is shown in Figure 6.13(b), which corresponds to a permutation of V1 ∪ V2 . This structure in a tower polygon is used for characterizing visibility graphs of tower polygons. Let G be the visibility graph of a tower polygon F . Remove the edges from G that correspond to the edges of R1 and R2 in F and remove the vertex from G that corresponds to the apex of F . The remaining graph of G, denoted as G0 , is called the cross-visible sub-graph of G. It can be seen that G0 is a bipartite graph and it satisfies Lemma 6.4.22. We have the following necessary and sufficient condition for recognizing visibility graphs of a tower polygon. Theorem 6.4.23 A graph G is the visibility graph of a tower polygon if and only if its cross-visible sub-graph G0 is a bipartite permutation graph. Exercise 6.4.4 Prove Theorem 6.4.23. The above theorem suggests that in order to recognize a given graph G as the visibility graph of a tower polygon, construct G0 from G and test whether G0 is a bipartite permutation graph. It can be tested in linear time whether G0 is a bipartite permutation graph [61, 313]. However, to construct G0 from G, it is necessary to
198
Visibility Graph Theory
identify a Hamiltonian cycle C in G which corresponds to the boundary of a tower polygon. Moreover, three vertices of C have to be identified, which correspond to convex vertices of a tower polygon. So, the problem of recognizing visibility graphs of tower polygons is now reduced to the problem of locating a Hamiltonian cycle C in G and identifying three special vertices in C.
Exercise 6.4.5 Design a linear time algorithm for recognizing bipartite permutation graphs [61, 313].
Let w be a vertex of the given graph G such that it is adjacent to exactly two other vertices of G. If no such vertex w exists, then G is not the visibility graph of a tower polygon as the apex of any tower polygon F can see only its two adjacent vertices on the boundary of F . So, we assume that such a vertex w exists in G. If there are two such vertices w in G, then one of them corresponds to the apex of F and the other one corresponds to a vertex of the base of F . If there are three or more such vertices w in G, then G cannot be the visibility graph of any tower polygon. Since there can be at most two such vertices w, considering each vertex w as the vertex corresponding to the apex of F , the recognition algorithm tests whether G is the visibility graph of a tower polygon. If it fails for both vertices, then G is not the visibility graph of a tower polygon. Without loss of generality, we assume that there is only one such vertex w in G. Treating w as the vertex corresponding to the apex of F , the remaining vertices of G are partitioned into two ordered sets V1 and V2 such that the vertices of V1 and V2 correspond to the sequence of vertices of R1 and R2 of F , respectively. Label w as vj (see Figure 6.14). Label two neighbors of vj in G as vj+1 and vj−1 . Observe that if vj+1 and vj−1 are not connected by an edge in G, then G is not the visibility graph of any tower polygon. So, we assume that vj+1 and vj−1 are connected by an edge in G. The vertex vj+1 becomes the first vertex in V1 and similarly, vj−1 becomes the first vertex of V2 . The ordered sets V1 and V2 are constructed by labeling a pair of vertices of G at each iteration, one belonging to V1 and the other belonging to V2 , until all vertices of G are labeled. Assume that vp and vm are the last vertices added to V1 and V2 , respectively. We know that vp and vm are connected by an edge in G. The vertices vm , vm+1 , . . . , vp−1 , vp are called labeled vertices of G, and the remaining vertices of G are called unlabeled vertices. We have the following lemma on the labeling of the next pair of vertices of G. Lemma 6.4.24 Let vp and vm be the last pair of vertices of G that has been labeled. Let K be a maximal clique such that (i) vp and vm are vertices of K, and (ii) the remaining vertices of K are unlabeled vertices of G. If K has five or more vertices, then G is not the visibility graph of a tower polygon.
6.4 Recognizing Special Classes of Visibility Graphs
199
Figure 6.14 (a) The labeled vertices vj+1 and vp belong to V1 , and labeled vertices vj−1 and vm belong to V2 . The other vertices are not yet labeled. (b) The unlabeled vertex u is added to V1 . (c) The unlabeled vertex u is added to V2 .
Corollary 6.4.25 If G is the visibility graph of a tower polygon, then K is the maximal clique in G having one or two unlabeled vertices. Let W be the set of all unlabeled vertices of G that are neighbors of both vp and vm in G. If the vertices of W do not form a clique or the size of W is more than two, then G is not the visibility graph of a tower polygon by Lemma 6.4.24. So, we assume that the vertices of W ∪ {vp } ∪ {vm } is a clique K of size three or four. If K has four vertices (see Figure 6.14(a)), one unlabeled vertex of K is labeled as vp+1 and the other unlabeled vertex of K is labeled as vm−1 . Then vp+1 and vm−1 are added to V1 and V2 , respectively. If K has three vertices, then the unlabeled vertex u of K is added to either V1 or V2 . For the graph in Figure 6.14(b), u is added to V1 . The vertex u is added to V1 (or V2 ) if (i) there is no unlabeled vertex in G that forms a clique with u and vp (respectively, vm ), and (ii) there exists a unlabeled vertex that forms a clique with u and vm (respectively, vp ). For the graph in Figure 6.14(c), u is added to V2 . If u cannot be added to either V1 or V2 , then G is not the visibility graph of a tower polygon. By repeating this process of labeling of vertices of G, the ordered sets of vertices V1 and V2 can be constructed. We have the following lemma. Lemma 6.4.26 If the given graph G is the visibility graph of a tower polygon F , then using the method of labeling, the vertices of G can be partitioned into three sets of vertices {vj }, V1 = {vj+1 , vj+2 , . . . , vi } and V2 = {vj−1 , vj−2 , . . . , vi+1 } such that vj corresponds to the apex of F , and the ordered sets of vertices V1 and V2 correspond to the sequence of vertices of R1 and R2 of F respectively.
200
Visibility Graph Theory
Once V1 and V2 are known, the cross-visible sub-graph G0 can be constructed from G. If G0 satisfies Theorem 6.4.23, then G is the visibility graph of a tower polygon. In the following, we state the major steps of the algorithm for recognizing the given graph G of n vertices as the visibility graph of a tower polygon. Step 1. Locate the vertex w of degree two in G which has formed a clique with two of its neighbors. Label w as v1 and the neighbors of w as v2 and vn . Add v2 and vn to V1 and V2 , respectively. Assign 2 to p and n to m. Step 2. Locate the maximal clique K consisting of vp , vm and unlabeled vertices of G. Step 3. If |K| = 2 or |K| > 4 then goto Step 8. Step 4. If |K| = 4 then
Step 4a. Increment p by 1, label an unlabeled vertex of K as vp and add it to V1 . Step 4b. Decrement m by 1, label the unlabeled vertex of K as vm , add it to V2 and goto Step 6. Step 5. Let u be the unlabeled vertex of K. If K is the only clique with u and vp in the remaining unlabeled graph of G then increment p by 1, label u as vp and add it to V1 else decrement m by 1, label u as vm and add it to V2 . Step 6. If all vertices of G are not labeled then goto Step 2. Step 7. Construct the cross-visible sub-graph G0 of G using V1 and V2 . If G0 is a bipartite permutation graph then report that G is the visibility graph of a tower polygon and goto Step 9. Step 8. Report that G is not the visibility graph of a tower polygon. Step 9. Stop. The correctness of the algorithm follows from Lemma 6.4.26 and Theorem 6.4.23. Let us analyze the time complexity of the algorithm. Step 1 can be performed in O(n) time. Step 2 involves locating the maximal clique K containing vp and vm in the unlabeled graph of G. Let W1 be the unlabeled vertices of G that are adjacent to vp . Let W2 ⊂ W1 be the vertices in G that are adjacent to vm . So, the vertices of W2 with vp and vm have formed the current maximal clique K. It can be seen that the vertices in W1 − W2 must belong to V2 and these vertices can be ordered as they correspond to consecutive reflex vertices of R 2 in a tower polygon. This ordering helps to locate the maximal clique containing a vertex of W2 for subsequent iterations. It means that the current maximal clique K can be located in time proportional to its size. Therefore, Step 2 can be executed in O(n) time. Similarly, Step 5 can also be executed in O(n) time. Constructing and testing G0 in Step 7 can be done in O(n) time [61, 313]. Hence, the overall time complexity of the recognition algorithm is O(n). We summarize the result in the following theorem.
6.5 Characterizing a Sub-Class of Segment Visibility Graphs
201
Figure 6.15 (a) The segment visibility graph Gs of a set S of disjoint line segments. (b) The segment visibility graph Gf of these three line segments is 4-connected. (c) There are four empty convex quadrilaterals in this set S of seven line segments.
Theorem 6.4.27 The visibility graph of a tower polygon of n vertices can be recognized in O(n) time.
6.5 Characterizing a Sub-Class of Segment Visibility Graphs In this section, we present the characterization of a special class of segment visibility graphs given by Everett et al. [136]. They have characterized those segment visibility graphs that do not have K5 (a complete graph of five vertices) as a minor. This class of graphs is called K5 -free segment visibility graphs. Their characterization gives a straightforward polynomial time algorithm for recognizing this class of graphs. Let S be a set of n disjoint line segments in the plane. If the line segment uw joining two endpoints u and w of different segments in S does not intersect any segment in S (except at u and w), then uw is called visible segment in S. The segment visibility graph Gs of S is a graph whose 2n vertices represent 2n endpoints of line segments in S and whose edges represent visible segments in S (see Figure 6.15(a)). A graph M is called a minor of a graph G if M can be obtained from G by a sequence of vertex deletions, edge deletions and edge contractions. It can be seen that K4 in any segment visibility graph corresponds to an empty convex quadrilateral formed by four endpoints of segments in S assuming no three-segment endpoints of K4 are collinear. Figure 6.15(c) shows four empty convex quadrilaterals in a set of seven line segments. We have the following lemma. Lemma 6.5.1 There are at least n − 3 empty convex quadrilaterals in S for |S| ≥ 4. Exercise 6.5.1 Prove Lemma 6.5.1. A graph is called planar if it can be embedded on the plane such that no two edges intersect. We know that Kuratowski’s theorem characterizes planar graphs as
202
Visibility Graph Theory
those graphs that do not have K5 or K3,3 as a minor [58, 224], where K3,3 denotes the complete bipartite graph with three vertices in each vertex set. The similarity between planar graphs and K5 -free segment visibility graphs is that both do not have K5 as a minor. A graph G is called k-connected if there are k disjoint paths in G between any two vertices of G [58]. A cutset in a graph G is a set of minimum number of vertices in G whose removal disconnects G. If G is k-connected, then k is the size of cutset in G (denoted as k(G)). If k(G) = 1, the vertex in the cutset is called a cut vertex. The characterization of K 5 -free segment visibility graphs is based on the property that this class of graphs are not 4-connected graphs (except for one particular segment visibility graph). The only S whose segment visibility graph (say, Gf ) is K5 -free and 4-connected is shown in Figure 6.15(b). We have the following lemmas. Lemma 6.5.2 The graph Gf is the only K5 -free segment visibility graph of S which is 4-connected. Proof. We know from Lemma 6.5.1 that there exists at least an empty convex quadrilateral in S. It means that in a K5 -free segment visibility graph Gs for |S| ≥ 4, there exists a sub-graph H of Gs isomorphic to K4 . If Gs is 4-connected, it follows from Menger’s theorem [58] that for every vertex u of Gs not in H, u is connected to each vertex of H by four disjoint paths in Gs . It means that Gs has K5 as a minor, which is a contradiction. For |S| < 4, the result can be checked by enumeration.
Corollary 6.5.3 The size of a cutset in any K5 -free segment visibility graph except Gf is less than four. Lemma 6.5.4 No K5 -free segment visibility graph of S contains a cut vertex. Proof. Since S can always be triangulated and triangulated graphs are 2-connected, Gs contains no cut vertex.
Lemma 6.5.5 If a segment visibility graph Gs of a set of n disjoint line segments S does not contain K5 as a minor, then at least one endpoint of every segment in S is a vertex of the convex hull of S.
Proof. If S has a segment pq such that neither p nor q is a vertex of the convex hull of S, then by contacting the corresponding edge of pq in Gs , a minor in Gs can be constructed which is K5 , and this is a contradiction.
6.5 Characterizing a Sub-Class of Segment Visibility Graphs
203
In order to recognize a given graph G as a K5 -free segment visibility graph, it can be checked whether G is Gf . If G is isomorphic to Gf , then G is Gs . Otherwise, if k(G) is not 2 or 3, then G is not Gs . We assume from now on that the size of a cutset in G is 2 or 3. We need some more properties of Gs before the edges of G that correspond to segments of S can be identified. We have the following lemma. Lemma 6.5.6 There is a path in a K5 -free segment visibility graph Gs consisting of only the vertices of a cutset in Gs . Exercise 6.5.2 Prove Lemma 6.5.6. Any path that satisfies Lemma 6.5.6 is called a separating path in Gs . We know from Lemma 6.5.5 that one endpoint of every segment in S is a vertex of the convex hull of S. Suppose there is a segment pq in S such that both endpoints p and q are vertices of the convex hull of S. Assume that p and q are not two consecutive vertices on the boundary of the convex hull of S (see Figure 6.15(c)). In such situations, k(Gs ) = 2. In fact, this is the only situation when Gs can have a cutset of size 2 as stated in the following lemma. Lemma 6.5.7 If a cutset consists of two vertices u and v in a K5 -free segment visibility graph Gs of S (Figure 6.15(c)), then u and v correspond to endpoints of the same segment pq in S and p and q are two non-adjacent vertices on the boundary of the convex hull of S. Exercise 6.5.3 Prove Lemma 6.5.7. The above lemma suggests that if the given G has a cutset of size 2, the edge in G connecting these two vertices, which is a separating path in G, corresponds to a segment in S. Remove both vertices of the cutset and all edges incident on these vertices from G. This removal decomposes G into two disjoint components as no vertex of one component is connected by an edge in G to any vertex of other component. Again, if any component has a cutset of size 2, decompose this component again into two components. This process is repeated till the size of a cutset in every component is 3 or all those edges of G, that correspond to segments in S, are identified. The remaining problem is to identify those edges of every component which correspond to segments in S. This can be solved by treating each component as the given graph G having a cutset of size 3. In order to recognize a given graph G, we need a characterization of G s for k(Gs ) = 3. Since a cutset in Gs consists of three vertices, by Lemma 6.5.6 there is a separating path in Gs consisting of these three vertices. It can be seen that this separating path must correspond to a geometric path in S that contains a segment of S. We have the following lemmas on separating paths in Gs .
204
Visibility Graph Theory
Figure 6.16 (a) The ray drawn from p through q intersects a segment of S. (b) A segment visibility graph of a set of vertical segments which is 3-connected and K 5 -free. (c) A planar embedding (up to u4 w4 ) of the graph in the previous figure.
Lemma 6.5.8 If k(Gs ) = 3, then one of the edges in every separating path in Gs corresponds to a segment in S. Proof. Let Q be a separating path consisting of three vertices of a cutset in G s . Let Q0 be the geometric path in S corresponding to Q. Since Q is a separating path in Gs which has connected two non-adjacent vertices on the exterior face of G s , no two endpoints of a segment in S can see each other across Q0 . Therefore, one of the edges in Q0 must be a segment of S. Hence, one of the edges of Q corresponds to a segment of S. Corollary 6.5.9 The geometric path Q0 connects two non-adjacent vertices of the convex hull of S. Lemma 6.5.10 Let pq be a segment in S such that (i) the corresponding edge of pq belongs to a separating path in the segment visibility graph of S which is K 5 -free and 3-connected, and (ii) p is a vertex of the convex hull of S. No segment of S is − intersected by → pq. − Proof. The proof follows from the fact that if → pq intersects any segment in S (see Figure 6.16(a)), the segment visibility graph of S contains K5 as a minor. Exercise 6.5.4 Prove Lemma 6.5.10. The above lemma suggests that segments in S, whose segment visibility graph is K5 -free and 3-connected, can be considered to be vertical segments. Let us consider a class of graphs D such that any graph H in this class can be constructed from a set of edges {u1 w1 , . . . , un wn } as follows (see Figure 6.16(b)). For 1 ≤ i ≤ n, ui and wi are connected in H to ui+1 and wi+1 by four edges forming K4 . Moreover, for
6.6 A Few Properties of Vertex-Edge Visibility Graphs
205
1 ≤ i ≤ n − 1, if ui−1 ui+1 is not an edge of H, ui ui+2 can be an edge in H and if wi−1 wi+1 is not an edge of H, wi wi+2 can be an edge in H. The edges u1 w1 and un wn are called the first and last links of H, respectively. The embedding in Figure 6.16(c) shows that the graph H is a maximal planar graph which corresponds to a triangulation of S. Observe that H is a segment visibility graph, where links in H correspond to vertical segments in S. In fact, every graph in D is a segment visibility graph and its 3-connected components can be embedded similar to Figure 6.16(b). Recall that Gs can be 2-connected but it may have 3-connected components (see Lemma 6.5.7). The embedding of 3-connected components of Gs is essentially unique as long as the extension of any segment in S does not intersect any other segment of S, except may be for the first and last links (see Lemma 6.5.10). We have the following characterization. Theorem 6.5.11 The class of K5 -free segment visibility graph is exactly the class D ∪ {Gf }. Proof. Proof follows from Lemmas 6.5.5, 6.5.7, 6.5.8 and 6.5.10. To recognize a given graph G as a segment visibility graph, which is K5 -free and 3-connected, start from a vertex of G of degree 3 and label link by link using the similar method as stated in the algorithm for recognizing a tower polygon in Section 6.4.2. We have the following theorem. Theorem 6.5.12 A K5 -free segment visibility graph of 2n vertices can be recognized in polynomial time. Exercise 6.5.5 Design an O(n) time algorithm for identifying the links in segment visibility graphs of 2n vertices, which are 3-connected and K5 -free [136].
6.6 A Few Properties of Vertex-Edge Visibility Graphs In this section, we present a few properties of vertex-edge visibility graphs of simple polygons given by O’Rourke and Streinu [275]. We assume that the vertices of a simple polygon P are labeled v1 , v2 , . . . , vn in counterclockwise order, and no three vertices are collinear in P . So, the edges on the boundary of P in counterclockwise order are v1 v2 , v2 v3 , . . . , vn v1 . Let Vv and Ve denote the ordered set of vertices and edges of P in counterclockwise order. The vertex-edge visibility graph G ve of P is a bipartite graph with nodes Vv and Ve , and arcs between vi ∈ Vv and vj vj+1 ∈ Ve if and only if vi is visible from some internal point z of vj vj+1 in P . Note that z is some point of vj vj+1 other that vj and vj+1 . Figure 6.17(a) shows a simple
206
Visibility Graph Theory
Figure 6.17 (a) A simple polygon P . (b) The visibility graph of P . (c) The vertex-edge visibility graph of P .
polygon P , and its visibility graph Gv is shown in Figure 6.17(b). The vertex-edge visibility graph Gve of P is shown in Figure 6.17(c). Given a simple polygon P , Gve of P can be constructed with a little modification of Hershberger’s algorithm [186] for computing the visibility graph Gv of a simple polygon (see Section 5.2). In the sequel, Gv is also referred as a vertex visibility graph. We know that two consecutive vertices vi and vi+1 are mutually visible in P . If vi−1 is not visible in P from any internal point of vi vi+1 , then vi is a reflex vertex in P . Therefore, vi−1 is not connected by an arc to vi vi+1 in Gve . Conversely, if vi−1 is not connected by an arc to vi vi+1 in Gve , then vi is a reflex vertex in P . Thus, the reflex vertices of P can be determined uniquely from Gve . On the other hand, it is not a straightforward task to identify reflex vertices of P from Gv as discussed in Section 6.2.1. It appears that vertex-edge visibility graphs capture more geometric structures of polygons than vertex visibility graphs. In the following lemmas, we establish the relationship between Gv and Gve of the same polygon P . Lemma 6.6.1 If vi is connected by arcs to vj−1 vj and vj vj+1 in Gve , then (vi , vj ) is a visible pair in Gv . Lemma 6.6.2 If (vi , vj ) is a visible pair in Gv , then vi is connected by an arc to vj−1 vj or vj vj+1 (or both) in Gve . Lemma 6.6.3 Assume that vi is connected by arcs to two non-adjacent nodes vj vj+1 and vk vk+1 in Gve and no intermediate node in Gve is connected by an arc to vi . Then, exactly one of Cases A or B holds. Case A: (i) In Gv , (vi , vj+1 ) is a visible pair but not (vi , vk ), and (ii) in Gve , vj+1 is connected to vk vk+1 by an arc but there is no arc connecting vk to vj vj+1 (Figure 6.18(a)).
6.6 A Few Properties of Vertex-Edge Visibility Graphs
207
Figure 6.18 (a) The extension of vi vj+1 from vj+1 meets vk vk+1 . (b) The extension of vi vk from vk meets vj vj+1 . (c) The vertices vj and vk are blocking vertices of invisible pairs (vi , vm ) and (vi , vm+1 ) respectively.
Case B: (i) In Gv , (vi , vk ) is a visible pair but not (vi , vj+1 ), and (ii) in Gve , vk is connected to vj vj+1 by an arc but there is no arc connecting vj+1 to vk vk+1 (Figure 6.18(a)). Corollary 6.6.4 In Gv , vj+1 and vk are the blocking vertices for invisible pairs (vi , vk ) and (vi , vj+1 ) in Case A and Case B, respectively. Exercise 6.6.1 Prove Lemma 6.6.3. The above lemmas can be used to construct Gv from Gve as follows. For each node vi ∈ Vv , consider the nodes Ni in Ve that are connected to vi by arcs in Gve . Consider two nodes vj vj+1 and vk vk+1 consecutive in Ni . If j + 1 = k, then connect vi to vj+1 by an edge in Gv as they are visible in P by Lemma 6.6.1. Otherwise, if Case A (or Case B) of Lemma 6.6.3 is satisfied, then vi is connected to vj+1 (respectively, vk ) by an edge in Gv . We have the following theorem. Theorem 6.6.5 The vertex visibility graph Gv can be constructed from the vertex-edge visibility graph Gve in time proportional to the size of Gve . Using Corollary 6.6.4, the shortest path tree in P rooted at any vertex (say, SP T (vi )) can be constructed from Gve as follows. For details on shortest path trees, see Section 3.6. From a given Gve , locate all vertices of P that are visible from vi using Gv and they are connected to vi as children of vi in SP T (vi ). Recall that Gv can be computed from Gve . Consider two nodes vj and vk of Ni consecutive in the counterclockwise order in Ni . Assume that vk belongs to the counterclockwise boundary of P from vj to vi (see Figure 6.18(c)). If vj and vk are two consecutive
208
Visibility Graph Theory
vertices of P , then vj and vk are leaves of SP T (vi ). Otherwise, test whether vj or vk are blocking vertices using Corollary 6.6.4. If vj is a blocking vertex for an invisible pair, say, (vi , vm ), then we know that vj is the root of the sub-tree of SP T (vi ) in the sub-polygon of P determined by the extension of vi vj from vj to the edge vm vm+1 . Treating vj as the root in this sub-polygon, compute SP T (vj ) recursively. Analogously, if vk is a blocking vertex, compute the sub-tree of SP T (vi ) rooted at vk in the corresponding sub-polygon of P . We have the following theorem. Theorem 6.6.6 Given the vertex-edge visibility graph Gve of a simple polygon P , the shortest path tree from a vertex inside P can be constructed from Gve in time proportional to the size of Gve . The edge-edge visibility graph Ge of P is a graph with nodes Ve , and arcs between nodes vi vi+1 ∈ Ve and vj vj+1 ∈ Ve if and only if some internal point of vi vi+1 is visible from an internal point of vj vj+1 in P . Although Ge is a natural extension of Gve , Ge does not seem to capture more geometric structure of P than Gve . In fact Ge can be constructed from Gve using the following lemma. Lemma 6.6.7 Nodes vi vi+1 and vj vj+1 are connected by an arc in Ge if and only if the shortest paths SP (vi , vj+1 ) and SP (vi+1 , vj ) in P do not share any vertex. The above lemma suggests that Ge can be constructed once the shortest paths between every pair of vertices in P are known. Since they can be computed from G ve using Theorem 6.6.6, Ge can be constructed from Gve . Using the method similar to the method of constructing Gv from Gve stated earlier in this section, Gve can also be constructed from Ge . So, it may be concluded that Gve and Ge are equivalent.
6.7 Computing Maximum Clique in a Visibility Graph In this section, we present the algorithm of Ghosh et al. [167] for computing the maximum clique in the visibility graph G of a simple polygon P in (n2 E) time, where n and E are the number of vertices and edges of G, respectively. The algorithm assumes that G is given along with the Hamiltonian cycle C, where C corresponds to the boundary of P . The maximum clique in G is a complete sub-graph of G with the largest number of vertices. For example, the maximum clique in G shown in Figure 6.19(a) consists of vertices v1 , v3 , v5 , v6 , v7 , v8 , v9 and v10 . There may be two or more maximum cliques in G with the same number of vertices. We are interested in locating any one of them. Observe that the maximum clique in G corresponds to a convex polygon inside P formed by the largest number of vertices (see Figure 6.19(b)).
6.7 Computing Maximum Clique in a Visibility Graph
209
Figure 6.19 (a) The maximum clique in G consists of vertices v1 , v3 , v5 , v6 , v7 , v8 , v9 and v10 . (b) The vertices forming the largest convex polygon in P are the vertices of the maximum clique in the visibility graph of P .
Exercise 6.7.1 Let S be a set of n points in the plane. Design an O(n3 ) time algorithm for computing the largest subset S 0 of S such that points in S 0 form a convex polygon Q with no point of S − S 0 lying inside Q [40]. Assume that the vertices of C are labeled v1 , v2 , . . . , vn in counterclockwise order. Let C(vj , vm ) denote the portion of C from vj to vm in counterclockwise order. For each vertex vi ∈ G, Gi denotes the induced sub-graph of G formed by vi with its neighboring vertices in G. In Figure 6.19(a), G3 is the entire visibility graph since all vertices of the graph are neighbors of v3 . The sub-polygon of P formed by the vertices of Gi is called the fan Fi with vi as the fan vertex. The fan Fi is referred as convex fan if the internal angle at vi is convex in Fi . It can be seen that the order of vertices on the boundary of Fi follows the order in C. Observe that if the maximum clique in G contains a vertex vi , then all vertices of the maximum clique belong to Gi as they are neighbors of vi in G. Using this observation, the algorithm first computes maximum cliques in G1 , G2 , . . . , Gn and then takes the clique with the largest size as the maximum clique in G. So, it is enough to present the procedure for computing the maximum clique in Gi . Without loss of generality, we assume that all vertices of G are neighbors of v i . This assumption implies that Fi is P and therefore, the angular order of vertices around vi in Fi is same as the order of vertices in C. For any edge (vp , vq ) ∈ Gi , if there exists an edge (vk , vm ) in Gi such that vk ∈ C(vp+1 , vq−1 ) and vm ∈ C(vq+1 , vp−1 ), we say that there is a cross-visibility across (vp , vq ) [154, 157]. For any vertex vj , if there is no cross-visibility across (vi , vj ) (see Figure 6.20(a)), then all vertices of the maximum clique in Gi belong to either C(vi , vj ) or C(vj , vi ). So, Gi can be partitioned into two induced sub-graphs formed by vertices of C(vi , vj ) and
210
Visibility Graph Theory
Figure 6.20 (a) There is no cross-visibility across (vi , vj ) as well as across (vi , vp ). (b) The vertex vj is the sole blocking vertex for (vj−1 , vj+1 ).
C(vj , vi ). So, the maximum clique in Gi can be computed by computing maximum cliques in these two sub-graphs. Let vp be a vertex of C(vj , vi ). Again, if there is no cross-visibility across (vi , vp ) (see Figure 6.20(a)), then the induced sub-graph formed by vertices of C(vj , vi ) can again be partitioned into two sub-graphs as stated earlier. This process of partitioning sub-graphs continues till no further partition is possible. We have the following lemmas. Lemma 6.7.1 The graph Gi can be partitioned into sub-graphs using the criteria of cross-visibility such that one of them totally contains the maximum clique in G i . Corollary 6.7.2 There can be at most one sub-graph of Gi whose corresponding fan is not a convex fan. Proof. Since the edges used for partitioning Gi are all incident at vi , these edges divide the reflex angle at vi in Fi . After the division, only one of them can be reflex at vi . Hence, there can be at most one sub-graph of Gi after partition whose corresponding fan is not a convex fan. Lemma 6.7.3 All edges of Gi used for partitioning Gi can be located in O(E) time. Exercise 6.7.2 Prove Lemma 6.7.3. Without loss of generality, we assume that there is a cross-visibility across (v i , vj ) in Gi for every vj ∈ C(vi+2 , vi−2 ). If (vj−1 , vj+1 ) is an edge in Gi , then vj is a convex vertex in Fi . If (vj−1 , vj+1 ) is not an edge in Gi (see Figure 6.20(b)), vj is a blocking vertex for (vj−1 , vj+1 ). For properties of blocking vertices, see Section 6.2.1. The vertex vi is the only other blocking vertex for (vj−1 , vj+1 ) as (vi , vj−1 ) and (vi , vj+1 )
6.7 Computing Maximum Clique in a Visibility Graph
211
are edges in Gi (see Figure 6.20(a)). If vi is used to block the visibility between vj−1 and vj+1 in Fi , then there is no cross-visibility across (vi , vj ) contradicting the assumption that there is a cross-visibility across (vi , vj ) (see Figure 6.20(a)). Therefore, vj must be a reflex vertex in Fi (see Figure 6.20(b)). We state this observation in the following lemma. Lemma 6.7.4 If (vj−1 , vj+1 ) is not an edge in Gi but cross-visibility exists across (vi , vj ), then vj must be a reflex vertex in Fi . By traversing C once, all reflex vertices of Fi can be identified using the above lemma. For computing the maximum clique in Gi , the algorithm needs the property that vi is a convex vertex in Fi . If (vi−1 , vi+1 ) is not an edge in Gi , then vi is not a convex vertex in Fi and there is no clique in Gi with vertices vi−1 and vi+1 . So, subgraphs of Gi are constructed in such way that their corresponding fans are convex fans as follows (see Figure 6.21(a)). Let (vi+1 , vk ) be the edge in Gi such that no vertex of C(vk+1 , vi−1 ) is a neighbor of vi+1 . The vertex vk is called the furthest adjacent vertex of vi+1 . It can be seen that the corresponding fan of the induced sub-graph of Gi formed by vi with vertices of C(vi+1 , vk ) is a convex fan. Let vm be the first vertex of C in counterclockwise order from vi+1 such that vi−1 is the furthest adjacent vertex of vm . Using the furthest adjacent vertices of vi+2 , . . . , vm as stated earlier, the corresponding sub-graphs of Gi are constructed, and they are visibility graphs of convex fans. Since the maximum clique in Gi belongs to one of these sub-graphs, the maximum clique is computed by computing maximum cliques in these sub-graphs of Gi . From now on, we assume that vi is a convex vertex in Fi , i.e., (vi−1 , vi+1 ) is an edge in Gi . Let (vk , vl ) and (vp , vk ) be two edges of Gi such that vp ∈ C(vi , vk−1 ) and vl ∈ C(vk+1 , vi−1 ). We know that the three vertices vl , vk and vp belong to a clique in Gi if and only if (vl , vp ) is an edge in Gi . All pairs of such edges (vk , vl ) and (vp , vk ) satisfying this property are called valid pairs of edges at vk . So, every valid pair of edges at any vertex vk ∈ C(vi+1 , vi−1 ) forms a clique of three vertices in Gi . The edge (vp , vk ) is called an incoming edge of vk and the other edge (vk , vl ) is called an outgoing edge of vk . Note that any edge is an incoming edge of one vertex and an outgoing edge of the other vertex. We have the following lemma on valid pairs of edges in Gi . Lemma 6.7.5 If an outgoing edge (vk , vl ) at vk forms a valid pair with an incoming edge (vp , vk ) at vk , then for every incoming edge (vq , vk ) at vk , where vq ∈ C(vi , vp ), (vk , vl ) forms a valid pair with (vq , vk ) at vk . Proof. Since (vk , vl ) has formed a valid pair with (vp , vk ), the internal angle at vk in Fi (say, α) formed by (vk , vl ) and (vp , vk ) is convex. Since any incoming edge (vq , vk ) divides α in Fi , the internal angle at vk in Fi formed by (vk , vl ) and (vq , vk )
212
Visibility Graph Theory
Figure 6.21 (a) The vertices vk and vi−1 are the furthest adjacent vertices of vi+1 and vm , respectively. (b) Weights are assigned to the outgoing edges at vi , vi+1 , . . . , vk .
is also convex. So, (vl , vq ) must be an edge in Gi as vl and vq are visible in Fi . Therefore, (vk , vl ) forms a valid pair with (vq , vk ) at vk . Using valid pairs of edges, weights are assigned to edges of Gi for computing the maximum clique in Gi . The weight of 2 is assigned to edges (vi , vi+1 ), (vi , vi+2 ), . . . (vi , vi−2 ). Consider vi+1 . Since (vi , vi+1 ) is the only incoming edge at vi+1 and all vertices of Gi are connected to vi (see Figure 6.21(b)), (vi , vi+1 ) forms a valid pair with every outgoing edge at vi+1 . Assign the weight of 3, which is the size of the clique, to every outgoing edge at vi+1 . For the next vertex vi+2 , (vi , vi+2 ) and (vi+1 , vi+2 ) are incoming edges at vi+2 and each of them forms a valid pair with every outgoing edge at vi+2 . Therefore, assign the weight of 4, which is the size of the clique, to every outgoing edge at vi+2 . Note that the weight of 4 is obtained by adding one to the maximum among weights of incoming edges at vi+2 . Consider any vertex vk (see Figure 6.21(b)). Assume that the weight on every incoming edge at vk has already been assigned. For every outgoing edge (vk , vl ) at vk , find the maximum among weights on those incoming edges at vk that have formed valid pairs with (vk , vl ), add one to the maximum weight, and assign the weight to (vk , vl ). In this method, weights on all outgoing edges at vk are assigned. By traversing C(vi+1 , vi−1 ) in counterclockwise order, weights are assigned to all edges in Gi . We have the following lemma. Lemma 6.7.6 The size of the maximum clique in Gi is the same as the largest weight among weights on edges of Gi . Exercise 6.7.3 Prove Lemma 6.7.6.
6.7 Computing Maximum Clique in a Visibility Graph
213
Let (vk , vl ) be an edge in Gi with the maximum weight. Starting from (vk , vl ), all vertices of the maximum clique in Gi can be located by traversing backward as follows. Without loss of generality, (vk , vl ) is considered as an outgoing edge at vk . Let M C denote the ordered set of vertices of the maximum clique in Gi from vl to vi . Initialize M C by adding vl and vk to M C. Locate an incoming edge at vk (say, (vp , vk )) such that (vk , vl ) has formed a valid pair with (vp , vk ) at vk , and the weight on (vp , vk ) is one less than that of (vk , vl ). Add vp to M C as it is the next vertex of vk in M C. In the same way, the next vertex of vp in M C can again be found by locating an appropriate incoming edge at vp . The process is repeated till vi is added to M C. Thus all vertices of M C can be located using weights on edges of Gi and valid pairs of edges in Gi . We have the following lemma.
Exercise 6.7.4 Write the procedure for locating the maximum clique in the visibility graph Gi of a convex fan Fi under the assumption that there exists cross-visibility across every edge connecting a vertex of C(vi+2 , vi−2 ) to the fan vertex vi .
Lemma 6.7.7 The vertices of the maximum clique M C in Gi can be located O(E) time. Proof. We first show that the time complexity of assigning weights to all outgoing edges at any vertex vk is proportional to the degree of vk . Assume that the weight on every incoming edge at vk has already been assigned. Consider the outgoing edges at vk in counterclockwise order starting from (vk , vk+1 ). Also consider the incoming edges of vk in counterclockwise order starting from (vi , vk ). Consider the first outgoing edge (vk , vk+1 ). Let (vp , vk ) be the incoming edge of vk such that (vp , vk+1 ) is an edge in Gi but the next incoming edge of vk does not form a valid pair with (vk , vk+1 ). While considering incoming edges of vk from (vi , vk ) to (vp , vk ), the procedure can compute the maximum among weights on these edges, which gives the weight of (vk , vk+1 ). For assigning the weight on the next outgoing edge of (vk , vk+1 ), it is enough to consider the incoming edges of vk from (vp , vk ) rather than from (vi , vk ) (see Lemma 6.7.5). In this process, weights on all outgoing edges of vk can be computed in time proportional to the degree of vk . Therefore, assigning weights to all outgoing edges at vk for all k takes O(E) time. Since vertices of M C can also be located in O(E) time by scanning backward starting from an edge of G i with maximum weight, the maximum clique M C in Gi can be computed in O(E) time. In the following, we state the major steps for locating the vertices of the maximum clique in the given visibility graph G.
214
Visibility Graph Theory
Step 1. Construct G1 , G2 , . . . , Gn from G. Step 2. Initialize the set S to empty. For every graph Gi , partition Gi into subgraphs using cross-visibility and add them to S. Step 3. For every sub-graph Q in S, if Q is not the visibility graph of a convex fan then decompose Q into visibility graphs of convex fans and replace Q by these decomposed sub-graphs in S. Step 4. For each sub-graph Q of S, assign weights on edges of Q using valid pairs of edges and locate the vertices of the maximum clique in Q from the weighted sub-graph Q. Step 5. Choose the largest clique among the maximum cliques in sub-graphs of S and assign the clique as the maximum clique in G. Step 6. Output the maximum clique in G and Stop. The correctness of the algorithm follows from Lemmas 6.7.1, 6.7.4, 6.7.5 and 6.7.6. Let us analyze the time complexity of the algorithm. Step 1 takes O(nE) time as each sub-graph can be constructed in O(E) time. By Lemma 6.7.3, Gi can be partitioned in O(E) time and therefore, partitioning G1 , G2 , . . . , Gn in Step 2 takes O(nE) time. After the decomposition in Step 3, there can be at most O(n 2 ) sub-graphs in S due to Corollary 6.7.2. So, Step 3 can be executed in O(n2 E) time. By Lemma 6.7.7, the maximum clique in a sub-graph of S can be computed in O(E) time and there are O(n2 ) sub-graphs in S. So, Step 4 takes O(n2 E) time. Hence, the overall time complexity of the algorithm is O(n2 E). We summarize the result in the following theorem. Theorem 6.7.8 Assume that the visibility graph G of a simple polygon is given along with the Hamiltonian cycle in G corresponding to the boundary of the polygon. The maximum clique in G can be computed in O(n2 E) time, where n and E denote the number of vertices and edges of G.
6.8 Computing Maximum Hidden Vertex Set in a Visibility Graph In this section, we present an O(nE) time algorithm given by Ghosh et al. [167] for computing the maximum hidden vertex set in the visibility graph G of a convex fan F , where n and E denote the number of vertices and edges of G. A maximum hidden vertex set in G is the set of maximum number of vertices in which no two vertices are neighbors in G. Assume that the Hamiltonian cycle C in G corresponding to the boundary of F is given along with G. We also assume that the vertices of C are labeled v1 , v2 , . . . , vn in counterclockwise order. Let vi be a vertex of G such that all vertices G are neighbors of vi , and (vi−1 , vi+1 ) is an edge in G. We take vi as the fan vertex of F .
6.8 Computing Maximum Hidden Vertex Set in a Visibility Graph
215
Figure 6.22 (a) The vertex vm is the next vertex of vk in the Euclidean shortest path between vj and vk in F . (b) The vertex vi is placed either at ui or wi to construct convex fans with v1 as the fan vertex.
Recall that for any two vertices vj and vk , C(vj , vk ) denotes the portion of C in counterclockwise order from vj to vk . Assume that vj ∈ C(vi , vk ). If (vj , vk ) ∈ G, then both vj and vk cannot be in a hidden vertex set in G. If (vj , vk ) is not an edge in G, then both vj and vk can be in a hidden vertex set in G. Suppose, there exists a vertex vm ∈ C(vj , vk ) such that (vk , vm ) ∈ G and no vertex of C(vj , vm−1 ) is a neighbor of vk in G. This implies that the the Euclidean shortest path between vj and vk in F passes through vm , and vm is the next vertex of vk in the path (see Figure 6.22(a)). Using this property, the maximum hidden vertex set in C(vj , vk ) (denoted as H(vj , vk )) can be located by the following lemma of Ghosh et al. [163] (after a minor modification). Let |H(vj , vk )| denote the number of vertices of H(vj , vk ). Lemma 6.8.1 For any two vertices vj and vk of G where vk ∈ C(vj , vi−1 ), |H(vj , vk )| = max(|H(vj , vm−1 )| + |H(vm+1 , vk )|, |H(vj , vk−1 )|), where (vm , vk ) ∈ G and no vertex of C(vj , vm−1 ) is a neighbor of vk in G. Proof. If vk does not belong to H(vj , vk ), then H(vj , vk ) = H(vj , vk−1 ). If vk ∈ H(vj , vk ), then H(vj , vk ) does not contain vm as (vk , vm ) ∈ G. Since no vertex of C(vj , vm−1 ) is a neighbor of any vertex of C(vm+1 , vk ) in G, H(vj , vk ) = H(vj , vm−1 ) ∪ H(vm+1 , vk ). So, |H(vj , vk )| = max(|H(vj , vm−1 )| + |H(vm+1 , vk )|, |H(vj , vk−1 )|). Using the above lemma, |H(vj , vk )| can be computed for all pairs of vj and vk in C(vi+1 , vi−1 ). Let |H(vp , vq )| be the largest in G for some pair of vertices vp and vq . Vertices in H(vp , vq ) are located by scanning C in clockwise order from vq to vp . The overall time complexity of the algorithm is O(nE) as the algorithm takes O(E) time for every vertex vj . We summarize the result in the following theorem.
216
Visibility Graph Theory
Figure 6.23 Two simple polygons are not similar but their visibility graphs are isomorphic.
Theorem 6.8.2 Assume that the visibility graph G of a convex fan is given along with the Hamiltonian cycle in G corresponding to the boundary of the fan. The maximum hidden vertex set in G can be computed in O(nE) time, where n and E denote the number of vertices and edges of G. Exercise 6.8.1 Design an O(n2 ) time algorithm for computing the maximum hidden vertex set in a simple polygon P of n vertices, where P is weakly visible from one of its convex edges [163].
6.9 Notes and Comments In Section 6.7, it was shown that the problem of computing the maximum clique in a visibility graph G can be solved in polynomial time. However, the algorithm needs an additional input in the form of a Hamiltonian cycle. Can this problem be solved in polynomial time without any additional information? The algorithm presented in Section 6.8 is for computing the maximum hidden vertex set in the visibility graph of a very special class of polygons. Can this problem be solved for the visibility graph G of other classes of simple polygons in polynomial time if the Hamiltonian cycle in G corresponding to the boundary of the polygon is given along with G? Two graphs G1 = (V1 , E1 ) and G2 = (V2 , E2 ) are isomorphic if and only if there is a bijection f that maps vertices of V1 to vertices of V2 such that an edge (u, w) ∈ E1 if and only if the edge (f (u), f (w)) ∈ E2 . We show that the number of non-isomorphic visibility graphs of simple polygons of n vertices can be exponential. Construct convex fans of n vertices v1 , v2 . . . vn (in counterclockwise order) with v1 as the fan vertex as follows (see Figure 6.22(b)). Let u2 , u3 , u4 , . . . un be a convex chain of points in counterclockwise order. Mark u2 and un as v2 and vn , respectively. Connect v1 with v2 by an edge. Similarly, connect v1 with vn by an edge. For all i between 3 and n − 1, take a point wi on the segment vi ui such that w3 , w4 , . . . wn−1 form a chain of reflex points facing v1 . For every vertex vi of 2 < i < n, place vi
6.9 Notes and Comments
217
either at ui or wi and connect vi to vi−1 by an edge. Finally, connect vn to vn−1 by an edge to complete the construction of the fan. So, the number of convex fans that can be constructed in this way by all possible combinations of two positions of v3 , v4 . . . vn−1 is 2n−3 . However, the visibility graph of each fan in this family of 2n−3 fans is isomorphic to the visibility graph of one other fan in the family due to symmetry. Therefore, there are 2n−4 convex fans in this family that have non-isomorphic visibility graphs. We have the following lemma. Lemma 6.9.1 The number of non-isomorphic visibility graphs of simple polygons of n vertices is at least 2n−4 . Let G1 and G2 be the visibility graphs of simple polygons P1 and P2 , respectively. Let C1 (or C2 ) denote the Hamiltonian cycles in G1 (respectively, G2 ) that corresponds to the boundary of P1 (respectively, P2 ). Polygons P1 and P2 are called similar if and only if there is a bijection f that maps adjacent vertices on the boundary of P1 to that of boundary of P2 such that f (G1 ) = G2 [244]. It has been shown by Avis and ElGindy [39] that the similarity of P1 and P2 of n vertices can be determined in O(n2 ) time. Therefore, given G1 and G2 along with C1 and C2 , the corresponding visibility graphs similarity problem can also be solved in O(n2 ) time. It can be seen that the two simple polygons in Figure 6.23 are not similar but their visibility graphs are isomorphic. We have the following observation from Lin and Skiena [244]. Lemma 6.9.2 Two simple polygons with isomorphic visibility graphs may not be similar polygons. Exercise 6.9.1 Let S be a set of n disjoint line segments in the plane such that one endpoint of every segment of S belongs to the convex hull of S. Design an O(n log n) time algorithm for computing a simple polygon P (if it exists) such that all segments of S appear as edges of P and the remaining edges of P are visible segments between the endpoints of S [293].
7 Visibility and Link Paths
7.1 Problems and Results Assume that a point-robot moves in straight-line paths inside a polygonal region P . Every time it has to change its direction of the path, it stops and rotates until it directs itself to the new direction. In the process, it makes several turns before reaching its destination. If straight line motions are ‘cheap’ but rotations are ‘expensive’, minimizing the number of turns reduces the cost of the motion although it may increase the length of the path. This motivates the study of link paths inside a polygonal region P . For more details on applications of such paths, see the review article of Maheshwari et al. [253]. A link path between two points s and t of a polygon P (with or without holes) is a path inside P that connects s and t by a chain of line segments (called links). A minimum link path between s and t is a link path connecting s and t that has the minimum number of links (see Figure 7.1). Observe that there may be several link paths between s and t with the minimum number of links. The link distance between any two points of P is the number of links in the minimum link path between them. The problem of computing the minimum link path between any two points inside a simple polygon were first studied by ElGindy [126] and Suri [318]. Using weak visibility, Suri gave an O(n) time algorithm for this problem [318, 319] which we present in Section 7.2.1. Using a different method involving complete visibility, Ghosh [155, 156] later gave an alternative algorithm for this problem which also runs in O(n) time. In Section 7.2.2, we present Ghosh’s algorithm. One of the steps of Ghosh’s algorithm was simplified by Hershberger and Snoeyink [188] and this is also presented in Section 7.2.2. For this problem in a polygon with holes, Mitchell et al. [262] gave an algorithm that runs in O(Eα(n) log 2 n) time and O(E) space, where E is the number of edges in the visibility graph of the polygon and α(n) is the inverse Ackermann function. We present their algorithm in Section 7.3. Suri [318, 319] showed that minimum link paths from a point s to all vertices of a simple polygon can also be computed in O(n) time. For this problem in a 218
7.1 Problems and Results
219
Figure 7.1 A minimum link path and the Euclidean shortest path between two points s and t are shown (a) inside a simple polygon and (b) inside a polygon with holes.
polygon with holes, Mitchell et al. [262] presented an algorithm that runs in O((E + ln)2/3 n2/3 l1/3 log3.11 n + E log3 n) time and O(E) space, where l is the length of the longest link path from s to any vertex of the polygon. The link diameter of a simple polygon P is the maximum link distance between any two points inside P . The link distance between s and t in Figure 7.1(a) is the link diameter of the polygon. Since there always exists a pair of vertices in P such that their link distance is the diameter of P , the link diameter of P can be computed in O(n2 ) time by computing minimum link paths in O(n) time from each vertex to all other vertices of P . Using an involved method, Suri [319] showed that the link diameter of P can be computed in O(n log n) time. Suri [320] also presented an algorithm for computing an approximate link diameter of P which can be less than the link diameter of P by at most two links. Consider any point w inside P . Let rw denote the maximum among link distances between w and any point of P . For every other point u in P , if ru ≥ rw , then rw is called the link radius of P . The set of all such points w in P is called the link center of P . Lenhart et al. [241] gave an O(n2 ) time algorithm for computing the link center and link radius of P . We present their algorithm in Section 7.4. Consider the problem of locating a diagonal vi vj in a triangulation of P such that the maximum link distance from vi vj to any point of P is minimized. Note that vi vj may not always intersect the link center of P . However, it lies very close to the link center of P . Using a central diagonal of P , Djidjev et al. [111] showed that the link center and link radius of P can be computed in O(n log n) time. It is still open whether the link center of P can be computed in O(n) time. A simple polygon P is said to be k-visible if there exists a segment st inside P such that the link distance from each point on st to any point of P is at most k.
220
Visibility and Link Paths
The problem of locating such a segment st inside P for the smallest k is called the k-visibility problem. With the help of a central diagonal of P and the link center of P , this problem can be solved in O(n log n) time by the algorithm of Aleksandrov et al. [16]. Link paths have been used to solve minimum nested polygon problems. A polygon K is called nested between two given simple polygons P and Q, where Q ⊂ P , when it circumscribes Q and is inscribed in P (i.e. Q ⊂ K ⊂ P ). The problem here is to compute a nested polygon K with the minimum number of vertices. If both P and Q are convex, Aggarwal et al. [12] gave an O(n log k) algorithm for computing a minimum nested polygon K, where n is the total number of vertices of P and Q, and k is the number of vertices of K. We present their algorithm in Section 7.5.1. If P or Q is not convex, K can still be a convex polygon. Ghosh [155] presented an O(n) time algorithm to determine whether K is a convex polygon. When K is a convex polygon, Wang [336] and Wang and Chan [337] showed that the algorithm of Aggarwal et al. [12] can be used to compute K after pruning some regions of P ; they presented an O(n log n) algorithm for pruning P . Using the notion of complete visibility, Ghosh [155] showed that the pruning of P can be done in O(n) time and therefore, a minimum nested convex polygon K can be computed in O(n log k) time. If K is not a convex polygon, Ghosh and Maheshwari [159] presented an O(n) time for computing such K. We present their algorithm in Section 7.5.2 along with the algorithm of Ghosh [155] for determining whether K is a non-convex polygon. For special classes of polygons, Dasgupta and Veni Madhavan [104] presented approximation algorithms for computing nested polygons. Bhadury et al. [46] studied the problem of computing nested polygons in the context of art gallery problems. Alsuwaiyel and Lee [17] proved that the problem of computing a minimum link path between a pair of points inside a simple polygon such that the entire polygon is weakly visible from the link path is NP-hard. They gave an O(n2 ) time approximation algorithm for this problem and the link path computed by the approximation algorithm is at most thrice the optimal. Alsuwaiyel and Lee [18] also gave approximation algorithms for a minimum link path watchman route in simple polygons. This problem for a polygon with holes has been studied by Arkin et al. [22]. A watchman route in a polygon is a polygonal path such the every point of the polygon is visible from some point on the path. Guibas et al. [179] studied the problem of simplifying a polygon or polygonal subdivision using the minimum number of links. They showed that approximating subdivisions and approximating with simple chains are NP-hard. They also suggested approximation algorithms for some variation of the problem. Link paths of a given homotopy class were studied by Hershberger and Snoeyink [188]. Two link paths between the same pair of points are said to be homotopic if there is a continuous function that maps one path to the other. The problem
7.2 Computing Minimum Link Paths in Simple Polygons
221
of minimizing both the length and the number of links in a path was studied by Arkin et al. [23] and Mitchell et al. [261]. Kahan and Snoeyink [206] studied the bit complexity of link distance problems for a computational model with finite precision arithmetic. Link path problems have also been studied for rectilinear polygons. A polygon P is said to be rectilinear if the edges of P are aligned with a pair of orthogonal coordinate axes. In other words, P is a rectilinear polygon if the internal angle at every vertex of P is 90◦ or 270◦ . Link paths in a rectilinear polygon P are rectilinear paths as the links in the path are parallel to edges of P . De Berg [108] presented an O(n) time algorithm for computing a minimum rectilinear link path between any two points in a rectilinear polygon P without holes. He also showed that the rectilinear link diameter of P can be computed in O(n log n) time. Later, Nilsson and Schuierer [267] presented an O(n) time algorithm for this problem. Nilsson and Schuierer [268] also presented an O(n) time algorithm for computing the rectilinear link center of P . Das and Narasimhan [102] presented an O(n log n) time algorithm for computing a minimum rectilinear link path between any two points in a polygon with rectilinear holes. Maheshwari and Sack [252] gave O(n) time algorithms for nested polygon problems in rectilinear polygons. The problem of computing a watchman tour in rectilinear polygons was studied by Kranakis et al. [222]. Rectilinear polygons can be viewed as a special case of c-oriented polygons, where edges are parallel to a fixed set of c orientations. Link paths in c-oriented polygons were studied by Hershberger and Snoeyink [188] and Adegeest et al. [5].
7.2 Computing Minimum Link Paths in Simple Polygons 7.2.1 Using Weak Visibility: O(n) Algorithm In this section, we present an O(n) time algorithm of Suri [318] for computing a minimum link path between two given points s and t inside a simple polygon P . We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. Let M LP (s, t) denote a minimum link path between s and t in P . Exercise 7.2.1 Let s and t be two points inside a simple polygon P of n vertices. Let u1 and d1 be the boundary points of P such that the segment u1 d1 lies inside P . Cut P into two sub-polygons using u1 d1 . Design an O(n) time algorithm to determine whether s and t belong to the same or different sub-polygons of P . Compute the visibility polygon V (s) of P from s by the algorithm of Lee [230] (see Section 2.2.1). It can be seen that V (s) is the set of all points of P that can be reached by one link from s (see Figure 7.2). If t ∈ V (s), then the segment st is the
222
Visibility and Link Paths
Figure 7.2 Every M LP (s, t) intersects u1 d1 , u2 d2 and u3 d3 , which are constructed edges of visibility polygons R1 , R2 and R3 , respectively.
minimum link path from s to t. Let us denote the region V (s) as R1 and P as P0 . We have the following lemma. Lemma 7.2.1 The visibility polygon of P0 from s is the set R1 of all points of P0 that can be reached from s by one link. Consider the other situation when t cannot be reached from s by one link. Since t ∈ P0 − R1 , every M LP (s, t) must intersect a constructed edge of R1 in order to reach t. In fact, every M LP (s, t) intersects the same constructed edge (say, u 1 d1 ) of R1 (see Figure 7.2), as P is a closed and bounded region. However, they intersect at different points of u1 d1 . We have the following lemma. Lemma 7.2.2 There exists a M LP (s, t) such that the first turning point of the M LP (s, t) lies on the constructed edge u1 d1 . Proof. Consider any M LP (s, t). Let w1 be the point of intersection of u1 d1 and M LP (s, t). So, the path of M LP (s, t) between s and w1 can be replaced by the link sw1 to construct another M LP (s, t) whose first turning point is w1 . Let us identify the constructed edge u1 d1 among all constructed edges of R1 . Remove R1 from P0 and it splits P0 into sub-polygons. Identify the sub-polygon (say, P1 ) containing t. So, the constructed edge of R1 , which is on the boundary of P1 , is u1 d1 . The problem is now to locate the first turning point w1 on u1 d1 . Let us compute the set of all points R2 of P1 that can be reached from s by two links (see Figure 7.2). In other words, R2 is the set of all points of P1 that can be reached by one link from some point of u1 d1 . It can be seen that R2 is the weak visibility polygon
7.2 Computing Minimum Link Paths in Simple Polygons
223
of P1 from u1 d1 . Compute R2 . If t ∈ R2 , take any point on u1 d1 as w1 such that tw1 is a link lying inside R2 . So, M LP (s, t) consists of sw1 and w1 t. Otherwise, remove R2 from P1 . Again, P1 splits into sub-polygons and one of the sub-polygons of P1 (say, P2 ) contains t. Let u2 d2 be the constructed edge of R2 such that it is an edge on the boundary of P2 . This process of locating Pi and computing Ri+1 from the constructed edge ui di continues until t becomes visible from um−1 dm−1 , where m is the link distance between s and t. We state the above facts in the following lemmas. Lemma 7.2.3 Let ui di be the constructed edge of Ri such that after removing Ri from Pi−1 , ui di is an edge on the boundary of the sub-polygon Pi containing t. For 1 ≤ i < m, every M LP (s, t) intersects ui di and there exists a M LP (s, t) whose i-th turning point lies on ui di . Lemma 7.2.4 For 1 ≤ i < m, the set of all points Ri+1 of Pi that can be reached from s by i + 1 links is the weak visibility polygon of Pi from ui di . Based on the above lemmas, we present the major steps of the algorithm for computing M LP (s, t) in P0 . The index i is initialized to 1. Step 1. Compute the visibility polygon Ri of Pi−1 from s. If t is visible from s, then report st as M LP (s, t) and goto Step 6. Step 2. Locate the sub-polygon of Pi−1 containing t and call it Pi . Locate the constructed edge of Ri on the boundary of Pi and call it ui di . −−→ Step 3. If i > 1 then assign the intersection point of ui−1 di−1 and di ui to wi−1 . Step 4. Compute the weak visibility polygon Ri+1 of Pi from ui di . If t is not visible from ui di then i := i + 1 and goto Step 2. Step 5. Locate a point wi ∈ V (t) on ui di and report M LP (s, t) = (sw1 , w1 w2 , . . . , wi t). Step 6. Stop.
Correctness of the algorithm follows from Lemmas 7.2.1, 7.2.2, 7.2.3 and 7.2.4. Let us analyze the time complexity of the algorithm. Using the algorithm of Lee [230] (see Section 2.2.1), the visibility polygons from s in Step 1 can be computed in O(n) time. Let us explain how to locate Pi in Step 2. Let ud be any constructed edge of Ri . We know that one of the endpoints of every constructed edge is a vertex of P . Without loss of generality, we assume that u is a vertex vj of P . Let vk vk+1 be the edge of P such that d ∈ vk vk+1 . Let vp be a vertex visible from t, i.e., vp ∈ V (t). If ud intersects tvp , the intersection point becomes wi . Otherwise, by comparing j, k, p, the portion of the boundary of Pi−1 forming the boundary of Pi can be determined. Once Pi is known, the constructed edge of Ri associated with Pi becomes ui di . Therefore, by spending O(1) time for each constructed edge of Ri , ui di can be located. Since there can be only one constructed edge for every reflex
224
Visibility and Link Paths
vertex of P , Step 2 can be executed in O(n) time. The running time of Step 4 is O(n) as each visibility polygon Ri+1 from ui di can be computed in time proportional to the number of vertices of Ri+1 as follows. Compute the shortest path tree SP T (s) in P0 rooted at s in O(n) time by the algorithm of Guibas et al. [178] (see Section 3.6.1) and then compute the shortest path map SP M (s) in O(n) time by the algorithm of Hershberger [186] (see Section 5.2). It can be seen that vertices of R1 are children of s in SP T (s) and u1 d1 is an extension edge of SP M (s). Assume that u1 is a vertex of P0 and d1 is a point on the boundary of P0 . Take the sub-tree SP T (u1 ) of SP T (s) rooted at u1 and compute SP T (d1 ) by shifting the root from u1 to d1 as in the algorithm of Hershberger [186]. It follows from Lemma 5.2.1 that vertices of R2 are only those vertices of P1 whose parents in SP T (u1 ) and SP T (d1 ) are different. Since SP T (u1 ) and SP T (d1 ) are the same in R3 , R4 , . . . , Rm−1 , the time taken for locating vertices of R2 is proportional to the number of vertices of R2 . Compute SP M (d1 ). It follows from Lemma 5.2.2 that constructed edges of R2 are extension edges of SP M (u1 ) and SP M (d1 ). Repeating this process of computations for u2 d2 , u3 d3 , . . . um−1 dm−1 , weak visibility polygons R3 , R4 , . . . , Rm−1 can be computed in a total time of O(n). Note that whether or not t belongs to Ri+1 can be determined in time proportional to the size of Ri+1 . Hence the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 7.2.5 A minimum link path between two given points inside a simple polygon of n vertices can be computed in O(n) time. Exercise 7.2.2 Design an O(n) time algorithm for computing minimum link paths from a given point inside a simple polygon P to all vertices of P [318, 319].
7.2.2 Using Complete Visibility: O(n) Algorithm In this section, we present an alternative algorithm given by Ghosh [155, 156] for computing a minimum link path in O(n) time between two given points s and t inside a simple polygon P . While presenting this algorithm, we also present the simplification suggested by Hershberger and Snoeyink [188] for one of the steps of Ghosh’s algorithm. Let SP (s, t) = (s, u1 , ..., uk , t). We know that SP (s, t) can be computed in O(n) time by the algorithm of Lee and Preparata [235] (see Section 3.6.1), once P is triangulated in O(n) time by the algorithm of Chazelle [71] (see Theorem 1.4.6). From now on, we assume that P is given along with a triangulation of P . An edge uj uj−1 of SP (s, t) is called eave if uj−2 and uj+1 lie on the opposite sides of the
7.2 Computing Minimum Link Paths in Simple Polygons
225
Figure 7.3 The portion of the link path L1 between z1 and z2 can be replaced by the segment z1 z2 .
line passing through uj and uj−1 (see Figure 7.3). If an edge uk uk+1 of SP (s, t) is a sub-segment of a link in a link path, we say that the link path contains uk uk+1 . We have the following lemma on eaves of SP (s, t). Lemma 7.2.6 There exists a minimum link path between s and t that contains all eaves of SP (s, t).
Proof. Consider a minimum link path L1 between s and t such that L1 does not contain an eave uj−1 uj of SP (s, t). Let w1 and w2 be the closest points among −−→ −−−−→ the intersection points of bd(P ) with − u− j uj−1 and uj−1 uj respectively (see Figure 7.3). So w1 w2 partitions P into four disjoint regions and two of these regions (say R1 and R2 ) do not contain s or t. Since P is a closed and bounded region, there exists a link ` in L1 with one endpoint in R1 and the other endpoint in R2 as every link path from s must intersect uj−1 uj in order to reach t. Let z1 and z2 be the intersection points of L1 with uj−1 w1 and uj w2 , respectively. A new link path L2 can be constructed from L1 by removing the portion of L1 between z1 and z2 , and adding the segment z1 z2 . This modification has removed ` totally and therefore, L2 is a minimum link path between s and t containing the eave uj−1 uj . If there exists another eave ui−1 ui that is not contained in L2 , remove the portion of L2 as before to construct another minimum link path L3 between s and t containing both eaves uj−1 uj and ui−1 ui . By repeating this process, a minimum link path between s and t can be constructed that contains all eaves of SP (s, t). The above lemma suggests a procedure for constructing a minimum link path between s and t in P .
226
Visibility and Link Paths
Figure 7.4 The construction of the sub-polygon Pij .
(i) Decompose P into sub-polygons by extending each eave from both ends to bd(P ). (ii) If two consecutive extensions intersect at a point z, then z is a turning point of the minimum link path between s and t. (iii) Construct minimum link paths connecting the extensions of every pair of consecutive eaves on SP (s, t) to form a minimum link path between s and t. Let us consider one such sub-polygon between the non-intersecting extensions of two consecutive eaves ui ui+1 and uj−1 uj of SP (s, t) (see Figure 7.4). Let wi+1 and wj−1 be the extension points on bd(P ) of the eaves ui ui+1 and uj−1 uj , respectively. Since wi+1 and wj−1 belong to the counterclockwise boundary of P from uj to ui −− −−→ (i.e., bd(uj , ui )), they can be computed by checking the intersection of u i ui+1 and − −−→ u− j uj−1 with the edges on bd(uj , ui ). This means that the extension points of all eaves of SP (s, t) can be computed in O(n) time. Let Pij denote the sub-polygon bounded by bd(wj−1 , wi+1 ), the segment wi+1 ui+1 , SP (ui+1 , uj−1 ) and the segment uj−1 wj−1 . Note that since SP (ui+1 , uj−1 ) does not contain any eave, no vertex of bd(wj−1 , wi+1 ) belongs to SP (ui+1 , uj−1 ), and therefore, Pij is a simple sub-polygon. Let Lij denote a minimum link path from a point on ui+1 wi+1 to some point on uj−1 wj−1 . A link path is called convex if it makes only left or only right turns at every turning point in the path. It has been observed by Ghosh [155] that Lij is a convex path inside Pij and this has been proved formally by Chandru et al. [69]. We prove this observation in the following lemma. Lemma 7.2.7 A minimum link path Lij is a convex path inside Pij . Proof. Without loss of generality, we assume that SP (ui+1 , uj−1 ) makes a right turn at every vertex in the path (see Figure 7.5). Let Lij =(z1 z2 , ..., zq−1 zq ), where
7.2 Computing Minimum Link Paths in Simple Polygons
227
Figure 7.5 (a) The segment xy intersects Lij at four points. (b) Lij makes a left turn at zr .
z1 ∈ ui+1 wi+1 and zq ∈ uj−1 wj−1 . To prove the lemma, it suffices to show that Lij makes a right turn at turning points z2 , z3 , ..., zq−1 while it is traversing from z1 to zq . Consider an edge up up+1 of SP (ui+1 , uj−1 ) (see Figure 7.5). Let x and y de−−→ −−−−→ note the closest points of intersection on bd(wj−1 , wi+1 ) with − u− p+1 up and up up+1 respectively. Let R denote the region of Pij bounded by xy and bd(y, x). If Lij intersects xy at three or more points (Figure 7.5(a)) or R contains three or more turning points of Lij , then the number of links in Lij can be reduced using xy, contradicting its minimality. So, we assume that Lij intersects xy at two points and R contains at most two turning points (say, zr and zr+1 ) of Lij (see Figure 7.5(b)). If Lij makes a left turn at zr , then extend the link zr−1 zr from zr meeting the link zr+1 zr+2 at a point z 0 . It means that there exists another link path z1 z2 , . . ., zr−1 z 0 , z 0 zr+2 , . . . , zq−1 zq , which has one link less that Lij , and this is a contradiction. So, Lij makes a right turn at zr . Analogous arguments show that Lij also makes a right turn at zr+1 . Since every turning point of Lij lies in one such region of Pij corresponding to an edge of SP (ui+1 , uj−1 ), Lij makes a right turn at z2 , z3 , ..., zq−1 . The above arguments also show that Lij does not cross any edge of SP (ui+1 , uj−1 ) and therefore, it remains inside Pij . In order to compute a convex link path Lij , we need the definitions of left and right tangents from a point z ∈ Pij to SP (ui+1 , uj−1 ). The segment zup is called the left tangent (or right tangent) of z at the vertex up ∈ SP (ui+1 , uj−1 ) (see Figure −−→ −−−−→ 7.4) if zup lies inside Pij and z lies to the right of − u− p−1 up (respectively, up up−1 ) and 0 − − − − → − − − − → to the left of up up+1 (respectively, up+1 up ). Note that for all points z ∈ Pij that lie −−→ −−−−→ 0 to the right of − u− p−1 up and to the left of up up+1 , z up may not be the left tangent of
228
Visibility and Link Paths
Figure 7.6 (a) The greedy path z1 z2 , z2 z3 , z3 z4 inside Pij is a minimum link path connecting ui+1 wi+1 to uj−1 wj−1 . (b) The convex set Cp is the region enclosed by SP (up , uq ) and the segment up uq .
z 0 if the segment z 0 up does not lie inside Pij . So, some points of Pij may not have the left or right tangent to SP (ui , uj ). We have the following lemma. Lemma 7.2.8 If a point z ∈ Pij is on a convex path between ui+1 wi+1 and uj−1 wj−1 inside Pij , then z has both left and right tangents. Proof. We prove the lemma only for the left tangent of z. The proof for the right tangent of z is analogous. Let up be the vertex of SP (ui+1 , uj−1 ) such that −−→ −−−−→ z lies to the right of − u− p−1 up and to the left of up up+1 . If the segment zup lies inside Pij , then zup is the left tangent of z. If zup does not lie inside Pij , it means that bd(wj−1 , wi+1 ) has intersected zup . Since z belongs to a convex path between ui+1 wi+1 and uj−1 wj−1 inside Pij by assumption, bd(wj−1 , wi+1 ) has intersected zup by intersecting the convex path, which is a contradiction. So, zup is the left tangent of z. Let Rij denote the set of all points of Pij such that every point of Rij has both left and right tangents to SP (ui , uj ) (see Figure 7.6(a)). We explain later the procedure for computing Rij . Assume that Rij has been computed. Lij can be constructed in Rij as follows (see Figure 7.6(a)). Let z1 ∈ ui+1 wi+1 denote the first turning point of Lij . If wi+1 belongs to Rij then z1 = wi+1 . Otherwise, z1 is the furthest point of ui+1 on ui+1 wi+1 that belongs to Rij (i.e., the next clockwise vertex of ui+1 in Rij ). Draw the right tangent from z1 to SP (ui+1 , uj−1 ) and extend the tangent until it meets the boundary of Rij at some point z2 . Again, draw the right tangent from z2 to SP (ui+1 , uj−1 ) and extend the tangent until it meets the boundary of Rij at some point z3 . Repeat this process of construction until a point zq is found
7.2 Computing Minimum Link Paths in Simple Polygons
229
on uj−1 wj−1 . Thus, the greedy path z1 z2 , z2 z3 ,...,zq−1 zq is constructed between ui+1 wi+1 and uj−1 wj−1 . We have the following lemma. Lemma 7.2.9 The greedy path z1 z2 , z2 z3 , ..., zq−1 zq is a minimum link path inside Pij , where z1 ∈ ui+1 wi+1 and zp ∈ uj−1 wj−1 . Proof. Since no link of any minimum link path connecting ui+1 wi+1 to uj−1 wj−1 can intersect more than one of the left tangents from z1 , z2 ,...,zq−1 to SP (ui+1 , uj−1 ), the greedy path z1 z2 , z2 z3 , ..., zq−1 zq is a minimum link path. Considering the first and the last edge of SP (s, t) as eaves on SP (s, t), the greedy paths between the extensions of every pair of consecutive eaves on SP (s, t) are computed and then they are connected as stated earlier to form a minimum link path between s and t. Let us discuss the procedure for computing Rij . For computing Rij , the algorithm of Ghosh [155, 156] partitions Pij into sub-polygons by extending some of the edges of SP (ui+1 , uj−1 ) to the boundary of Pij such that (i) no two extensions pass through the same triangle in the triangulation of P , and (ii) the portion of SP (u i+1 , uj−1 ) in each sub-polygon (say, SP (up , uq )) does not make a total turn of more than 2π (see Figure 7.6(b)). Treating the region enclosed by SP (up , uq ) and the segment up uq as a convex set Cp , compute the complete visibility polygon from Cp of the sub-polygon of Pij bounded by uq wq , bd(wq , wp ), wp up and up uq (see Figure 7.6(b)). It can be seen that the union of these complete visibility sub-polygons from such convex sets Cp is Rij (see Section 3.8) and the time taken to compute Rij from Pij is proportional to the size of Pij . The region Rij can also be computed using shortest path trees as shown by Chandru et al. [69]. In the following lemma, we present their main idea used in computing Rij (see Figure 7.7(a)). Lemma 7.2.10 For any vertex vi ∈ bd(wj−1 , wi+1 ), the left and right tangents of vi lie inside Pij if and only if the parents of vi in SP T (ui+1 ) and SP T (uj−1 ) are vertices of SP (ui+1 , uj−1 ). Proof. If a vertex up ∈ SP (ui+1 , uj−1 ) is the parent of vi in SP T (ui+1 ), then vi up is the left tangent of vi by the definition of left tangent. Conversely, if the left tangent of vi (say, vi up ) lies inside Pij , then vi up is tangential to SP (ui+1 , uj−1 ) at up by the definition of left tangent of vi . Therefore, up is the parent of vi in SP T (ui+1 ). Analogous arguments hold for the right tangent of vi . Using the above lemma, vertices of Pij that belong to Rij can be identified by traversing SP T (ui+1 ) and SP T (uj−1 ). Hence, Rij can be computed in time proportional to the size of Pij (see Section 3.3.2).
230
Visibility and Link Paths
Figure 7.7 (a) The parent of each vertex of Rij is a vertex of SP (ui+1 , uj−1 ) in both SP T (ui+1 ) and SP T (uj−1 ). (b) The vertex up is the last vertex of SP (ui+1 , uj−1 ) visible from ui+1 wi+1 .
It has been shown by Hershberger and Snoeyink [188] that there is no need to compute Rij as the greedy path z1 z2 , z2 z3 , ..., zq−1 zq connecting ui+1 wi+1 to uj−1 wj−1 can be computed directly inside Pij as follows. Let up be the vertex of SP (ui+1 , uj−1 ) such that the first link z1 z2 passes through up (see Figure 7.7(b)). Let us explain how up can be identified. Since z1 up is the right tangent of z1 , each vertex of SP (ui+1 , up ) is visible from some point of ui+1 wi+1 and no vertex of SP (up+1 , uj−1 ) is visible from any point of ui+1 wi+1 . This means that while traversing SP (ui+1 , uj−1 ) from ui+1 to uj−1 , up is the last vertex such that SP (ui+1 , up ) and SP (wi+1 , up ) are disjoint (see Corollary 3.2.8). Using the triangulation of Pij , compute SP (wi+1 , ui+2 ), SP (wi+1 , ui+3 ), . . . till a vertex ul is reached such that SP (ui+1 , ul ) and SP (wi+1 , ul ) are not disjoint. So, ul−1 is the vertex up . Let vr ∈ bd(wj−1 , wi+1 ) be the previous vertex of up in SP (wi+1 , up ) (see Figure 7.7(b)). Observe that if vr is same as wi+1 , then z1 = wi+1 . → Otherwise, the intersection point of − u− p vr and ui+1 wi+1 is the point z1 . Using the triangulation of Pij , extend z1 up from up to the boundary of Pij meeting it at a point z20 . Treating vp z20 as ui+1 wi+1 , z2 can be located on up z20 as before. By repeating this process, the greedy path z1 z2 , z2 z3 , ..., zq−1 zq can be computed in Pij without computing Rij . Observe that vertices of SP (wi+1 , up ) are the vertices of the convex hull of bd(vd , wi+1 ), where vd up is a diagonal in the triangulation of Pij . It means that all vertices of SP (wi+1 , up ) belong to those triangles that are on the path from wi+1 to up in the dual of the triangulation of P ij. Therefore, it is enough to consider
7.3 Computing Minimum Link Paths in Polygons with Holes
231
these triangles to compute SP (wi+1 , up ). Hence, the greedy path inside Pij can be computed in time proportional to the number of vertices of Pij . In the following, we present the main steps of the algorithm for computing a minimum link path between two given points s and t inside a simple polygon P . Step 1. Compute SP (s, t) using the algorithm of Lee and Preparata [235]. Step 2. Decompose P into sub-polygons by extending each eave of SP (s, t) from both ends to bd(P ). Also extend the first and the last edges of SP (s, t) to bd(P ). Step 3. In each sub-polygon of P , construct the greedy path between the extensions of the eaves. Step 4. Connect the greedy paths using the extension of the eaves to form a minimum link path between s and t. The correctness of the algorithm follows from Lemmas 7.2.6, 7.2.7 and 7.2.9. We have already shown that the algorithm runs in O(n) time. We summarize the result in the following theorem. Theorem 7.2.11 A minimum link path between two given points inside a simple polygon of n vertices can be computed in O(n) time.
7.3 Computing Minimum Link Paths in Polygons with Holes In this section, we present the algorithm of Mitchell et al. [262] for computing a minimum link path between two given points s and t inside a polygon P with holes. The algorithm runs in O(Eα(n) log2 n) time and O(E) space, where E is the number of edges in the visibility graph of P and α(n) is the inverse of Ackermann’s function. This algorithm can be viewed as the generalization of that of Suri [318] (see Section 7.2.1). Let M LP (s, t) denote a minimum link path between s and t in P . Compute the visibility polygon V (s) of P from s. This can be computed by the algorithm of Asano [27] in O(n log n) time (see Section 2.3). Observe that V (s) is the set of all points of P that can be reached by one link from s (see Figure 7.8(a)). If t ∈ V (s), then the segment st is the minimum link path from s to t. Let us denote the region V (s) as R1 and P as P0 . We have the following lemma. Lemma 7.3.1 The visibility polygon of P0 from s is the set R1 of all points of P0 that can be reached from s by one link. Consider the other situation when t cannot be reached by one link. Observe that since the given polygon P0 contains holes, removing R1 from P0 does not split P0 into disjoint sub-polygons as in the case of a simple polygon and therefore, all
232
Visibility and Link Paths
Figure 7.8 (a) The target point t can be reached from s in four links as t ∈ R4 . (b) The region H1 is a cell formed due to the intersection of two constructed edges of Ri+1 .
constructed edges of R1 (denoted as E1 ) are considered for computing M LP (s, t), as any one of them can be intersected by M LP (s, t). Let P1 denote the region P0 − R1 . Let R2 denote the set of all points of P1 that can be reached from s by two links (see Figure 7.8(a)). In other words, R2 is the set of all points of P1 that can be reached by one link from some point of any constructed edge in E1 . It can be seen that R2 is the union of weak visibility polygons of P1 from constructed edges in E1 . Compute R2 . If t ∈ R2 , take any point w1 on a constructed edge in E1 such that tw1 lies inside R2 . So, M LP (s, t) consists of sw1 and w1 t. Otherwise, compute R3 , which is the union of weak visibility polygons of P1 − R2 (denoted as P2 ) from constructed edges of R2 (say, E2 ). This process of computing Ri+1 in Pi from constructed edges in Ei continues till t becomes visible from a constructed edge in Em−1 , where m is the link distance between s and t. We have the following lemmas.
Lemma 7.3.2 For 1 ≤ i < m, the set of all points Ri+1 of Pi that can be reached from s by i + 1 links is the union of weak visibility polygons of P i from constructed edges in Ei . Lemma 7.3.3 For 1 ≤ i < m, there exists a M LP (s, t) in P0 whose i-th turning point lies on a constructed edge in Ei . Once t becomes visible from some constructed edge ud ∈ Em−1 , turning points w1 , w2 , . . . , wm−1 of M LP (s, t) can be located using Lemma 7.3.3 as follows. Take a point wm−1 ∈ ud such that wm−1 t lies inside Rm . Locate a point wm−2 on a constructed edge in Em−2 such that wm−2 , u and d are collinear and the segment
7.3 Computing Minimum Link Paths in Polygons with Holes
233
Figure 7.9 (a) Cells H1 and H2 do not contain t. (b) Cells H1 and H2 and the holes enclosed by them are included in the enhanced Ri+1 .
wm−2 wm−1 lies inside Rm−1 . Similarly, other turning points wm−3 , wm−4 , . . . , w1 can also be located in this manner. Hence, M LP (s, t) consists of links sw1 , w1 w2 , . . ., wm−1 t. Let us discuss the problem of computing Ri+1 in Pi for i ≥ 1. We know that Ri+1 is the union of weak visibility polygons of Pi computed from every constructed edge in Ei . Suppose Ei has only one constructed edge ud. Using the algorithm of Suri and O’Rourke [321] (see Section 3.4), the weak visibility polygon V (ud) of Pi from ud can be computed in O(n4 ) time. It has been shown by Suri and O’Rourke that there can be O(n2 ) constructed edges in V (ud) and some of them may be intersecting each other. As a result, there can be O(n4 ) boundary edges of V (ud). It means that for computing Ri+2 , the weak visibility polygon has to be computed from each of the O(n4 ) boundary edges of V (ud). The discussion suggests that a large computation time is required to carry out this process. Therefore, the construction of a full boundary representation of Ri+1 is avoided for i ≥ 1. Exercise 7.3.1 Let P be a polygon with holes with a total of n vertices. Draw a diagram showing that the number of constructed edges of the weak visibility polygon of P from a given segment inside P can be O(n 4 ) [321]. Observe that due to intersections of constructed edges of Ri+1 among themselves, there can be several bounded regions (called cells) which are not visible from any constructed edge in Ei but every such region is enclosed by the points of Ri+1 . In Figure 7.8(b), the region H1 is a cell as it is formed due to the intersection of two constructed edges of Ri+1 . If a cell H1 contains t (see Figure 7.8(b)), it is enough to consider H1 as Pi+1 as every path from s to t intersects boundary edges of H1 and therefore non-polygonal boundary edges of H1 constitute Ei+1 . If t is not contained
234
Visibility and Link Paths
in a cell H1 (see Figure 7.9(a)), H1 and the regions of holes enclosed by H1 are included in Ri+1 (see Figure 7.9(b)), which simplifies the boundary of Ri+1 . We state this fact in the following lemma. Lemma 7.3.4 If a cell, formed in Pi due to constructed edges of Ri+1 , does not contain t, then the cell along with the regions of holes enclosed by the cell can be added to Ri+1 . Consider another type of cell H2 that is not enclosed by points of Ri+1 but all its non-polygonal boundary edges are parts of constructed edges of Ri+1 . If H2 does not contain t (see Figure 7.9(a)), it means that no M LP (s, t) passes through any point of H2 and therefore, H2 can also be included in the enhanced Ri+1 as Lemma 7.3.4 holds for H2 (see Figure 7.9(b)). Since only one cell of either type contains t (see Figure 7.9(b)), all other cells can be included in Ri+1 and therefore, the enhanced Ri+1 becomes a simple polygon, which is denoted as Qi . So, by enhancing Ri+1 , a simple polygon Qi is constructed inside Pi . The cell in Pi containing t can be identified as follows. Construct the single face f containing t in the arrangement of constructed edges of Ei+1 and all polygonal edges of Pi using the algorithm of Edelsbrunner et al. [118]. For computing a single face in an arrangement of N line segments, this algorithm takes O(N α(N ) log 2 N ) time. Observe that the same polygonal edge can occur on the boundary of the face containing t at every iteration and therefore, the total cost becomes O(n 2 α(n) log2 n) in the worst case. However, Mitchell et al. showed that the total cost can be reduced to O(Eα(n) log2 n), where E is the number of edges in the visibility graph of P . Their algorithm first constructs the arrangement consisting of only the constructed edges in Ei+1 along with those polygonal edges in Pi that contain the endpoints of these constructed edges in Ei+1 , and then identifying the face in the arrangement, which is a part of f . For more details on identifying f , see the original paper. Observe that the algorithm for computing arrangements needs only the constructed edges of Ri+1 to locate the face f in Pi . This means that there is no need to compute the entire Ri+1 . Later, we explain how constructed edges of Ri+1 can be computed using the visibility graph of P without computing the region Ri+1 . Before the algorithm computes weak visibility polygons from the non-polygonal boundary edges of Qi , Qi is further simplified using the paths of minimum length between appropriate boundary points of Qi as stated in the following lemma. Lemma 7.3.5 Let chain(z1 , zk ) denote a portion of the boundary of Qi such that z1 and zk are points on the boundary of P and all edges of chain(z1 , zk ) are constructed edges of Qi (Figure 7.10(a)). Let mpath(z1 , zk ) denote the path between z1 and zk inside Pi of minimum length such that the region enclosed by mpath(z1 , zk ) and chain(z1 , zk ) lies inside Pi . If a point y ∈ Pi − Qi is visible from some point on mpath(z1 , zk ), then y is also visible from some point on chain(z1 , zk ).
7.3 Computing Minimum Link Paths in Polygons with Holes
235
Figure 7.10 (a) The region bounded by mpath(z1 , zk ) and chain(z1 , zk ) is added to Qi to form the relative convex hull Q0i . (b) The boundary of Qi consists of only one closed chain consisting of sub-segments of constructed edges in Ei+1 .
Exercise 7.3.2 Prove Lemma 7.3.5. The above lemma suggests that by replacing each portion of non-polygonal boundary of Qi by its corresponding mpath, Qi can be modified to another simple polygon Q0i . So, the non-polygonal edges of Q0i can be used to compute weak visibility polygons for the next stage. The polygon Q0i is called the relative convex hull of Qi . Let us explain how mpath(z1 , zk ) can be computed (see Figure 7.10(a)). Scan the edges of chain(z1 , zk ) from z1 till a point m1 is reached such that the segment z1 m1 passes through a vertex r1 of Pi . It can be seen that m1 is the intersection point of chain(z1 , zk ) with the boundary of the visibility polygon of Pi from z1 . So, r1 is the next vertex of z1 in mpath(z1 , zk ). Continue the scan treating r1 as z1 till a point m2 (and the vertex r2 ) is located or zk is reached. Thus, the intermediate vertices r1 , r2 , . . . of mpath(z1 , zk ) can be located. It may so happen that Qi is bounded only by the constructed edges in Ei+1 (see Figure 7.10(b)). In such a situation, we have only one closed chain and no point of the chain belongs to the polygonal boundary. Therefore, the boundary of Q 0i is the boundary of the convex hull of those holes that are lying inside the closed chain. In the following, we present the major steps of the algorithm for computing M LP (s, t) in P00 , where P00 = P . The index i is initialized to 0. Step 1. Compute the visibility polygon Ri+1 of Pi0 from s. If t is visible from s, report st as M LP (s, t) and goto Step 7. Step 2. Add the constructed edges of Ri+1 to Ei+1 . Step 3. Construct the single face f containing t in the arrangement of constructed
236
Visibility and Link Paths
edges of Ei+1 and all polygonal edges of Pi0 using the algorithm of Edelsbrunneret al. [118]. Assign the region of Pi0 excluding the face f to Qi . 0 . Step 4. Compute the relative convex hull Q0i of Qi and assign Pi0 -Q0i as Pi+1 Step 5. If t is not visible from any non-polygonal edge of Q0i then i := i + 1, compute all constructed edges of Ri+1 in Pi0 from non-polygon edges of Q0i−1 and goto Step 2. Step 6. Locate a point wi+1 on an edge ui+1 di+1 in Ei+1 that is visible from t. While i ≥ 1 do
Step 6a. Locate a point wi on an edge ui di in Ei that is collinear with ui+1 and di+1 and is visible from wi+1 . Assign i − 1 to i.
Step 7. Report M LP (s, t) = (sw1 , w1 w2 , . . . , wi+1 t). Step 8. Stop.
The correctness of the algorithm follows from Lemmas 7.3.1, 7.3.2, 7.3.3, 7.3.4 and 7.3.5. Before we analyze the time complexity of the algorithm, we state a preprocessing step which allows constructed edges of all weak visibility polygons in P to be computed in O(E) time. Compute the visibility graph of P in O(n log n + E) time by the algorithm of Ghosh and Mount [165] (see Section 5.3.2). This algorithm first triangulates P using plane-sweep and then constructs funnel sequences for all triangulating edges and polygonal edges in P , giving the visibility graph of P . So, by traversing a funnel sequence using the pointers CCW , CW , CCX, CX and REV , the vertices of P that are weakly visible from the base of the funnel can be located. Let ud be a constructed edge of Ri , where d is a point on a polygonal edge vj vj+1 (see Figure 7.11(a)). In order to compute the constructed edges of the weak visibility polygon from ud, it is necessary to locate vertices of P visible from ud, and this can be done by traversing the funnel sequence for the base ud. On the other hand, there is no funnel sequence in the visibility graph P with ud as the base because d is not a vertex of P . So, the algorithm incorporates d as a vertex in the visibility graph of P by adding all edges dd0 to the visibility graph of P , where d0 is a vertex visible from d. It can be seen that all vertices of P visible from d are also weakly visible from the edge vj vj+1 . Therefore visible vertices of d belong to the funnel sequence for vj vj+1 , which can be located by traversing the funnel sequence for vj vj+1 . Observe that there can be several constructed edges that are incident on v j vj+1 . If the non-vertex endpoint of every constructed edge incident on vj vj+1 is incorporated as a vertex of the visibility graph of P , it may involve repeated traversal of the same vertices of the funnel sequence for vj vj+1 . On the other hand, we need the visibility polygons only from those non-vertex endpoints on vj vj+1 that are on the boundary of the relative convex hulls. Since there can be at most two such nonvertex endpoints on vj vj+1 that can belong to the relative convex hulls, the funnel sequence for vj vj+1 can be traversed at most twice. Hence the total time required to
7.3 Computing Minimum Link Paths in Polygons with Holes
237
Figure 7.11 (a) The vertices of Ri+1 visible from non-vertex endpoint d belong to the funnel sequence for vj vj+1 . (b) The funnels F2 and F3 share edges of the visibility graph of P .
compute the visibility polygons from two non-vertex endpoints on every polygonal edge is O(E). Assume that the algorithm has incorporated the non-vertex endpoint d of a constructed edge ud as a vertex in the visibility graph of P (see Figure 7.11(b)). Consider a constructed edge u1 d1 of the weak visibility polygon from ud, where u1 is a vertex of P and d1 is a point on some polygonal edge vk vk+1 . Observe that u1 d1 is an extension of an edge on the side of a funnel F1 (with ud as a base) from the apex u1 to vk vk+1 . In fact, u1 is also the apex of another funnel F2 with base vk vk+1 . This polygonal edge vk vk+1 can be located by traversing the visibility graph of P from the apex u1 using pointers CCX or CX at each vertex of P in the path, (which is a side of F2 ) until vk vk+1 is reached. Once vk vk+1 is located, u1 d1 can be constructed. It may happen that another constructed edge u2 d2 of the weak visibility polygon from ud is also incident on vk vk+1 (see Figure 7.11(b)). Let F3 be the funnel with the apex u2 and the base vk vk+1 . It can be seen that the sides of F2 and F3 may have the same edges up to a vertex before they bifurcate to u1 and u2 . Keeping the history of the earlier traversal of the side of F2 , repeated traversal of the common edges of F2 and F3 can be avoided. This means that the entire funnel sequence for vk vk+1 can be traversed only once for computing all constructed edges in P incident on vk vk+1 . Therefore, the total time required for computing all constructed edges in P is O(E). Let us analyze the time complexity of the algorithm after the visibility graph of P has been computed in O(n log n + E) time by the algorithm of Ghosh and Mount [165]. Consider Step 1. Locate the triangle in the plane-sweep triangulation
238
Visibility and Link Paths
of P containing s. Considering each side of this triangle as a base, traverse their funnel sequences to locate vertices of P that are visible from s. Then compute all constructed edges E1 of R1 by traversing the visibility graph of P as stated above. So, Step 1 takes O(n) time. It has been discussed earlier that Step 3 takes O(Eα(n) log2 n) time. Step 4 takes O(Eα(n)) time as the total number of edges on the boundaries of Q0 , Q1 , . . . , Qm−2 can be O(Eα(n)), where m is the link distance between s and t. Consider Step 5. Compute the visibility polygon V (t) of P from t in the same way V (s) has been computed in Step 1. Then it can be tested in O(log |V (t)|) time whether any given segment lies inside V (t). Since a vertex of P can belong to only two edges of Q00 , Q01 , . . . , Q0m−2 , the total time for testing all edges of Q00 , Q01 , . . . , Q0m−2 until t becomes visible is O(n log n). It has been shown earlier that all constructed edges of R1 , R2 , . . . , Rm−1 can be computed in O(E) time. Hence, the overall time complexity of the algorithm is O(Eα(n) log 2 n). We summarize the result in the following theorem. Theorem 7.3.6 A minimum link path between two given points inside a polygon P with holes with a total of n vertices can be computed in O(Eα(n) log 2 n) time, where E is the number of edges in the visibility graph of P and α(n) is the inverse of Ackermann’s function.
7.4 Computing Link Center and Radius of Simple Polygons In this section, we present an O(n2 ) time algorithm of Lenhart et al. [241] for computing the link center, link radius and link diameter of a simple polygon P . We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. As defined earlier, the link center of P is the set of all points w ∈ P at which the maximum link distance from w to any point of P is minimized (see Figure 7.12(a)). Recall that the maximum link distance of w is called the link radius of P . In Figure 7.12(a), the link radius of P is 2. We know that the link distance between any two points u and u0 of P can be computed by computing a minimum link path from u to u0 . Suppose, P is partitioned into regions Q1 , Q2 ,..., Qm such that for 1 ≤ i ≤ m, all points of Qi is reachable by i links from u (see Figure 7.12(b)). This means that Q1 is the visibility polygon of P from u, Q2 is the union of weak visibility polygons of P − Q1 from constructed edges of Q1 , Q3 is the union of weak visibility polygons of P − Q1 − Q2 from constructed edges of Q2 and so on. This partition helps in computing the link distance from u to any other point u0 in P by locating the region Qi containing u0 . The partition of P into regions Q1 , Q2 ,..., Qm has been introduced by Suri [318, 319] and is called the window partition of P for u. We refer to the union of regions Q 1 , Q2 ,..,Qk as k-visibility regions of u, where 1 ≤ k ≤ m.
7.4 Computing Link Center and Radius of Simple Polygons
239
Figure 7.12 (a) Shaded region is the link center of P and all points of P can be reaches by two links from any point w of the link center. (b) The window partitioning of P for u.
Consider first the problem of computing the link radius r of P . If a point w in the link center of P is known, then compute the window partition Q1 , Q2 ,..., Qm of P for w. So, r is same as m. If no point of the link center is known, then r can be computed once the link diameter d of P is known. As defined earlier, the link diameter of P is the maximum link distance between any two points inside P . In Figure 7.12(a), the link diameter of P is 4. We have the following lemmas on the link diameter of P . Lemma 7.4.1 Let r and d be the link radius and link diameter of P . Then dd/2e ≤ r ≤ d(d/2)e + 1. Lemma 7.4.2 The maximum of link distances among all pairs of vertices of P is the link diameter of P . Exercise 7.4.1 Prove Lemmas 7.4.1 and 7.4.2. Compute the window partition of P for each vertex of P and choose a pair of vertices which have the maximum link distance (say d0 ). By Lemma 7.4.2, d0 is same as d. Once d is known, r can be computed from d using Lemma 7.4.1. Once r is known, the link center of P can be computed using the following lemma. Lemma 7.4.3 The link center of P is the intersection of all r-visibility regions of P for every convex vertex in P . Proof. Let w be a point in the common intersection region of all r-visibility regions of P for every convex vertex in P . If w belongs to the link center of P , then the
240
Visibility and Link Paths
lemma holds. So, we assume that w does not belong to the link center of P . This means that there exists a point u ∈ P such that the r-visibility region of P for u does not include w. Therefore, the link distance between w and u is more that r. Let u0 be the point on the boundary of P such that uu0 is the extension of the last link w 0 u in the minimum link path from w to u. Let vj and vk be two convex vertices such that all vertices of bd(vj , vk ) are reflex vertices and u0 belongs bd(vj , vk ). If vj or vk is visible from w 0 , then the link distance between w and u cannot be more than r as w belongs to the r-visibility region of P for both vj and vk , which is a contradiction. If both vj and vk are not visible from w 0 , it means that the link distance between w and u is less than r as at least two links from w 0 are necessary to reach vj and vk in minimum link paths from w to vj and vk , which is a contradiction. Hence, w belongs to the link center of P . Exercise 7.4.2 Prove that the link center of a simple polygon is a convex region [241]. In the following, we present the major steps of the algorithm for computing the link radius r, link diameter d and link center lc of P . Initialize i, d and r by 1. Step 1. Compute the window partition of P for vi and assign the number of regions in the partition to d0 . Step 2. If d0 > d then d := d0 . Step 3. If i 6= n then i := i + 1 and goto Step 1. Step 4. Assign dd/2e to r.
Step 5. Initialize lc by P . Initialize i by 1.
Step 6. If vi is a convex vertex then Step 6a. Compute r-visibility region of P for vi and take its intersection with lc. Step 6b. Assign the common intersection region to lc. Step 7. If lc is empty then r := r + 1 and goto Step 5. Step 8. If i 6= n then i := i + 1 and goto Step 6.
Step 9. Report lc as the link center of P . Report r and d as the link radius and link diameter of P , respectively.
The correctness of the algorithm follows from Lemmas 7.4.1, 7.4.2 and 7.4.3. Note that Step 5 can be executed at most twice as the link radius r of P can be dd/2e or d(d/2)e + 1.
Let us analyze the time complexity of the algorithm. The window partition of P for a vertex vi in Step 1 can be computed in O(n) as follows. Compute the shortest path tree SP T (vi ) in P rooted at vi in O(n) time by the algorithm of Guibas et al. [178] (see Section 3.6.1). It can be seen that vertices of Q1 are children of vi in
7.4 Computing Link Center and Radius of Simple Polygons
241
SP T (vi ). Let V1 denote these vertices. Compute the shortest path map SP M (vi ) in O(n) time by the algorithm of Hershberger [186] (see Section 5.2). Observe that all non-polygonal edges on the boundary of Q1 are those extension edges of SP M (vi ) whose one endpoint is a vertex of V1 . Thus, the boundary of Q1 can be identified in time proportional to the size of Q1 after SP T (vi ) and SP M (vi ) have been computed in O(n) time. Let vj u be an extension edge of SP M (vi ) on the boundary of Q1 . We know that vj belongs to V1 and u is a point on the boundary of P . Take the sub-tree SP T (vj ) of SP T (vi ) and compute SP T (u) by shifting the root from vj to u as in the algorithm of Hershberger [186]. It follows from Lemma 5.2.1 that vertices of SP T (v j ) belonging to Q2 are only those vertices of SP T (vj ) whose parents in SP T (u) are different. Therefore, vertices of SP T (vj ) that are weakly visible from vj u can be identified in a time that is proportional to the number of such vertices. Note that although SP M (vj ) is available from SP M (vi ), SP M (u) needs to be computed in order to identify the extension edges of SP M (u) that are on the boundary of Q2 . This can also be done in a time that is proportional to the number of vertices that are weakly visible from vj u. Repeat this process for all extension edges of SP M (vi ) on the boundary of Q1 . Thus, entire Q2 can be constructed in a time that is proportional to its size as the shifting of roots along extension edges involve disjoint sub-trees of SP T (vi ). Analogously, Q3 , Q4 , . . . , Qm can also be computed in a time that is proportional to their respective sizes. Hence, the window partitioning of P in Step 1 for each vertex can be done in O(n) time. Since Step 1 is executed for each vertex of P , Step 1 takes O(n2 ) time. Let us discuss the time complexity of Step 6a. Since the window partitioning of P for vi has already been computed in Step 1, the r-visibility region of P for vi (say, V Ri ) is known. To compute V Ri ∩ lc, the procedure traverses the boundary of lc in counterclockwise order and checks whether the current vertex vp is an endpoint of a non-polygonal edge (say vp u) of V Ri . If so, it computes the intersection point u0 of vp u with the boundary of lc by traversing lc from vp in the clockwise or counterclockwise direction depending upon the position of u. So, vp u0 divides lc into two parts and one part is removed from lc. It may so happen that there is no intersection point u0 as the entire vp u (except the vertex vp ) lies outside lc, which can be tested in constant time. In that case, either lc remains unchanged or lc becomes empty. Once the intersection of lc and all non-polygonal edges of V R i with common vertices have been computed, the remaining portion of lc is considered as the current lc. The procedure then traverses the boundary of V Ri and checks whether the current vertex vq is an endpoint of a non-polygonal edge (say, vq u) of V Ri and vq is not a vertex of lc. If so, compute the intersection of lc with vq u using a method that is similar to the procedure for computing the kernel of a simple polygon (see Section 2.4). Thus, V Ri ∩ lc can be computed in O(n) time. Since Step 6a is executed for each convex vertex of P , Step 6a can take O(n2 ) time in
242
Visibility and Link Paths
Figure 7.13 (a) The polygon K is a minimum nested polygon between two convex polygons P and Q. (b) The nested polygon K 0 has one more vertex than a minimum nested polygon K.
the worst case. Hence, the overall time complexity of the algorithm is O(n 2 ). We summarize the result in the following theorem. Theorem 7.4.4 The link center, link radius and link diameter of a simple polygon P of n vertices can be computed in O(n2 ) time.
7.5 Computing Minimum Nested Polygons 7.5.1 Between Convex Polygons: O(n log k) Algorithm In this section, we present an O(n log k) algorithm of Aggarwal et al. [12] for computing a minimum nested polygon K between two given convex polygons P and Q, where Q ⊂ P , n is the total number of vertices of P and Q, and k is the number of vertices of K (see Figure 7.13(a)). A simple polygon K is called nested between P and Q, when it circumscribes Q and is inscribed in P (i.e. Q ⊂ K ⊂ P ). The problem here is to compute a nested polygon K with the minimum number of vertices. We assume that the vertices of P and Q are labeled in counterclockwise order p 1 , p2 , . . . , pm and q1 , q2 , . . . , ql , respectively, where m + l = n. Let R denote the annular region between P and Q, i.e., R = P − Q. Draw the tangent from a point z ∈ R to Q meeting Q at a vertex qi such that both vertices →i (see Figure 7.13(a)). We call zqi as the left tangent qi−1 and qi+1 lie to the left of − zq of z. The right tangent from z to Q is defined analogously. It can be seen that both tangents of z lie inside R as P and Q are convex. Let z1 be a point on the boundary of P (denoted as bd(P )). Draw the left tangent from z1 to Q and extend the tangent until it meets bd(P ) at some point z2 (see Figure 7.13(b)). Again, draw
7.5 Computing Minimum Nested Polygons
243
the left tangent from z2 to Q and extend the tangent until it meets bd(P ) at some point z3 . Repeat this process of construction until a point zq ∈ bd(P ) is found such that the segment zq z1 lies inside R. This greedy path z1 z2 , z2 z3 , . . . , zq−1 zq along with the link zq z1 gives a nested polygon K 0 in R. Note that K 0 can be computed in O(n) time. For any two turning points zi and zj for i < j, zj is called the forward projection point of zi and zi is called the backward projection point of zj . We have the following observations. Lemma 7.5.1 Let z1 z2 , z2 z3 , . . . , zq z1 be the edges of a convex polygon K 0 nested between P and Q such that vertices z1 , z2 , . . . , zq are on the boundary of P and edges z1 z2 , z2 z3 , . . . , zq−1 zq are tangential to Q. The polygon K 0 has at most one more vertex than a minimum nested polygon K between P and Q. Proof. Since no edge of K can intersect more than one of the left tangents from z1 , z2 , . . . , zq−1 (see Figure 7.13(b)), the polygon K 0 has at most one more vertex than K. Corollary 7.5.2 For 1 ≤ i ≤ q − 1, the region of R bounded by zi zi+1 and the counterclockwise boundary of P from zi to zi+1 contains a vertex of K. Lemma 7.5.3 There exists a minimum nested polygon K between P and Q such that all vertices of K belong to the boundary of P . Exercise 7.5.1 Prove Lemma 7.5.3. Let us explain the procedure for computing K from K 0 . We know from Corollary 7.5.2 and Lemma 7.5.3 that there is a vertex of K lying on the counterclockwise boundary of P from z1 to z2 (denoted as bdp (z1 , z2 )). If the position of a vertex (say, u1 ) of K on bdp (z1 , z2 ) is known (see Figure 7.13(b)), the edges u1 u2 , u2 u3 , . . . , uk u1 of K can be computed by constructing the greedy path starting from u1 . Note that q − 1 ≤ k ≤ q by Lemma 7.5.1. Therefore, the problem of computing K has been reduced to finding the position of u1 on bdp (z1 , z2 ). Suppose a point w is moved along bdp (z1 , z2 ) starting from z1 and for each position of w, the greedy path from w is computed. It can be seen that when w reaches u1 (see Figure 7.13(b)), the last link in the greedy path from w ‘collapses’ to a point, which gives K as it has one edge less than K 0 . On the other hand, it is not feasible to compute the greedy path from every point w on bdp (z1 , u1 ). So, the algorithm first divides bdp (z1 , z1 ) into intervals and then composes a unique function for every interval which maps any point w in the interval to the last turning point of the greedy path from w. Using these functions, the algorithm locates a point u1 ∈ bdp (z1 , z2 ) such that u1 is same as uk+1 and then constructs K by computing the greedy path from u1 to u1 .
244
Visibility and Link Paths
Figure 7.14 (a) The reverse greedy path from s1 is (s1 s2 , s2 s3 , s3 s4 ). (b) The intervals on bdp (z1 , z2 ) in R1 ∪ R2 are computed using backward projection points of A2 on bdp (z1 , z2 ).
Let us first explain the procedure for computing intervals on bdp (z1 , z2 ). Recall that the greedy path z1 z2 , z2 z3 , . . . , zq−1 zq alternatively touches a vertex qj of Q and meets an edge ei of P . This alternating sequence (ei1 , qj1 , ei2 , qj2 , .., eiq ) of vertices and edges (see Figure 7.13(b)), where z1 ∈ ei1 and zq ∈ eiq , is called the link sequence of z1 [69]. Observe that there is a neighborhood of z1 on bd(P ) such that for any point in the neighborhood, the link sequence is the same. We define an interval on bd(P ) to be the largest such neighborhood forming a segment, which is an edge or a subset of an edge on bd(P ). We have the following observation. Lemma 7.5.4 A point w is an endpoint of an interval on bdp (z1 , z2 ) if and only if (i) w is a vertex of P on bdp (z1 , z2 ), or (ii) the greedy path from w turns at some vertex of P or passes through an edge of Q. Proof. Proof of the lemma follows from the definition of the link sequence. Using the above lemma, bdp (z1 , z2 ) can be divided into intervals using backward projection points of (i) vertices of P , and (ii) those points that are extensions of edges of Q to bd(P ). Backward projection points can be computed as follows. For any point s1 on bd(P ), draw the right tangent from s1 to Q and extend the tangent meeting bd(P ) at some point s2 (see Figure 7.14(a)). If s2 ∈ bdp (z1 , z2 ), then s2 is the backward projection point of s1 on bdp (z1 , z2 ). If s2 ∈ / bdp (z1 , z2 ), compute s3 by drawing the right tangent from s2 and extend the tangent meeting bd(P ) at s3 . This process of computing backward projection points continues until a point on bdp (z1 , z2 ) is reached. We call this path s1 s2 , s2 s3 , . . . the reverse greedy path from s1 . Observe that the intervals on bdp (z1 , z2 ) can be computed in O(nk) time by traversing the boundaries of P and Q once in counterclockwise order and by comput-
7.5 Computing Minimum Nested Polygons
245
ing the reverse greedy path (of size at most k) from each vertex or extension point on bd(P ). Once the intervals are computed, the greedy paths from every endpoint of all intervals on bdp (z1 , z2 ) can also be computed in O(nk) time. Let us show that there is a unique function associated with each interval of bdp (z1 , z2 ). We start with the link sequence (ei1 , qj1 , ei2 , qj2 , .., eiq ) of z1 (see Figure 7.13(b)). We know the coordinates of z1 and qj1 , and the equation of ei2 . Therefore, the coordinates of z2 can be obtained from those of z1 using the following pair of bilinear functions. x(z2 ) = (a1 .x(z1 ) + b1 .y(z1 ) + c1 )/(d1 .x(z1 ) + f1 .y(z1 ) + g1 ) y(z2 ) = (a2 .x(z1 ) + b2 .y(z1 ) + c2 )/(d1 .x(z1 ) + f1 .y(z1 ) + g1 ) where x(), y() denote the abscissa and ordinate values of a point. The coefficients a1 , b1 , c1 , d1 , f1 , g1 , a2 , b2 and c2 depend on the coordinates of qj1 and the equation of ei2 . It can be seen that the above pair of bilinear functions map points in the neighborhood of z1 to points in the neighborhood of z2 . Similarly, we have a pair of bilinear functions that map points in the neighborhood of z2 to points in the neighborhood of z3 . By composing these two pairs of functions, we obtain a pair of bilinear functions which map points in the neighborhood of z1 to points in the neighborhood of z3 . By composing k times, a pair of bilinear functions can be obtained which map points in the neighborhood of z1 to points in the neighborhood of zq . This pair of functions is called the projection function of z1 . Observe that the coefficients of the projection function of z1 depend on the vertices and edges of the link sequence of z1 . This multiple composition shows that there is a unique function for each interval of bdp (z1 , z2 ) and it takes constant time to evaluate the function. Exercise 7.5.2 Prove that given the coefficients of a projection function, its fixed point can be computed in O(1) time [69]. Once the projection functions for each interval of bdp (z1 , z2 ) are composed, it can be checked whether there is a fixed point u1 of the projection function of any interval on bdp (z1 , z2 ) (see Figure 7.13(b)). The fixed point of a projection function can be found in O(1) time by finding eigenvalues and their corresponding eigenvectors of the matrix formed by the coefficients of the projection function [69]. We have the following theorem. Theorem 7.5.5 Given two convex polygons P and Q with a total of n vertices (Q ⊂ P ), a minimum nested polygon K between P and Q can be computed in O(nk) time, where k is the number of vertices of K. It can be seen that the above algorithm runs in O(nk) time because the number of backward projection points in a reverse greedy path can be at most k. We show that it is possible to restrict the number of backward projection points to log k using projection functions and a divide and conquer strategy. In presenting our divide
246
Visibility and Link Paths
and conquer algorithm, we adopt the method of merging intervals as suggested by Chandru et al. [69]. Let us define regions R1 , R2 , . . . , Rq with respect to the greedy path z1 z2 , z2 z3 , . . . , zq zq+1 , where zq zq+1 intersects z1 z2 (see Figure 7.14(b)). Without loss of generality, we assume that z1 is p1 . We also assume that z1 z2 and zq zq+1 are tangential to Q at vertices q1 and ql respectively. The counterclockwise boundary of Q from a vertex qr to a vertex qt is denoted as bdq (qr , qt ). Let R1 denote the region of R bounded by the segment q1 z1 , bdp (z1 , z2 ) and the segment z2 q1 (see Figure 7.14(b)). So, the initial intervals on bdp (z1 , z2 ) are p1 p2 , p2 p3 , . . . , pi z2 , where z2 belongs to the edge pi pi+1 . The endpoints of the intervals are stored in the list A1 in counterclockwise order, where the first and last elements in A1 are z1 and z2 . Assume that z2 z3 is tangential to Q at the vertex qj . Let R2 denote the region of R bounded by the segment q1 z2 , bdp (z2 , z3 ), the segment z3 qj and bdq (q1 , qj ) (see Figure 7.14(b)). Extend the edges in bdq (q1 , qj ) to bdp (z2 , z3 ) and insert the extension points on bdp (z2 , z3 ), which divides edges of bdp (z2 , z3 ) into intervals. The endpoints of intervals on bdp (z2 , z3 ) are then stored in the list A2 in counterclockwise order, where the first and last elements in A2 are z2 and z3 . The regions R3 , R4 , . . . , Rq and the intervals on their boundaries are defined analogously. Note that R1 , R2 , . . . , Rq−1 are disjoint, whereas R1 and Rq are overlapping. Starting from A1 , final intervals on bdp (z1 , z2 ) can be computed by combining R1 , R2 , . . . , Rq as follows. Firstly, intervals on bdp (z1 , z2 ) are computed in R1 ∪ R2 . It can be seen that backward projection points of A2 on bdp (z1 , z2 ) and points in A1 can be merged according to their counterclockwise order to form intervals on bd p (z1 , z2 ) in R1 ∪ R2 (see Figure 7.14(b)). The endpoints of these intervals are again stored in A1 . Moreover, projection functions of all intervals in R1 ∪R2 are composed and they map points of an interval on bdp (z1 , z2 ) to points in the corresponding interval on bdp (z2 , z3 ). Since the forward projection points of A1 on bdp (z2 , z3 ) can always be computed using these projection functions, there is no need to store these forward projected points on bdp (z2 , z3 ) in A2 . Similarly, intervals on bdp (z3 , z4 ) in R3 ∪ R4 are computed using A3 and A4 , and the endpoints of these intervals are again stored in A3 along with the projection functions of these intervals. Let us compute intervals on bdp (z1 , z2 ) in R1 ∪R2 ∪R3 ∪R4 . The task is to compute backward projection points of A3 on bdp (z1 , z2 ), which can be done in two steps. The backward projection points of A3 on bdp (z2 , z3 ) are first computed by drawing right tangents from points of A3 and extending them to bdp (z2 , z3 ) as in a reverse greedy path. Then, these backward projected points on bdp (z2 , z3 ) are projected backward on bdp (z1 , z2 ) using the inverse of the projection functions associated with A1 which map points of bdp (z1 , z2 ) to points of bdp (z2 , z3 ). Now, backward projection points of A3 on bdp (z1 , z2 ) and points in A1 can be merged according to their counterclockwise order to form intervals on bdp (z1 , z2 ) in R1 ∪ R2 ∪ R3 ∪ R4 . The endpoints of these intervals are again stored in A1 . The projection functions of intervals formed
7.5 Computing Minimum Nested Polygons
247
by points in A1 to intervals on bdp (z4 , z5 ) can be composed using the projection functions (i) from bdp (z1 , z2 ) to bdp (z2 , z3 ) (composed in R1 ∪R2 ), (ii) from bdp (z2 , z3 ) to bdp (z3 , z4 ) (composed after drawing right tangents in this iteration), and (iii) from bdp (z3 , z4 ) to bdp (z4 , z5 ) (composed in R3 ∪ R4 ).
Observe that the first set of backward projection points of A3 (on bdp (z2 , z3 )) have been computed by drawing right tangents and only then the last set of backward projection points (on bdp (z1 , z2 )) are computed using the inverse of the projection functions. During the merging step in general, the first and the last backward projection points in any reverse greedy path are computed and computation of all intermediate backward projection points in the path are skipped using the inverse of the projection functions. Therefore, at most log k backward projection points (or turning points) are computed in the reverse greedy path from a point on bd(P ) to bdp (z1 , z2 ), which helps in computing K in O(n log k) time.
The above process of computation can be repeated until the intervals on bd p (z1 , z2 ) are computed in R1 ∪R2 ∪. . .∪Rq−1 ∪Rq . In the following, we present the major steps of the algorithm for computing a minimum nested polygon K under the assumption that q is a power of 2. Step 1. Construct the greedy path z1 z2 , z2 z3 , . . . , zq−1 zq , zq zq+1 , where z1 ∈ bd(P ) and zq zq+1 intersects z1 z2 . Introduce points z1 , z2 , . . . , zq as vertices of P . Step 2. Construct the regions R1 , R2 , . . . , Rq with respect to the greedy path from z1 . Initialize the ordered lists A1 , A2 , . . . , Aq by the vertices of P and extension points of edges of Q to bd(P ). Assign q to j. Step 3. For i = 1 to j/2 do Step 3a. Compute the intervals on bdp (z2i−1 , z2i ) in R2i−1 ∪R2i by merging points in A2i−1 and the backward projection points of A2i on bdp (z2i−1 , z2i ) in counterclockwise order and store their endpoints in A2i−1 . Step 3b. Compose the projection functions in R2i−1 ∪ R2i of intervals on bdp (z2i−1 , z2i ) formed by the points in A2i−1 . Step 3c. Ri := R2i−1 ∪ R2i and Ai := A2i−1 .
Step 4. Step 5. Step 6. from
If j 6= 1 then j := j/2 and goto Step 3. Locate a fixed point u1 in an interval of bdp (z1 , z2 ). Construct a minimum nested polygon K by computing the greedy path u1 and Stop.
It can be seen that the above algorithm runs in O(n log k) time as Step 3 takes O(n) time and it is repeated log k times. We summarize the result in the following theorem.
248
Visibility and Link Paths
Figure 7.15 (a) Although P and Q are non-convex polygons, K is a convex polygon which contains the convex hull C of Q. (b) Rays are drawn from z through every vertex of C and V (z) to form wedges.
Theorem 7.5.6 Given two convex polygons P and Q with a total of n vertices (Q ⊂ P ), a minimum nested polygon K between P and Q can be computed in O(n log k) time, where k is the number of vertices of K.
7.5.2 Between Non-Convex Polygons: O(n) Algorithm In this section, we present two algorithms for computing a minimum nested polygon K between two given simple polygons P and Q given by Ghosh [155] and Ghosh and Maheshwari [159], where Q ⊂ P , n is the total number of vertices of P and Q and k is the number of vertices of K. If K is convex, the algorithm of Ghosh [155] computes K in O(n log k) time. If K is not convex, the algorithm of Ghosh and Maheshwari [159] computes K in O(n) time. As defined earlier, a simple polygon K is called nested between P and Q , when it circumscribes Q and is inscribed in P (i.e. Q ⊂ K ⊂ P ). The problem here is to compute a nested polygon K with the minimum number of vertices. We assume that the vertices of P and Q are labeled in counterclockwise order p1 , p2 , . . . , pm and q1 , q2 , . . . , ql , respectively, where m + l = n. The boundaries of P and Q are denoted as bd(P ) and bd(Q), respectively. It has been shown in Section 7.5.1 that if both P and Q are convex, K is also a convex polygon. If P or Q is not a convex polygon, K can still be a convex polygon as shown in Figure 7.15(a). Therefore, we first determine whether K is convex or not. This can be checked in O(n) time by the algorithm of Ghosh [155]. We start our presentation of Ghosh’s algorithm with the following lemma.
7.5 Computing Minimum Nested Polygons
249
Lemma 7.5.7 There exists a nested convex polygon between P and Q if and only if the boundary of P does not intersect the convex hull of Q. Proof. If bd(P ) does not intersect the convex hull of Q, there exists a point z ∈ bd(P ) such that both tangents from z to Q lie inside P . Since the entire boundary of P (including z) lies outside the convex hull of Q by assumption, the region of P enclosed by the two tangents of z and the convex hull of Q form a nested convex polygon. Let us prove the converse. If a nested convex polygon K exists, bd(P ) must lie in the exterior of K by definition. Since K is a convex polygon containing Q and the convex hull of Q is the smallest convex set containing Q, the convex hull of Q also lies inside K. Therefore, bd(P ) does not intersect the convex hull of Q. The above lemma suggests that it is necessary to check whether bd(P ) intersects the convex hull of Q (denoted as C), which can be done in O(n) time using the algorithm of Ghosh [151] for detecting the intersection between two star-shaped polygons. We state this algorithm in the following steps as presented in Ghosh [155]. Step 1. Compute the convex hull C of Q by the algorithm of Graham and Yao [175]. Step 2. Take a point z of Q and compute the visibility polygon V (z) of P from z by the algorithm of Lee [230] (see Section 2.2.1). Step 3. Divide the plane into wedges by drawing rays from z through every vertex of C and V (z) (Figure 7.15(b)). Step 4. Merge the angular order of vertices of C and V (z) around z to form the sorted angular order of wedges. Step 5. Check the intersection between the pair of edges in each wedge by traversing the wedges in sorted angular order around z. Step 6. If an intersection is detected then report that K is not a convex polygon else report that K is a convex polygon. Exercise 7.5.3 Let Q be a star-shaped polygon inside an arbitrary simple polygon P (Q ⊂ P ). Prove that the boundary of the visibility polygon of P from a point z in the kernel of Q intersects Q if and only if the boundary of P intersects Q [151]. The correctness and the time complexity of the above algorithm follow from Graham and Yao [175], Lee [230] and Ghosh [151]. We summarize the result in the following theorem. Theorem 7.5.8 Given two simple polygons P and Q with a total of n vertices (Q ⊂ P ), it can be determined in O(n) time whether there exists a convex nested polygon between P and Q.
250
Visibility and Link Paths
Let us consider the situation when K is convex. Before K can be computed, P is pruned to another polygon P 0 such that every nested convex polygon K lies inside P 0 . We have the following observation. Lemma 7.5.9 Let P 0 be the set of all points of P such that both tangents from any point z ∈ P 0 − C to C lie inside P . Every nested convex polygon K 0 between P and C lies inside P 0 . Proof. Let z be a point inside K 0 − C. Since K 0 is a convex polygon and lies inside P , two tangents drawn from z to C lie inside K 0 as well as P . Hence K 0 lies inside P 0 by the definition of P 0 . Corollary 7.5.10 Every minimum nested convex polygon K lies between P 0 and C. Exercise 7.5.4 Let C be a convex polygon inside a simple polygon P i.e. C ⊂ P . Let P 0 be the set of all points of P such that both tangents from any point z ∈ P 0 − C to C lie inside P . Design an O(n) time algorithm for computing P 0 , where n is the total number of vertices of P and C [155]. The polygon P 0 is called the complete visibility polygon of P from C. Since P 0 can be computed in O(n) time, a minimum nested polygon K between P 0 and C can be computed in O(n log k) time by the algorithm of Aggarwal et al. [12] (presented in Section 7.5.1). Note that though P 0 is not a convex polygon, the algorithm of Aggarwal et al. [12] can still be used as P 0 is completely visible from C as shown by Wang [336] and Wang and Chan [337]. In the following, we present the major steps for computing a convex nested polygon K. Step 1. Compute the convex hull C of Q by the algorithm of Graham and Yao [175]. Step 2. Check the intersection between bd(P ) and C by the algorithm of Ghosh [151]. If an intersection is detected then report that there is no convex nested polygon between P and Q and goto Step 5. Step 3. Compute the complete visibility polygon P 0 of P from C (see Exercises 3.8.1 and 7.5.3). Step 4. Construct a minimum nested convex polygon K between P 0 and C by the algorithm of Aggarwal et al. [12] and report K. Step 5. Stop. The correctness of the algorithm follows from Lemma 7.5.9, Theorem 7.5.8 and Aggarwal et al. [12]. Let us analyze the time complexity of the algorithm. We know that Steps 1, 2 and 3 can be performed in O(n) time. Step 4 takes O(n log k) time. Hence, the overall time complexity of the algorithm is O(n log k). We summarize the result in the following theorem.
7.5 Computing Minimum Nested Polygons
251
Figure 7.16 (a) The boundary of the relative convex hull Q0 of Q is the union of SPc (qs , qt ) and SPcc (qs , qt ). (b) A minimum nested non-convex polygon K is formed by the greedy path and the extensions of the eaves of Q0 .
Theorem 7.5.11 Given two simple polygons P and Q with a total of n vertices (Q ⊂ P ), a minimum nested convex polygon K between P and Q can be computed in O(n log k) time, where k is the number of vertices of K.
Let us consider the other situation where K is not convex. This means that bd(P ) has intersected the convex hull C of Q. So, a simple polygon Q0 ⊂ C is constructed such that Q0 is the smallest perimeter polygon inside P containing Q (see Figure 7.16(a)). This polygon Q0 is called the relative convex hull of Q with respect to P . Note that all vertices of C belong to Q0 . To compute Q0 , we need a triangulation of the region P − Q.
Without loss of generality, we assume that the vertex q1 of Q is a vertex of C (see Figure 7.16(a)). Extend q1 q2 from q1 meeting bd(P ) at a point q 0 on an edge pi pi+1 . Cut P −Q along q 0 q1 to construct a simple polygon (q2 , q1 , q 0 , pi+1 , pi+2 , . . . , pi , q 0 , q1 , ql , ql−1 , . . . , q2 ) and triangulate this polygon in O(n) time using the algorithm of Chazelle [71] (see Theorem 1.4.6). This triangulation can be considered a triangulation of P − Q with an additional vertex q 0 .
Let qs and qt be two vertices of C (see Figure 7.16(a)). It can be seen that there exists two disjoint paths in P − Q from qs to qt passing through two disjoint set of triangles Tc and Tcc in the triangulation of P − Q. Compute the Euclidean shortest path from qs to qt in Tc using the algorithm of Lee and Preparata [235] and call it SPc (qs , qt ). Similarly, compute the Euclidean shortest path from qs to qt in Tcc and call it SPcc (qs , qt ). It can be seen that the union of SPc (qs , qt ) and SPcc (qs , qt ) is the boundary of Q0 .
252
Visibility and Link Paths
Let Q0 = (u1 , u2 , . . . , ur , ur+1 , . . . , u1 ), where u1 = qs and ur = qt . As defined in Section 7.2.2, an edge uj−1 uj of Q0 is called an eave if uj−2 and uj+1 lie on the opposite side of the line passing through uj−1 and uj (see Figure 7.16(b)). Observe that there exists an eave on the boundary of Q0 as bd(P ) has intersected C. In the following lemmas, we present the main idea of the algorithm for computing K (see Figure 7.16(b)). Lemma 7.5.12 There exists a minimum nested polygon K between P and Q containing all eaves of Q0 . Proof. Proof follows along the line of the proof of Lemma 7.2.6. Lemma 7.5.13 The greedy paths inside P − Q connecting the extensions of eaves of Q0 form a minimum nested non-convex polygon K between P and Q. Exercise 7.5.5 Prove Lemmas 7.5.13. In the following, we present the major steps of the algorithm for computing K under the assumption that bd(P ) has intersected C. Step 1. Construct a triangulation of P − Q using the algorithm of Chazelle [71]. Step 2. Let qs and qt be two vertices of both Q and C. Compute SPc (qs , qt ) and SPcc (qs , qt ) inside P − Q by the algorithm of Lee and Preparata [235] and take their union to form the boundary of Q0 . Step 3. Extend each eave of Q0 from both ends to the boundary of P − Q. Step 4. Compute the greedy path inside P − Q connecting the extensions of every pair of consecutive eaves of Q0 by the algorithm of Ghosh [155] presented in Section 7.2.2. Step 5. Connect the greedy paths using the extension of eaves to construct a minimum nested polygon K and Stop. The correctness of the algorithm follows from Lemmas 7.5.12 and 7.5.13, and Theorem 7.5.8. Let us analyze the time complexity of the algorithm. We know that Steps 1 and 2 take O(n) time. Extensions of eaves of Q0 to the boundary of P − Q can be computed in Step 3 in O(n) time as shown in Section 7.2.2. Since the extension of eaves partitions P − Q into disjoint regions, the greedy paths in these regions can also be computed in O(n) time. Therefore, Step 4 takes O(n) time. Hence, the overall time complexity of the algorithm is O(n). We summarize the result in the following theorem. Theorem 7.5.14 Given two simple polygons P and Q with a total of n vertices (Q ⊂ P ), a minimum nested non-convex polygon K between P and Q can be computed in O(n) time.
7.6 Notes and Comments
253
Figure 7.17 (a) The path of bounded curvature from s to t is simple but not convex. (b) The path of bounded curvature is self-intersecting.
7.6 Notes and Comments Link paths going around a convex chain, like convex nested polygons, can be used to define isomorphism between points of two polygons. Note that in Section 6.9, isomorphism between two polygons is defined with respect to vertices of the polygons. Here, two simple polygons are called isomorphic if there is one-to-one mapping between their internal points (including vertices) that preserves visibility. Using link paths structure, MacDonald and Shermer [251] established necessary and sufficient conditions for isomorphism between two spiral polygons and gave an O(n2 ) time algorithm for detecting such isomorphism. Consider the following problem on path planning of a point robot, whose path is of bounded curvature. Given two points s and t inside a polygon P with or without holes and two directions of travel at s and t, the bounded curvature problem is to compute a path inside P from s to t consisting of straight-line segments (or links) and circular arcs such that (i) the radius of each circular arc is at least 1, (ii) each link on the path is the tangent between the two consecutive circular arcs on the path, (iii) the given initial direction at s is tangent to the path at s, and (iv) the given final direction at t is tangent to the path at t. Figure 7.17(a) shows that there exists a simple but non-convex path of bounded curvature from s to t. A path of bounded curvature is called convex if it makes only right turns or only left turns. Note that there is no convex and simple path of bounded curvature between s and t in the polygon of Figure 7.17(a). On the other hand, a path of bounded curvature may not always be simple as shown in Figure 7.17(b). For this problem, Agarwal et al. [10] proposed an O(n2 log n) time algorithm for computing a shortest path of bounded curvature in a convex polygon P without holes. If P is a simple polygon and there exists a convex and simple path of bounded curvature from s to t inside P , the path can be computed in O(n4 ) time
254
Visibility and Link Paths
by the algorithm of Boissonnat et al. [57]. Their algorithm computes the path exploiting the relationship between Euclidean shortest paths, link paths, paths of bounded curvature and complete visibility. These are the only two polynomial time algorithms known for this problem in a polygon with or without holes. Let us mention parallel algorithms for the minimum link path and nested polygon problems considered in this chapter. Consider the problem of computing the minimum link path M LP (s, t) between two given points s and t inside a simple polygon P . Chandru et al. [69] gave an algorithm for computing M LP (s, t) following the sequential algorithm of Ghosh [155, 156] (presented in Section 7.2.2), combining a divide and conquer strategy with projection functions in computing the greedy path. Their algorithm runs in O(log n log log n) time using O(n) processors in the CREW-PRAM model of computations. Using this algorithm, Chandru et al. [69] gave another algorithm for computing the minimum nested polygon between two simple polygons, which also runs in O(log n log log n) time using O(n) processors in the CREW-PRAM model of computations. Using the above algorithm of Chandru et al. [69], Ghosh and Maheshwari [161] showed that minimum link paths from a point in a simple polygon P to all vertices of P can be computed in O(log2 n log log n) time using O(n) processors in the CREWPRAM model of computations. They also gave an algorithm for computing the link center of a simple polygon P in O(log2 n log log n) time using O(n2 ) processors in the CREW-PRAM model of computations. Lingas et al. [245] gave parallel algorithms for rectilinear link paths in rectilinear polygons. Exercise 7.6.1 Design an O(n log n) time algorithm for locating a diagonal uw in a simple polygon P of n vertices such that the difference between the maximum link distances from uw to opposite sides of uw in P is at most one [111].
8 Visibility and Path Queries
8.1 Problems and Results Let q1 , q2 , . . . , qm be a set of internal points of a polygon P with holes with a total of n vertices. Consider the problem of computing visibility polygons of points q1 , q2 , . . . , qm in the polygon P . Since the visibility polygon of P from each point qi can be computed in O(n log n) time by the algorithm of Asano [27] (see Section 2.3), the problem can be solved in O(mn log n) time. Suppose m is quite large compared to n. In that case, it may be a good idea to construct data structures by processing P once so that the visibility polygon from each query point qi can be computed in less than O(n log n) time with the help of these data structures. In fact, it has been shown by Asano et al. [28] that after spending O(n2 ) time in preprocessing of P , the visibility polygon from each query point qi can be computed in O(n) time. Thus the overall time complexity for solving this problem is reduced from O(mn log n) to O(mn). Such problems, that require a large number of computations of similar type on the same polygonal domain, are known as query problems in computational geometry [291]. Efficiency of a query algorithm is judged on the basis of the query time of the algorithm, the space occupied by the data structure of the algorithm, and the time required during the preprocessing of the algorithm. Here, we consider query problems on visibility, shortest paths and link paths. Exercise 8.1.1 Design a query algorithm for determining whether a query point lies inside a convex polygon C of m vertices in O(log m) query time taking O(m) preprocessing time and space [291]. Let us start with the ray-shooting problem. Let q be a point inside a simple − polygon P . Let → q denote the ray from q in the given direction. Let q 0 be the closest − point of q among all the intersection points of → q with the boundary of P . So, the 0 0 − segment qq lies inside P and q is visible from q. For a given query → q in P , the 0 problem of ray shooting is to answer the query by locating q . We know that the visibility polygon V (q) of P from q can be computed in O(n) time by the algorithm 255
256
Visibility and Path Queries
of Lee [230] (see Section 2.2.1). So, by traversing the boundary of V (q), q 0 can be located in O(n) time. Chazelle and Guibas [76] first showed that q 0 can be computed in optimal O(log n) query time. Using the geometric transformation of point-line duality, they developed data structures for answering each ray-shooting query in optimal query time. To build the data structures, their algorithm requires preprocessing of P which takes O(n log n) time and O(n) space. Using hourglass structures, Guibas et al. [178] showed that the preprocessing time of P can be improved to O(n) keeping the query time and the space requirement unchanged. Using a different method, Chazelle et al. [73] later developed another query algorithm for the same problem which also answers each ray-shooting query in optimal O(log n) query time. Their algorithm requires O(n) preprocessing time and space. In a preprocessing step, P is decomposed into geodesic triangles. A region of P bounded by the shortest paths between three vertices of P is called a geodesic trian− gle. It has been shown by Chazelle et al. [73] that the path of → q in P can be traced 2 in O(log n) query time using this geodesic triangulation. The query time is then improved to O(log n) using a weight-balanced binary search tree [256] and a data structuring technique called fractional cascading [74, 75]. Soon after, Hershberger and Suri [190] showed an alternative method for answering a query in O(log n) query time using weight assignments in place of fractional cascading. Their query algorithm also requires O(n) preprocessing time and space. We present the query algorithms of Chazelle et al. [73] in Sections 8.2. Consider the ray-shooting problem in a polygon P with h holes. For a given query → − q in P , q 0 can be located in O(n) time by traversing the boundary of the visibility polygon V (q) of P . Since computing V (q) takes O(n log h) time [27] (see Section 2.3), each query can be answered in O(n log h) time. It has been shown both by Chazelle et al. [73] and √ Hershberger and Suri [190] that each ray-shooting query can be answered in O( h log n) query time, n is the total number of vertices √ where 3/2 of P . The preprocessing of P takes O(n h + h log h + n log n) time. The query time of their algorithms is an improvement by a factor of O(log n) over that of an earlier algorithm proposed by Agarwal [6]. Let q be a query point inside a simple polygon P . Consider the problem of reporting the visibility polygon V (q) of P from q (see Figure 2.1(a)). We know that V (q) can be computed in O(n) time without any preprocessing of P by the algorithm of Lee [230] (see Section 2.2.1). Recall that this algorithm always requires O(n) time even though the number of vertices of V (q) (say, k) is less than n, i.e., the algorithm is not output sensitive. Guibas et al. [181] showed that it is possible to report V (q) in O(log n + k) query time. During the preprocessing of P , their query algorithm decomposes P into visibility cells in O(n3 ) time and then these cells are stored using O(n3 ) space. Using a similar method of decomposing P into visibility cells, Bose et al. [60] developed another query algorithm which also reports V (q)
8.1 Problems and Results
257
in O(log n + k) query time. The algorithm takes O(n3 log n) preprocessing time and O(n3 ) space. If the query point q lies outside P , the algorithm can also report the external visibility polygon of P from q in the same query time. Representing P as an union of disjoint canonical pieces, Aronov et al. [26] showed that the preprocessing time and space requirement can be reduced to O(n2 log n) and O(n2 ), respectively. However, the query time of their algorithm increases to O(log 2 n + k). We present the query algorithm of Bose et al. [60] in Section 8.3.1. Consider the corresponding problem of reporting V (q) in a polygon P with h holes (see Figure 2.1(b)). We know that V (q) can be computed in O(n log h) time by the algorithm of Asano [27] (see Section 2.3). Asano et al. [28] first showed that V (q) can be reported in O(n) query time after preprocessing steps taking O(n 2 ) time and O(n2 ) space. Their query algorithm uses point-line duality to find the angular sorted order of vertices of P around q, and then uses triangulation and set-union operations to compute portions of edges of P that are visible from q. It may be noted that the query time of this algorithm is always O(n) even though the number of vertices of V (q) (of size k) may be less than n. Vegter [335] showed that the query time can be a function of the output size k. His query algorithm reports V (q) in O(k log(n/k)) query time after preprocessing steps taking O(n 2 log n) time and O(n2 ) space. Recently, Zarei and Ghodsi [346] showed that V (q) can be reported in O((1 + min(h, k)) log n + k) query time after preprocessing steps taking O(n3 log n) time and O(n3 ) space. If P is a convex polygon containing only convex holes, Pocchiola and Vegter [287] presented a query algorithm that reports V (q) in O(k log n) query time. During the preprocessing of P , their algorithm decomposes P into a visibility complex taking O(n log n + E) time and O(E) space, where E is the number of edges in the visibility graph of P . We present the query algorithm of Asano et al. [28] in Section 8.3.2. Let pq be a query segment inside a simple polygon P . Consider the problem of reporting the weak visibility polygon V (pq) of P from pq (see Figure 3.3(b)). We know that without preprocessing of P , V (pq) can be computed in O(n) time by the algorithm of Guibas et al. [178] (see Section 3.3.2). Aronov et al. [26] showed that V (pq) of size k can be reported in O(k log 2 n) query time after preprocessing steps taking O(n2 log n) time and O(n2 ) space. Recently, Bose et al. [60] showed that the query time can be reduced to O(k log n). However, their algorithm takes O(n 3 log n) preprocessing time and O(n3 ) space. Consider a related problem for a fixed segment pq inside P . Let u ∈ P be a query point. Let p0 q 0 ⊆ pq be the segment visible from u. The problem is to report p0 q 0 for each query point u. Guibas et al. [178] showed that p0 q 0 can be reported in O(log n) query time after P is processed taking O(n) time and O(n) space. Consider the query problem of reporting the Euclidean shortest path SP (s, t) between two points s and t inside a simple polygon P (see Figure 7.1(a)). If s is fixed and t is a query point, SP (s, t) can be reported in O(log n + k) query time
258
Visibility and Path Queries
by the query algorithm of Guibas et al. [178], where k is the number of edges in SP (s, t). The preprocessing step takes O(n) time and O(n) space as it involves computing the shortest path tree from s to all the vertices of P . If both s and t are query points, SP (s, t) can still be answered in O(log n + k) query time with O(n) preprocessing time and O(n) space as shown by Guibas and Hershberger [177]. The algorithm decomposes P into sub-polygons in a balanced fashion by diagonals in a triangulation of P and uses these sub-polygons to construct O(n) funnels and hourglasses in P . The funnels and hourglasses, that are lying in the path between s and t in P , are then combined to compute SP (s, t). This problem in a polygon with holes has been studied by Chen et al. [85] and Chiang and Mitchell [86]. We present the query algorithm of Guibas and Hershberger [177] for reporting SP (s, t) in Section 8.4.1. Consider the query problem of reporting the minimum link path M LP (s, t) between two points s and t inside a simple polygon P (see Figure 7.1(a)). If s is fixed and t is a query point, M LP (s, t) can be reported in O(log n + k) query time by the query algorithm of Suri [320], where k is the number of links in M LP (s, t). In the preprocessing step, the algorithm computes a window tree from s in P taking O(n) time and O(n) space and, using this tree, the query algorithm reports M LP (s, t) in O(log n + k) query time. If the query problem is to report just the link distance k between s and t and not the path, k can be reported in O(log n) query time by this algorithm of Suri. In fact, the problem of reporting k was considered earlier by ElGindy [126] and Reif and Storer [297]. Their query algorithms report k in O(log n) query time although the preprocessing time is O(n log n). If both s and t are query points, Arkin et al. [23] showed that k and M LP (s, t) can be reported in O(log n) query time and O(log n + k) query time, respectively. Preprocessing steps take O(n3 ) time and space. Reducing the preprocessing cost to O(n2 ), they showed that k can be reported in O(log n) query time with an error of at most 1. Related query problems on link paths between two simple polygons were studied by Arkin et al. [23] and Chiang and Tamassia [87]. Let us state the method used by the query algorithm of Arkin et al. [23] for computing M LP (s, t) in P . The algorithm computes window partitioning of P during preprocessing (i) from every vertex of P , and (ii) from every extension point on bd(P ) of edges of the visibility graph of P . It can be seen that endpoints of these windows divide edges of P into intervals and these intervals satisfy the property that the link sequence of the greedy link path in P from any point of an interval to a point of some other interval is the same. For every such pair of intervals, projection functions are composed which are used during queries for computing M LP (s, t). Adopting this method for computing M LP (s, t), we design a simpler query algorithm for this problem, which is presented in Section 8.4.2. Although the query time of our algorithm for computing M LP (s, t) remains O(log n + k),
8.2 Ray-Shooting Queries in Simple Polygons
259
preprocessing steps take O(n3 log n) time and space, which is a factor of O(log n) more than the cost in preprocessing of the query algorithm of Arkin et al. [23]. Query problems on shortest paths and minimum link paths in L1 metric are studied for rectilinear polygons. As defined earlier, P is a rectilinear polygon if the internal angle at every vertex of P is 90◦ or 270◦ . Consider the query problem of reporting the rectilinear shortest path RSP (s, t) between two points s and t inside a simple rectilinear polygon P . RSP (s, t) can be reported in O(log n + k) query time by the query algorithm of de Berg [108], where k is the number of edges in RSP (s, t). Preprocessing steps take O(n log n) time and O(n log n) space. Later, Lingas et al. [245] and Schuierer [303] reduced the preprocessing cost to O(n) keeping the same query time. If both s and t are vertices of P , the query time of their algorithms becomes O(1 + k). Their method computes the rectilinear path which is optimal in both L1 and the rectilinear link metric (known as the smallest path [254]). For the corresponding query problems on rectilinear link paths, the same query time and preprocessing cost can be achieved using the query algorithms of de Berg [108], Lingas et al. [245] and Schuierer [303]. The shortest path query problem in P with rectilinear holes was studied by Atallah and Chen [33, 34], Chen et al. [80] and ElGindy and Mitra [130]. The corresponding query problem on rectilinear link paths was studied by Das and Narasimhan [102] and de Rezende et al. [109].
8.2 Ray-Shooting Queries in Simple Polygons In this section, we present the query algorithm of Chazelle et al. [73] for answering ray-shooting queries inside a simple polygon P . The ray-shooting problem is to − locate the intersection point q 0 of a given query → q with bd(P ) such that q 0 is visible − from q. The algorithm of Chazelle et al. answers each ray-shooting query → q in op0 timal O(log n) query time by locating q . The algorithm partitions P into geodesic triangles and using this triangulation, a query can be answered in O(log 2 n) query time. The query time is then improved to O(log n) using a weight-balanced binary tree [256] and fractional cascading [74, 75]. Preprocessing steps require O(n) time and O(n) space. The algorithm of Chazelle et al. [73] used the query algorithm of Guibas and Hershberger [177] (presented in Section 8.4.1) for decomposing P into geodesic triangles in O(n) time. Here we use a different method for this decomposition. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. The algorithm starts by partitioning P into a balanced geodesic triangulation. Compute shortest paths (i.e., geodesic paths) SP (v1 , vbn/3c ), SP (vbn/3c , vb2n/3c ) and SP (vb2n/3c , v1 ) (see Figure 8.1). Taking the middle vertex vbn/6c of bd(v1 , vbn/3c ), compute SP (v1 , vbn/6c ) and SP (vbn/6c , vbn/3c ). Analogously, taking middle vertices vbn/2c and vb5n/6c of bd(vbn/3c , vb2n/3c ) and bd(vb2n/3c , v1 ), respectively, compute (i) SP (vbn/3c , vbn/2c ) and SP (vbn/2c , vb2n/3c ), (ii) SP (vb2n/3c , vb5n/6c ) and
260
Visibility and Path Queries
Figure 8.1 The polygon P is partitioned into geodesic triangles up to the stage k = 2.
SP (vb5n/6c , v1 ). Repeat this process of computing shortest paths taking middle vertices till the shortest paths connect pairs of vertices, one vertex apart. So, these shortest paths partition P into disjoint regions called geodesic triangles of P . Observe that since the boundary of a geodesic triangle is formed by three shortest paths, each shortest path contributes a reflex chain of vertices on the boundary of the triangle. It can be seen that the total number of shortest path edges used for partitioning P into geodesic triangles cannot not exceed n − 3. Exercise 8.2.1 Let R be the region of P bounded by bd(v1 , vbn/3c ) and SP (v1 , vbn/3c ). Prove that SP (v1 , vbn/6c ) and SP (vbn/3c , vbn/6c ) lie totally inside R. Exercise 8.2.2 Design an algorithm to partition P into geodesic triangles in O(n log n) time. Let u1 , ubn/3c and ub2n/3c be three vertices of P (see Figure 8.1) such that (i) SP (vbn/3c , v1 ) and SP (vb2n/3c , v1 ) meet at u1 , (ii) SP (v1 , vbn/3c ) and SP (vb2n/3c , vbn/3c ) meet at ubn/3c , and (iii) SP (v1 , vb2n/3c ) and SP (vbn/3c , vb2n/3c ) meet at ub2n/3c . If u1 is same as v1 , this means that SP (vbn/3c , v1 ) and SP (vb2n/3c , v1 ) are disjoint. Similarly, it is possible to have ubn/3c = vbn/3c or ub2n/3c = vb2n/3c . It can be seen that the region of P enclosed by SP (u1 , ubn/3c ), SP (ubn/3c , ub2n/3c ) and SP (ub2n/3c , u1 ) is a geodesic triangle. We refer SP (v1 , u1 ), SP (vbn/3c , ubn/3c ) and SP (vb2n/3c , ub2n/3c ) as tails of this geodesic triangle. A geodesic triangle along with its three tails is called a kite. A kite may have an empty geodesic triangle if the shortest path between two end vertices of the kite passes though the third end vertex of the kite. It can be seen that each kite appears at a unique stage k while partitioning P into geodesic triangles. For example, the kite with end vertices v1 , vbn/3c and vb2n/3c
8.2 Ray-Shooting Queries in Simple Polygons
261
Figure 8.2 (a) The polygon P is decomposed into kites τ0 , τ1 , τ2 , τ3 , τ4 , τ5 , τ6 , τ7 , τ8 , τ9 . (b) Kites of the polygon P are represented in the geodesic tree.
appear when k = 1 (see Figure 8.1). Observe that for k > 1, one of the sides of a kite at stage k shares an edge with a kite at stage k − 1 and the other two sides share edges with two kites at stage k + 1 (if they exist). At the kth stage, there are at most 3.2k−1 shortest paths and some of these shortest paths share edges with shortest paths computed at earlier stages. We have the following observation. Lemma 8.2.1 The number of kites constructed at the k-th stage during the partition of P is 1 for k = 1 and at most 3.2k−2 for k > 1. Let us represent the kites of P computed by the above method by a free tree of degree 3 called the geodesic tree, which is denoted as GT (see Figure 8.2). The kite computed in the first stage is represented as the root of GT and the three kites at stage k = 2 are represented as children of the root of GT as each of them share an edge with the kite at stage k = 1. Similarly, the kites at stage k are represented as nodes of GT at depth k − 1 with their parents at depth k − 2. We have the following lemma. Lemma 8.2.2 The height and diameter of GT are at most log n and 2 log n, respectively. Observe that after P is partitioned into geodesic triangles, a non-polygonal edge in the partition is shared by two geodesic triangles but the same edge can be present in the tails of several kites. For example, the edge v1 v2 in Figure 8.2(a) is shared by kites τ0 , τ1 , τ2 and τ5 . Therefore, if a node α of GT corresponds to a kite τ , then only the geodesic triangle of τ is stored at α and not the tails of τ . This method helps in keeping the space complexity linear as each non-polygonal edge of the partition
262
Visibility and Path Queries
is stored twice. So, GT can also be viewed as a representation of geodesic triangles of P . We have the following lemma. − Lemma 8.2.3 A query → q intersects at most 2 log n geodesic triangles (or kites) in P. − Proof. Let q 0 be the boundary point of P hit by → q (see Figure 8.2(a)). In order to 0 0 reach from q to q , the segment qq has intersected geodesic triangles of P that are on the path in GT , where the the first and last nodes of GT represent the geodesic triangles containing q and q 0 , respectively. Since the number of such triangles intersected by qq 0 is at most the diameter of GT (see Figure 8.2(b)), qq 0 can intersected at most 2 log n geodesic triangles of P by Lemma 8.2.2. The above proof suggests a method for locating q 0 as follows. Locate the geodesic triangle α1 containing q. Using binary search on each concave side of α1 , locate − the edge of α1 intersected by → q . Let w be the point of intersection. If the edge containing w is a polygonal edge, w is q 0 . Otherwise, w is the entry point to the − next geodesic triangle α2 in the path from q to q 0 . Let → w be the ray starting from → − the point w in the same direction as q . Using binary searches again on the concave − sides of α2 , locate the intersection point of → w with the boundary of α2 . This process 0 is repeated until q is found. Let us analyze the time complexity of the above method. It has been shown by Edelsbrunner et al. [119] and Kirkpatrick [216] that by preprocessing a planar subdivision of triangles of having n edges in O(n) time, data structures can be built so that a query point can be located in the planar subdivision in O(log n) time. Note that the geodesic triangles in P can be partitioned into triangles in O(n) time. Using this method, the geodesic triangle α1 containing q can be located in O(log n) − time. We know that the binary search for checking the intersection of → q with a side of a geodesic triangle can be performed in O(log n) time. We also know from − Lemma 8.2.3 that → q intersects at most 2 log n geodesic triangles of P . Therefore, 0 q can be located in O(log2 n) time. We have the following theorem. Theorem 8.2.4 A given simple polygon P of n vertices can be preprocessed in − O(n log n) time and O(n) space so that each ray-shooting query → q in P can be 2 answered in O(log n) query time. Let us explain how the query time can be improved to O(log n). Let α1 , α2 , . . . , αm be the geodesic triangles intersected by qq 0 in the order from q to q 0 , where q ∈ α1 , q 0 ∈ αm and m ≤ 2 log n. For any geodesic triangle αi for 1 ≤ i ≤ m, the concave − chain of αi intersected by → q is called the front chain of αi (see Figure 8.3(a)). Note → − that if q intersects two concave chains of αi , the closer one is the front chain of − αi . Consider the other two chains of αi . If there exists a parallel line of → q which is tangential to one of the chains of αi , the chain is called the side chain of αi (see
8.2 Ray-Shooting Queries in Simple Polygons
263
Figure 8.3 (a) The front and side chains of a geodesic triangle αi are shown with respect to a query ray. (b) The segment rs lies inside P .
Figure 8.3(a)). The problem is now to identify front chains of α1 , α2 , . . . , αm and − then locate intersection points of → q with these chains. Moreover, the entire task has to be carried out in O(log n) time. − The intersection point of → q with the front chain of αi on some edge v vr can l
be located using a binary search. It can be seen that the total number of binary searches required to locate subsequent intersection points depends on the size of the pocket of vl vr , where the pocket of vl vr is bd(vl , vr ) (or bd(vr , vl )) if q 0 ∈ bd(vl , vr ) (respectively, q 0 ∈ bd(vr , vl ). So, we use a weight-balanced binary tree, with each leaf, representing an edge of the front chain and being weighted by the number of vertices in the pocket of the corresponding edge of the chain. In this tree, the cost of locating vl vr is O(1 + log(W/w)), where w is the size of the pocket of vl vr and W is the total size of all pockets of the front chain of αi . Let n1 , n2 , . . . , nm be the − size of the successive pockets into which → q enters. Then, the cost of locating q 0 is bounded by log n +
X j
log
nj nj+1
which is O(log n). − The above analysis is based on the assumption that every time → q enters into a geodesic triangle, it can be determined in O(1) time which is the front chain of the geodesic triangle before the intersection point is computed on the chain by binary search. So, it is necessary to calculate the cost of identifying side chains of α1 , α2 , . . . , αm . For each geodesic triangle α of P , create a fictitious node and link it to the three roots of weight balanced binary trees representing the three concave sides of α. It can be seen that each non-polygonal edge of a geodesic triangle is a leaf
264
Visibility and Path Queries
in two such trees. All such pairs of leaves are also connected by edges giving a big free tree whose every node has degree at most three. For each geodesic triangle α, an array representing the slopes of all edges of α is assigned to the node representing α in the big free tree. This gives the fractional cascading structure which allows searching along a path of length m in O(m + log n) time [74, 75]. Since m can be at most 2 log n by Lemma 8.2.3, q 0 can be located in O(log n) time. We have the following lemma. − Lemma 8.2.5 Each ray-shooting query → q in P can be answered in O(log n) time using fractional cascading. In the following we present the major steps of the query algorithm for locating q 0 . Step 1. Partition P into geodesic triangles and construct the geodesic tree GT . Step 2. Construct the data structure by the algorithm of Kirkpatrick [216] for locating a query point in the geodesic triangle. Step 3. Represent each side of every geodesic triangle α by a weight balanced binary tree and connect them to form a big free tree. Step 4. For each geodesic triangle α, construct the array representing the slopes of all edges of α and then assign it to the node representing α in the big free tree. − Step 5. For each query → q do Step 5a. Locate the geodesic triangle of P containing the point q. Step 5b. Using fractional cascading, locate the point q 0 . Step 5c. Report q 0 . Step 6. Stop. The correctness of the algorithm follows from Theorem 8.2.4 and Lemma 8.2.5. Let us analyze the time complexity of the algorithm. It has already been established in Lemma 8.2.5 that q and q 0 can be located in Step 5 in O(log n) time. We know that the data structures in Steps 2, 3 and 4 can be constructed in O(n) time. Partitioning P into geodesic triangles in Step 1 can also be done in O(n) time as follows. Compute SP T (v1 ) by the algorithm of Guibas et al. [178] in O(n) time (see Section 3.6.1). So, SP (v1 , vbn/3c ) and SP (v1 , vb2n/3c ) have been computed. To complete the computation of the geodesic triangle at the first stage, SP (v bn/3c , vb2n/3c ) has to be computed. We take a different approach in computing SP (vbn/3c , vb2n/3c ). We know that vbn/2c is the middle vertex of bd(vbn/3c , vb2n/3c ) (see Figure 8.3(b)). Suppose SP (vbn/2c , vb2n/3c ) and SP (vbn/2c , vbn/3c ) are known. Then, SP (vbn/3c , vb2n/3c ) can be computed by drawing the tangent between SP (vbn/2c , vb2n/3c ) and SP (vbn/2c , vbn/3c ) provided the tangent (say, rs) lies inside P . Initialize r and s by the next vertex of vbn/2c on SP (vbn/2c , vbn/3c ) and SP (vbn/2c , vb2n/3c ) respectively. Note that if SP (vbn/2c , vbn/3c ) and
8.2 Ray-Shooting Queries in Simple Polygons
265
Figure 8.4 (a) The segment r 0 s0 is the cross-tangent between SP (v1 , w) and SP (vbn/3c , r). (b) The cross-tangent between SP (v1 , w) and SP (vbn/3c , r), does not lie inside P .
SP (vbn/2c , vb2n/3c ) meet at some vertex vj other than vbn/2c , then SP (vj , vbn/2c ) is common to both the paths. In that case, r and s are assigned to the next vertices of vj . Without loss of generality, we assume that vj is vbn/2c . We have the following four cases. − Case 1. The parent of s in SP T (v1 ) lies to the left of → rs and the parent → − SP T (v1 ) lies to the right of sr (Figure 8.3(b)). − Case 2. The parent of s in SP T (v1 ) lies to the right of → rs and the parent → − SP T (v1 ) lies to the right of sr (Figure 8.4). − Case 3. The parent of s in SP T (v1 ) lies to the left of → rs and the parent → − SP T (v1 ) lies to the left of sr (Figure 8.5(a)). − Case 4. The parent of s in SP T (v1 ) lies to the right of → rs and the parent → − SP T (v1 ) lies to the left of sr (Figure 8.5(b)).
of r in of r in of r in of r in
Consider Case 1. It can be seen that the current rs lies inside P (see Figure 8.3(b)). If rs is the tangent between SP (vbn/2c , vbn/3c ) and SP (vbn/2c , vb2n/3c ), then SP (vbn/3c , vb2n/3c ) is the concatenation of SP (vbn/3c , r), rs and SP (s, vb2n/3c ). Otherwise, if rs is not a tangent to SP (vbn/2c , vb2n/3c ) at s, then assign s to the next vertex of s on SP (vbn/2c , vb2n/3c ). Otherwise, assign r to the next vertex of r on SP (vbn/2c , vbn/3c ). Test the above four cases for the new rs. Consider Case 2. It can be seen that the current rs does not lie inside P (see Figure 8.4). This means that SP (v1 , vb2n/3c ) has intersected rs. Let ww 0 be the first edge on SP (vbn/2c , vb2n/3c ) while moving from s to vb2n/3c such that w 0 ∈ SP (w, vb2n/3c ) and w it is the parent of w 0 in SP T (v1 ) (see Figure 8.4(a)). Observe that w and its parent in SP T (v1 ) have formed an eave on SP (vbn/3c , vb2n/3c ), and w is the
266
Visibility and Path Queries
Figure 8.5 (a) The segment r 0 s0 is the cross-tangent between SP (v1 , u) and SP (vb2n/3c , s). (b) The segment r 0 s0 is the tangent between SP (v1 , u) and SP (v1 , w).
vertex where SP (r, vb2n/3c ) and SP (v1 , vb2n/3c ) meet. Locate the cross-tangent r 0 s0 between SP (v1 , w) and SP (vbn/3c , r), where s0 ∈ SP (v1 , w) and r 0 ∈ SP (vbn/3c , r). So, SP (vbn/3c , vb2n/3c ) is the concatenation of SP (vbn/3c , r0 ), r0 s0 , SP (s0 , w) and SP (w, vb2n/3c ). Observe that there may not always be a cross-tangent between SP (v 1 , w) and SP (vbn/3c , r) that lies inside P (see Figure 8.4(b)). In that case, a similar approach as above is taken by locating r 0 on SP (v1 , SP (vbn/3c ) instead of SP (vbn/3c , r). Therefore, r 0 s0 becomes the tangent (and not the cross-tangent) between SP (v1 , SP (vbn/3c ) and SP (v1 , SP (vb2n/3c ). The remaining task is to construct SP (vbn/3c , r0 ). Let u be the vertex where SP (r, vbn/3c ) and SP (r 0 , SP (vbn/3c ) meet. So, SP (vbn/3c , vb2n/3c ) is the concatenation of SP (vbn/3c , u), SP (u, r 0 ), r0 s0 , SP (s0 , w) and SP (w, vb2n/3c ). It can be seen that Case 3 is analogous to Case 2 (see Figure 8.5(a)). In Case 4, the tangent r 0 s0 is drawn between SP (v1 , SP (vbn/3c ) and SP (v1 , SP (vb2n/3c ) (see Figure 8.5(b)), and the remaining portions of SP (vbn/3c , vb2n/3c ) are constructed as before by locating vertices w and u on SP (s, vb2n/3c ) and SP (r, vbn/3c ), respectively. The above method shows that with the help of SP T (v1 ), SP (vbn/3c , vb2n/3c ) can be computed correctly from SP (vbn/2c , vb2n/3c ) and SP (vbn/2c , vbn/3c ). It can be seen that the time for computing SP (vbn/3c , vb2n/3c ) is proportional to the sum of (i) the number of vertices of SP T (v1 ) included in SP (vbn/3c , vb2n/3c ), and (ii) the number of vertices of SP (vbn/2c , vb2n/3c ) and SP (vbn/2c , vbn/3c ) not included in SP (vbn/3c , vb2n/3c ). The above method suggests that once the shortest paths between the vertices at the leaves of GT are computed, the entire geodesic partitioning of P can be computing by drawing tangents and cross-tangents with the help of SP T (v 1 ). Since
8.3 Visibility Polygon Queries for Points in Polygons
267
there can be at most one intermediate vertex between the pair of vertices at the leaf level of GT , all shortest paths at the leaf level of GT can be computed in O(n) time. Applying the above method at each intermediate node of GT , P can be partitioned into geodesic triangles in O(n) time. We have the following lemma. Exercise 8.2.3 Let vj be a vertex in the shortest path between a pair of vertices at some stage k > 1. Prove that if vj is not in the shortest path of any pair of vertices at the stage k − 1, then no shortest path at stages k 0 < k passes through vj . Lemma 8.2.6 A geodesic triangulation of P can be constructed in O(n) time. We summarize the result in the following theorem. Theorem 8.2.7 A given simple polygon P of n vertices can be preprocessed in − O(n) time and O(n) space so that each ray-shooting query → q in P can be answered in O(log n) query time.
8.3 Visibility Polygon Queries for Points in Polygons 8.3.1 Without Holes: O(log n + k) Query Algorithm In this section, we present the query algorithm of Bose et al. [60] for reporting the visibility polygon V (q) of a query point q inside a simple polygon P in O(log n + k) query time, where k is the number of vertices of V (q). The algorithm takes O(n3 log n) preprocessing time and O(n3 ) space. In a preprocessing step, the algorithm decomposes P into a set of disjoint regions and stores their adjacency relationship. To answer a query, the algorithm locates the region (say, ci ) containing the query point in O(log n) time, and then traverses a subset of regions starting from ci using the adjacency relationship to extract V (q), taking O(k) time. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. Consider the visibility polygon V (vj ) from a vertex vj . We know that each constructed edge vl u of V (vj ) defines a region or pocket of P that is not visible from vj (see Figure 8.6(b)). If the pocket is bounded by vl u and bd(vl , u), then the pocket and vl u are called a right pocket and a right constructed edge of V (vj ), respectively. Otherwise, the pocket and vl u are called a left pocket and a left constructed edge of V (vj ), respectively. The algorithm starts by decomposing P into disjoint regions called visibility cells. Compute visibility polygons V (v1 ), V (v2 ), . . . , V (vn ). Let Wj denote the set of all constructed edges of V (vj ). For all j, add Wj to P . These constructed edges decompose P into a planar subdivision C = (c1 , c2 , . . . , cm ), where each face ci of
268
Visibility and Path Queries
Figure 8.6 (a) Since q1 and q2 are two points in the same visibility cell ci , vertices in V (q1 ) and V (q2 ) are the same. (b) The disjoint regions of P − V (vj ) are pockets of V (vj ).
the subdivision C is called a visibility cell (see Figure 8.6(a)). We have the following observations. Lemma 8.3.1 For any two points q1 and q2 in any visibility cell ci of C, the vertices of P in V (q1 ) and V (q2 ) are the same. Proof. Assume on the contrary that there exists a vertex vp in P such that vp ∈ V (q1 ) but vp ∈ / V (q2 ). This means that q1 lies inside V (vp ) and q2 lies inside a pocket of V (vp ). Therefore, a constructed edge in V (vp ) has intersected ci with one part of ci containing q1 and the other part containing q2 . Hence, ci is not a visibility cell, which is a contradiction. Lemma 8.3.2 The number of visibility cells in the planar subdivision C is O(n 3 ). Proof. We know that the number of constructed edges in the visibility polygon of a vertex in P is O(n). So, the total number of constructed edges in V (v1 ), V (v2 ), . . . , V (vn ) is O(n2 ). Let vl u be a constructed edge in the visibility polygon of a vertex vj . It can be seen that at most two constructed edges of V (vi ) for i 6= j can intersect vl u. So, there are O(n) intersection points on vl u. Therefore, there are O(n3 ) intersection points on all constructed edges in V (v1 ), V (v2 ), . . . , V (vn ) giving the bound on the number of vertices and edges of C. Since C is a planar subdivision, the number of faces of C is O(n3 ). Hence, the number of visibility cells in the planar subdivision C is O(n3 ). Exercise 8.3.1 Draw a simple polygon P such that the number of visibility cells in the planar subdivision C of P is Ω(n3 ).
8.3 Visibility Polygon Queries for Points in Polygons
269
For every visibility cell ci , take a point qi ∈ ci and compute V (qi ) in O(n) time by the algorithm of Lee [230] (see Section 2.2.1). By Lemma 8.3.1, the vertices of V (q i ) are the vertices of the visibility polygon of any query point q lying in ci . However, the boundaries of V (qi ) and V (q) are not identical as constructed edges on the two boundaries are different. Let vl u be a constructed edge of V (qi ). Let vs vs+1 be the → intersects vs vs+1 at some edge of P containing the point u. It can be seen that − qv l point (say, u0 ) and vl u0 is a constructed edge of V (q). Thus, for every constructed edge in V (qi ), the corresponding constructed edge of V (q) can be computed. Hence, V (q) can be obtained from V (qi ) in time proportional to the size of V (q). Let us discuss the procedure for locating the visibility cell in C containing a query point q. The planar subdivision C can be constructed from constructed edges in O(n3 log n) time using sweep-line methods given in Edelsbrunner [117]. If constructed edges are in general position, C can be computed in O(n3 ) time by the algorithm of Chazelle and Edelsbrunner [72]. Since constructed edges may not be in general position, the cost of computing C is considered O(n3 log n) time. After this construction, C is preprocessed for planar point location in O(n3 log n) time by the algorithm of Kirkpatrick [216]. After this preprocessing, the visibility cell in C containing a query point q can be located in O(log n) time. In the following, we present the major steps of the query algorithm for computing V (q) in P . Step 1. Compute visibility polygons V (v1 ), V (v2 ), . . . , V (vn ) by the algorithm of Lee [230] and form the set W containing all constructed edges of these visibility polygons. Step 2. Compute the planar subdivision C using constructed edges in W by the algorithm given in Edelsbrunner [117]. Step 3. Construct the data structure for locating a query point in C by the algorithm of Kirkpatrick [216]. Step 4. For every visibility cell ci of C, take a point qi ∈ ci and compute V (qi ) by the algorithm of Lee [230]. Step 5. For each query point q do Step 5a. Locate the visibility cell ci of C containing the point q. Step 5b. Compute V (q) from V (qi ). Step 5c. Report V (q). Step 6. Stop. Theorem 8.3.3 A given simple polygon P of n vertices can be preprocessed in O(n 4 ) time and O(n4 ) space so that the visibility polygon V (q) of each query point q in P can be computed in O(log n + k) query time, where k is the number of vertices of V (q).
270
Visibility and Path Queries
Figure 8.7 (a) The dual graph G of C. (b) Each edge of G is assigned a direction to indicate the loss of a visible vertex.
It can be seen that the preprocessing cost of the above algorithm is dominated by the cost of computing visibility polygons from O(n3 ) points q1 , q2 , . . . , qm in Step 4. In order to reduce the cost, we modify the algorithm showing that it is enough to compute visibility polygons from one representative point of O(n2 ) visibility cells having special properties. Let cj be a visibility cell in C (see Figure 8.7(a)) such that for every adjacent visibility cell ct of cj , qt sees all vertices of V (qj ), where qt and qj are points of ct and cj , respectively, and in addition, qt sees one more vertex of P (say, vf ). Intuitively, if the segment separating cj and ct is crossed from cj to ct , one more vertex becomes visible. Observe that the segment separating cj and ct is a part of a constructed edge of V (vf ) and cj lies inside the pocket of that constructed edge. All visibility cells of C satisfying the property of cj are referred to as minimal visibility cells. We have the following observation. Lemma 8.3.4 The number of minimal visibility cells in C is O(n2 ). Proof. Let vl u be a constructed edge of V (vs ) (see Figure 8.7(a)). Let ab be a boundary segment of a minimal visibility cell cj such that ab is a part of vl u. Without loss of generality, we assume that vl u is a left constructed edge of V (vs ). Let bc be the next clockwise segment of ab on the boundary of cj and it is a part of a constructed edge vh w of V (vf ). Since cj is a minimal visibility cell, cj lies in the pocket of V (vs ) as well as in the pocket of V (vf ). Observe that since vh w has intersected vl u, vh w does not intersect any other left constructed edge of V (vs ) as pockets in a visibility polygon are disjoint. This observation suggests that although there can be O(n2 ) intersection points on all left constructed edges of V (vs ), only O(n) intersection points can be on the boundary of minimal visibility cells that are also points on left constructed edges of V (vs ). The same bound holds for right
8.3 Visibility Polygon Queries for Points in Polygons
271
constructed edges of V (vs ). Since there are n visibility polygons, there are O(n2 ) minimal visibility cells in C. Exercise 8.3.2 Draw a simple polygon P such that the number of minimum visibility cells in the planar subdivision C of P is Ω(n2 ). Let us identify minimal visibility cells from the dual graph G of C. Represent every visibility cell of C as a node in G and connect two nodes by an edge in G if and only if their corresponding visibility cells are adjacent in C (see Figure 8.7(a)). Let ab be a segment on the boundary of two adjacent visibility cells ct and cg (see Figure 8.7(b)), where ab is a part of a constructed edge of the visibility polygon of some vertex vs . We know that vs is visible from every point of one of ct and cg (say, cg ) and is not visible from any point of other visibility cell ct . Assign a direction from cg to ct in the corresponding edge in G. Intuitively, a directed edge in G represents the loss of a visible vertex in the direction from one visibility cell to its adjacent visibility cell. We have the following observation. Lemma 8.3.5 If there is no outward edge from a node in G, the corresponding visibility cell of the node is a minimal visibility cell in C (Figure 8.7(b)). For every minimal visibility cell cj , take a point qj ∈ cj and compute V (qj ) in O(n) time by the algorithm of Lee [230] (see Section 2.2.1). Note that O(n2 ) visibility polygons can be computed in O(n3 ) time. Let ci be the visibility cell containing the query point q. If ci is a minimal visibility cell ci , V (q) can be computed from V (qi ) as stated earlier. Consider the other situation when ci is not a minimal visibility cell (see Figure 8.7(b)). Consider any directed path α in G from the node representing c i to a node representing a minimal visibility cell (say, cj ). Let ct be the next visibility cell of cj on α. Let vf be the vertex of P such that the boundary segment separating cj and ct is a part of a constructed edge vl u of V (vf ). We know that vl belongs to V (qj ). If vl u is a right (or, left) constructed edge, insert vf in V (qj ) as the next clockwise (or counterclockwise) vertex of vl to obtain V (qt ), where qt ∈ ct . If vl vf is not a polygonal edge, add the appropriate constructed edge at vl to V (qt ). Take the next visibility cell cg of ct on α and compute V (qg ) from V (qt ). Repeat this process till V (q) is computed. It can be seen that the length of α is less than k and therefore, V (q) can be computed from V (qj ) in O(k) time. We have the following lemma. Lemma 8.3.6 The visibility polygon V (q) can be computed from the visibility polygon from a point in a minimal visibility cell using the dual graph G of C in O(k) time. In the following, we present the major steps of the modified query algorithm for computing V (q) in P .
272
Visibility and Path Queries
Step 1. Compute visibility polygons V (v1 ), V (v2 ), . . . , V (vn ) by the algorithm of Lee [230] and form the set W containing all constructed edges of these visibility polygons. Step 2. Compute the planar subdivision C using constructed edges in W by the algorithm given in Edelsbrunner [117]. Step 3. Construct the data structure for locating a query point in C by the algorithm of Kirkpatrick [216]. Step 4. Compute the dual graph G of C and assign a direction to each edge of G. Identify all minimal visibility cells in C using depth-first search on G. Step 5. For every minimal visibility cell cj of C, take a point qj ∈ cj and compute V (qj ) by the algorithm of Lee [230]. Step 6. For each query point q do Step 6a. Locate the visibility cell ci of C containing the point q. Step 6b. Take a directed path α in G from the node representing ci to a node representing a minimal visibility cell cj . Step 6c. Traverse α in the opposite direction and obtain V (q) by inserting the remaining visible vertices of q in V (qj ). Step 6d. Report V (q). Step 7. Stop. The correctness and the time complexity of the algorithm follow from Lemmas 8.3.2, 8.3.4 and 8.3.6. We summarize the result in the following theorem. Theorem 8.3.7 A given simple polygon P of n vertices can be preprocessed in O(n3 log n) time and O(n3 ) space so that the visibility polygon V (q) of each query point q in P can be computed in O(log n + k) query time, where k is the number of vertices of V (q).
8.3.2 With Holes: O(n) Query Algorithm In this section, we present the query algorithm of Asano et al. [28] for computing the visibility polygon V (q) of a query point q in a polygon P with holes (see Figure 8.8(a)). The algorithm reports V (q) in O(n) query time after preprocessing steps taking O(n2 ) time and O(n2 ) space. The algorithm uses point-line duality to find the sorted angular order of vertices of P around q, and then uses triangulation and set-union operations to compute portions of edges of P that are visible from q. It may be noted that the query time of this algorithm is always O(n) even though the number of vertices of V (q) may be less than n. As in the algorithm of Asano [27] for computing V (q) once for one point q (see Section 2.3), we need to sort the vertices of P in angular order around q. On the
8.3 Visibility Polygon Queries for Points in Polygons
273
Figure 8.8 (a) The visibility polygon V (q) of a query point q in a polygon P with holes. (b) Six regions are formed by lines d1 , d2 and d3 drawn through the sides of a triangle D.
other hand, the vertices of P cannot be sorted directly for every query point q as it costs O(n log n) time for each query point. Using the duality transform between points and lines, the sorted angular order of vertices of P with respect to any query point q can be obtained in O(n) query time. In the first preprocessing step of the algorithm, the vertices of P are transformed into lines in the dual plane forming an arrangement of lines. For more details of this transformation, see the proof of Lemma 5.3.2. The planar subdivision formed by this arrangement can be constructed in O(n2 ) time and space by the algorithm of Chazelle et al. [77] or Edelsbrunner et al. [120]. For any point u ∈ P , let L(u) denote the line in the the dual plane. Given a query point q, the line L(q) is inserted in the arrangement taking O(n) time. Observe that the line connecting q and a vertex vi of P in the original plane corresponds to the intersection point of L(q) and L(vi ) in the dual plane. By properties of the duality transformation, the ordering by slope of the lines passing through q and every vertex vi corresponds to the ordering by x-coordinates of intersection points of L(q) with every line L(v i ) in the dual plane. Using this property, the ordering of vertices of P in increasing order of angle at q can be obtained from their ordering of slopes in O(n) time. We have the following lemma. Lemma 8.3.8 The sorted angular order of vertices of P around a query point q can be computed in O(n) query time using O(n2 ) space and O(n2 ) preprocessing time. Once the sorted angular order of vertices of P around q is known, V (q) can be computed by angular sweep following the algorithm of Asano [27] (see Section 2.3). However, this method takes O(n log n) time. The query algorithm adopts a different method for computing V (q) and takes O(n) time.
274
Visibility and Path Queries
Figure 8.9 (a) Vertices v17 , v18 and v19 are introduced in P on the vertical ray drawn from q. (b) Each edge of Sq is represented on orthogonal axes as a horizontal segment.
The algorithm uses another preprocessing step for assigning ranks to edges of P with respect to q. Let ei and ej be two edges of P such that ei is closer to q than ej (see Figure 8.8(a)). Then the rank assigned to ej is greater than that of ei , i.e., rank(ei ) < rank(ej ). Let S denote the set of edges e1 , e2 , . . . , en of P . To assign ranks to all edges in S, we need a relation ≺q on S. For every pair of edges ei and ej in S, ei ≺q ej if a ray from q intersects both ei and ej and the intersection point with ei is closer to q than the intersection point with ej . Observe that the directed graph of the ≺q can have cycles, and therefore, ≺q may not be a partial order. To convert it to a partial order, each edge in S, intersecting the upward vertical ray from q, is split into two parts at the point of intersection (see Figure 8.9(a)). Let Sq denote the set of all edges of S including split edges of S. It can be seen that the relation ≺q is now a partial order on the edges of Sq . We have the following observation. Lemma 8.3.9 The rank of an edge in Sq is its rank in a total order compatible with the relation ≺q . Triangulate P by the algorithm of Ghosh and Mount [165] in O(n log n) time and O(n) space (see Section 5.3.2). Using the triangles, construct the data structure by the algorithm of Kirkpatrick [216] so that a query point q can be located in the triangle containing q in O(log n) query time. Also triangulate the internal region of
8.3 Visibility Polygon Queries for Points in Polygons
275
every hole of P by the algorithm of Ghosh and Mount. Let T (P ) denote the resulting triangulation of P and its holes (see Figure 8.8(a)). Note that the computation of T (P ) and the construction of the data structure for planar point location are done in preprocessing steps of the algorithm. Let us return to the discussion of assigning ranks to edges of Sq . The algorithm first computes a total order on the edges of T (P ) in which ≺q on Sq is embedded. Then, a total order on Sq is computed from the total order on the edges of T (P ). From the total order on Sq , ranks of edges in Sq are computed as suggested in Lemma 8.3.9. Connect q by diagonals to three vertices of the triangle containing q. Locate the triangles of T (P ) intersected by the vertical ray from q (see Figure 8.9(a)). Cut these triangles into two parts using this vertical ray and triangulate each non-triangular face by adding a diagonal. The resulting triangulation is denoted as Tq . It can be seen that the above method computes Tq from T (P ) in O(n) time and each edge of Sq is an edge of Tq . Let us construct a directed graph G(Tq ) on the edges of Tq . Consider a triangle D formed by triangulating edges d1 , d2 , and d3 of Tq (see Figure 8.8(b)). Let d1 , d2 and d3 denote the lines containing edges d1 , d2 , and d3 , respectively. Let h(d1 ), h(d2 ) and h(d3 ) denote the half-planes of d1 , d2 and d3 , respectively such that they do not contain D. Let R1 = h(d1 ) − (h(d2 ) ∪ h(d3 )). Similarly, let R2 = h(d2 ) − (h(d1 ) ∪ h(d3 )) and R3 = h(d3 ) − (h(d1 ) ∪ h(d2 )). Let R10 = h(d2 ) ∩ h(d3 ). Similarly, let R20 = h(d1 ) ∩ h(d3 ) and R30 = h(d1 ) ∩ h(d2 ). It can be seen that R1 , R2 , R3 , R10 , R20 , R30 and D are faces of the arrangement of lines d1 , d2 and d3 . Directed edges in G(Tq ) are introduced between d1 , d2 , and d3 depending upon the location of q in the arrangement of d1 , d2 and d3 as follows (see Figure 8.8(b)). Case 1. If q is an internal point of R1 , add edges from d2 to d1 and from d3 to d1 in G(Tq ) as rays from q intersect d1 before intersecting either d2 or d3 . The cases where q is an internal point of R2 or R3 are analogous. Case 2. If q is an internal point of R10 , add edges from d1 to d2 and from d1 to d3 in G(Tq ) as rays from q intersect either d2 or d3 before intersecting d1 . The cases where q is an internal point of R20 or R30 are analogous. Case 3. If q is a boundary point of both R2 and R30 , add an edge from d3 to d2 in G(Tq ) as rays from q intersect d2 before intersecting d3 . The cases where q is a boundary point of other faces (excluding D) are analogous. Case 4. If q ∈ D, add no edges to G(Tq ) as rays from q do not cross any pair of edges of D. Using the above four cases, all directed edges are introduced between edges in T q which gives G(Tq ). We have the following observation on G(Tq ).
276
Visibility and Path Queries
Lemma 8.3.10 The directed graph G(Tq ) is acyclic. Moreover, for every pair of edges ei and ej in Sq such that ei ≺q ej , there is a directed path from ej to ei in G(Tq ). Exercise 8.3.3 Prove Lemma 8.3.10. It can be seen that a topological order of G(Tq ) is a total order on Tq in which ≺q is embedded. Therefore, a total order on Sq can be obtained, which gives the ranking of edges in Sq by Lemma 8.3.9. Since the number of vertices and edges of G(Tq ) is O(n), the topological sort [221] as well as the ranking of edges in S q can be done in O(n) time. We have the following lemma. Lemma 8.3.11 For a query point q, the ranking of edges in Sq can be done in O(n) query time using O(n) space and O(n log n) preprocessing time. Let us label the edges e1 , e2 , . . . , em of Sq according to their ranks, where m < 2n. After relabeling, ei in Sq represents the edge with rank i, i.e., rank(ei ) = i. We also define ranks for two endpoints of ei according to their positions in the sorted angular order around q. For every edge ei of Sq , ai and bi denote the ranks of two endpoints of ei in the sorted angular order around q in the counterclockwise direction, where ai < bi . Let us identify the edges in Sq that are partially or totally visible from q. It can be seen that e1 is totally visible from q. Consider the next edge e2 . If no ray from q intersects both e1 and e2 , then e2 is also totally visible from q. In other words, if b2 < a1 or b1 < a2 , then e2 is also entirely visible from q. If every ray from q that intersects e1 also intersects e2 , then no point of e2 is visible from q. Otherwise, a part of e2 is visible from q. Consider the next edge e3 . Again, comparing with e1 and the visible portion of e2 , the portion of e3 visible from q can be determined. In this process, the visible portions of edges in Sq can be determined in O(n2 ) time. We show that the above method of considering edges in the increasing order of ranks can be implemented in O(n) time. Let us represent each edge ei of Sq on orthogonal axes as a horizontal segment si connecting two points with co-ordinates (ai , i) and (bi , i) (see Figure 8.8(b)). Consider the vertical line Li with ai as xcoordinate in the orthogonal representation of Sq . Let sj be the segment with the smallest y-coordinate (i.e., the lowest segment) intersected by Li . It can be seen that ej is partially or totally visible from q in P because ej is the edge with the smallest rank intersected by the ray drawn from q through the endpoint of e i which corresponds to ai . Therefore, the problem of computing V (q) now becomes the problem of computing the lowest segment at each x-coordinate in the orthogonal representation of Sq . This problem is solved using the set-union algorithm of Gabow and Tarjan [146]. The set-union algorithm starts with disjoints sets, and allows two operations f ind(k)
8.3 Visibility Polygon Queries for Points in Polygons
277
and l ink(k) on these sets. The operation f ind(k) returns the maximum element of the set containing k, and l ink(k) unites the set containing k with the set containing k + 1. The algorithm of Gabow and Tarjan can perform a sequence of f ind(k) and l ink(k) operations, on-line, in time proportional to the number of operations. In the context of identifying lowest segments, the set-union algorithm starts with Nx + 2 disjoint sets {0}, {1}, . . . , {Nx }, {Nx + 1}, where Nx is the maximum xcoordinate in the orthogonal representation of Sq . For any segment si , the operation f ind(k) takes ai as the value of k and locates the x-coordinate c such that (i) the lowest segments intersected by the vertical lines with x-coordinates from a i to c have already been computed, and (ii) the lowest segment intersected by the vertical line with c + 1 as the x-coordinate is yet to be computed. In other words, f ind(a i ) gives the leftmost x-coordinate that is at least ai and immediately to the right of which the lowest segment is not known. The set-union algorithm for determining lowest segments in the orthogonal representation of Sq is given below. The index i is initialized to 0. Step 1. Increment i by 1 and c := f ind(ai ). Step 2. While c < bi do begin visible(c) := si ; link(c); c := f ind(c) end. Step 3. If i < |Sq | then goto Step 1. Step 4. Report the visible segments of Sq by scanning the array visible[0..Nx ] and Stop. The above algorithm performs l ink(k) operation at most once for each x-coordinate. Observe that once l ink(c) is performed, the value c is never returned again by any f ind operation. Therefore, f ind and l ink operations are performed at most O(n) times. Hence, the above algorithm runs in O(n) time. We have the following lemma. Lemma 8.3.12 The lowest segments in the orthogonal representation of Sq can be determined in O(n) time. Once lowest segments and their order in the orthogonal representation of S q are known, V (q) can be constructed easily from their corresponding edges in P . In the following, we present the major steps of the query algorithm for computing V (q) in P. Step 1. Transform every vertex of P into a line in the dual plane and compute the planar subdivision A formed by the arrangement of these lines using the algorithm of Chazelle et al. [77]. Step 2. Triangulate P and its holes by the algorithm of Ghosh and Mount [165]. Step 3. Construct the data structure by the algorithm of Kirkpatrick [216] for locating a query point q in the triangle of the triangulation of P . Step 4. For each query point q do
278
Visibility and Path Queries
Step 4a. Transform q into a line L(q) in the dual plane and compute the intersection points of L(q) with edges in A. From the intersection points, obtain the sorted angular order of vertices P around q. Step 4b. Let T (P ) denote a copy of the triangulation of P and its holes. Locate the triangle of T (P ) containing q and add three diagonals connecting q to the vertices of the triangle. Cut the triangles of T (P ) that are intersected by the vertical ray from q, and triangulate each non-triangular face by adding a diagonal to obtain a new triangulation Tq . Step 4c. Form a directed graph G(Tp ) by assigning direction between edges of Tp using Cases 1 to 4. Step 4d. Take the polygonal edges of T (P ) to form the set Sq . Assign the ranks to edges in Sq from the total order in G(Tp ). Step 4e. Construct the orthogonal representation of Sq and find the lowest segments using the set-union operations f ind(k) and l ink(k). Step 4f. Compute V (q) using the lowest segments and their order. Step 4g. Report V (q). Step 5. Stop. The correctness and the time complexity of the query algorithm follow from Lemmas 8.3.8, 8.3.11 and 8.3.12. We summarize the result in the following theorem. Theorem 8.3.13 A polygon P with holes with a total of n vertices can be preprocessed in O(n2 ) time and space so that the visibility polygon V (q) of each query point q in P can be computed in O(n) query time.
8.4 Path Queries Between Points in Simple Polygons 8.4.1 Shortest Paths: O(log n + k) Query Algorithm In this section, we present the query algorithm of Guibas and Hershberger [177] for computing the Euclidean shortest path SP (s, t) between two query points s and t inside a simple polygon P . The algorithm computes SP (s, t) in O(log n + k) query time, where k is the number of edges in SP (s, t). Preprocessing steps take O(n) time and space. The algorithm decomposes P into sub-polygons in a balanced fashion by diagonals in a triangulation of P and uses these sub-polygons to construct O(n) funnels and hourglasses in P . The funnels and hourglasses lying in the path between s and t in P are then combined to compute SP (s, t). We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. The algorithm starts by decomposing P into sub-polygons. In order to compute SP (s, t) in O(log n + k) query time, P is decomposed in such a way that SP (s, t) passes through only a logarithmic number of sub-polygons. For decomposing P , the
8.4 Path Queries Between Points in Simple Polygons
279
Figure 8.10 (a) The polygon P is decomposed into triangles in a balanced fashion by diagonals d0 , d1 , . . . , d14 . (b) Additional edges are added to the decomposition tree Td to form the factor graph Td∗ .
polygon cutting theorem of Chazelle [70] is used recursively. The theorem states that any simple polygon P of n vertices for n ≥ 4 has a diagonal that divides P into two sub-polygons with at least ((n/3) + 1) vertices and at most (2(n/3) + 1) vertices. Applying the theorem recursively on each sub-polygon, P can be decomposed into triangles (see Figure 8.10(a)) and the decomposition is called a balanced decomposition of P . Exercise 8.4.1 Assume that the given polygon P has been triangulated. Design an algorithm for a balanced decomposition of P of n vertices in O(n log n) time [70]. We know that P can be triangulated in O(n) by the algorithm of Chazelle [71] (see Theorem 1.4.6). From the triangulation of P , a balanced decomposition of P can be computed in O(n) time by the algorithm of Guibas et al. [178]. We have the following lemma. Lemma 8.4.1 A balanced decomposition of P can be constructed by diagonals in a triangulation of P in O(n) preprocessing time. Let us construct a binary tree Td whose nodes represent diagonals used in the balanced decomposition of P (see Figure 8.10(b)). Let d0 be the diagonal used to cut P into two sub-polygons P1 and P2 . So, d0 is at the root of Td . Let d1 and d2 be the diagonals used to cut P1 and P2 , respectively. So, d1 and d2 are the children of d0 in Td . The children of d1 in Td are those diagonals that are used to cut two sub-polygons of P1 . Similarly, the children of d2 in Td are those diagonals that are used to cut two sub-polygons of P2 . In this fashion, the decomposition tree Td is constructed from the diagonals used in the balanced decomposition of P .
280
Visibility and Path Queries
Let P (d) denote the sub-polygon which has been cut by the diagonal d during the balanced decomposition of P . So, P (d0 ) is P , P (d1 ) is P1 and P (d2 ) is P2 . Let depth(d) denote the depth of the diagonal d in Td . So, P (d) has no more than O(( 23 )depth(d) n) vertices because of the balanced decomposition of P . This fact suggests the following lemma. Lemma 8.4.2 The height of Td is O(log n). We know that every time a sub-polygon P (d) is cut by a diagonal d into two subpolygons (say, P 0 (d) and P 00 (d)), d becomes an edge on the boundary of both P 0 (d) and P 00 (d). This implies that all the diagonals that are on the boundary of P (d) are ancestors of d in Td and therefore, there can be at most depth(d) diagonals on the boundary of P (d), which is O(log n). We state this fact in the following lemma. Lemma 8.4.3 The number of diagonals on the boundary of P (d) is at most depth(d). Let the diagonal d0 be the parent of d in Td . We know that d0 is a diagonal on the boundary of P (d), depth(d) > depth(d0 ), and depth(d0 ) is the largest among the depths of other diagonals on the boundary of P (d). Connect d by edges to all diagonals (including d0 ) on the boundary of P (d). Once such edges are added in Td for all d ∈ Td , the resulting graph is called the factor graph of Td and is denoted as Td∗ (see Figure 8.10(b)). We have the following lemmas on Td∗ . Lemma 8.4.4 The degree of a node in Td∗ is O(log n). Proof. For any diagonal d as a node in Td∗ , there are at most depth(d) edges in Td∗ connecting d to diagonals of lesser depth in Td∗ due to Lemma 8.4.3. Moreover, d has edges in Td∗ to diagonals of higher depth. Observe that once P (d) is cut by d, d is an edge on the boundary at most two sub-polygons at every level of subsequent decompositions and therefore, d has edges to at most two diagonals at each depth greater than depth(d) in Td∗ . Hence, the degree of d in Td∗ is O(log n). Lemma 8.4.5 The number of edges in Td∗ is O(n). Proof. Let d and d0 be two diagonals in Td∗ such that d0 is a leaf in the sub-tree of Td∗ rooted at d. Let height(d) denote the height of d in Td∗ . So, height(d) = depth(d0 ) − depth(d). If height(d) is h, it can be proved by induction that P (d) contains at least b( 23 )h−1 + 1c triangles of a triangulation of P (d). As the subpolygons corresponding to diagonals with the same height h are disjoint, there can be O(( 23 )h n) diagonals in Td∗ with height h. We know that Td∗ has n − 3 diagonals as nodes in Td∗ and from each diagonal d, there are 2 × height(d) edges to descendants in Td∗ as there are at most two edges from d to nodes at each depth in Td∗ . So, the number of edges in Td∗ is
8.4 Path Queries Between Points in Simple Polygons
X
d∈Td∗
2 × height(d) = O(
X
k≤1+log3/2 n
h
µ ¶h
2 3
281
n) = O(n).
Let us define separating diagonals in the triangulation of P . Consider any diagonal d in Td . We know that d partitions P into two sub-polygons. If query points s and t lie on different sub-polygons of d, then SP (s, t) must intersect d in order to reach t from s. Such diagonals d are called separating diagonals. In Figure 8.10(a), separating diagonals in the order from s to t are d3 , d1 , d9 , d4 , d10 , d0 , d11 , d5 , d12 . Note that separating diagonals may be different for different pairs of query points s and t. We have the following lemma. Lemma 8.4.6 There can be O(n) separating diagonals in Td for a pair of query points. Let ds (or dt ) denote the first (respectively, last) separating diagonal that is intersected by SP (s, t) while traversing from s to t. Let dmin denote the separating diagonal having minimum depth in Td . It can be seen that dmin is the least common ancestor of ds and dt in Td . In Figure 8.10, d3 , d0 and d12 are ds , dmin and dt respectively. All separating diagonals in the path in Td from ds to dmin and from dmin to dt (including ds , dt and dmin ) are called principal separating diagonals. The set of all principal separating diagonals in the order from ds to dt is denoted as Dst . In Figure 8.10(b), ds = d3 , dmin = d0 and dt = d12 and Dst = (d3 , d1 , d0 , d5 , d12 ). Note that d2 is not a principal separating diagonal although it is in the path from d12 to d0 in Td . On the other hand, although d9 is a separating diagonal, d9 is not a principal separating diagonal because d9 is not in the path from d3 to d0 in Td . We have the following lemmas. Lemma 8.4.7 There are at most O(log n) principal separating diagonals in D st . Proof. Since the diagonals in Dst in the order from ds (and dt ) to dmin are of strictly decreasing depth, there are O(log n) principal separating diagonals in D st due to Lemma 8.4.2. Lemma 8.4.8 Any two consecutive principal separating diagonals in Dst are connected by an edge in Td∗ . Proof. Let d and d0 denote two consecutive diagonals in Dst . We know that either d0 is an edge on the boundary of P (d) or d is an edge on the boundary of P (d 0 ). So, d and d0 are connected by an edge in Td∗ .
282
Visibility and Path Queries
Let us state the procedure for locating diagonals in Dst . Construct the data structure in O(n) preprocessing time by the algorithm of Kirkpatrick [216] for planar point location. Using this data structure, the triangles containing s and t in the triangulation of P are located in O(log n) query time. Let vi , vj and vk be the vertices of the triangle containing s. Assume that vk belongs to bd(vi , vj ). If vi vj is ds , then all three vertices of the triangle containing t belong to bd(vj , vi ), which can be tested in O(1) time by comparing the numbering of these vertices. Otherwise, similar tests are carried out for vj vk and vk vi to identify ds . Using the analogous method, dt can also be located in O(1) time. For every diagonal d from ds to dt in Td , check whether d is a separating diagonal. Thus, all principal separating diagonals in Dst are located in O(log n) query time. We state this fact in the following lemma. Lemma 8.4.9 All principal separating diagonals in Dst can be identified in O(log n) query time using O(n) preprocessing time and space. Once the diagonals in Dst are known, SP (s, t) is computed in O(log n) query time by ‘combining’ hourglasses formed by adjacent diagonals in Dst . Hourglasses for all pairs of diagonals connected by edges in Td∗ are computed during preprocessing so that the hourglasses formed by adjacent diagonals in Dst are readily available for computing SP (s, t). Before we explain how adjacent hourglasses can be combined in order to compute SP (s, t), we state a preprocessing step for computing hourglasses corresponding to edges of Td∗ . Let va vb and vc vd be two non-intersecting diagonals in P such that va , vb , vd and vc are in counterclockwise order on the boundary of P . Let H(ab, cd) be the region of P bounded by va vb , vc vd , SP (va , vc ) and SP (vb , vd ) (see Figure 8.11(a)). The region H(ab, cd) is called a hourglass in P for diagonals va vb and vc vd . We refer SP (va , vc ) and SP (vb , vd ) as the upper and lower chains of H(ab, cd), respectively. If SP (va , vc ) and SP (vb , vd ) are disjoint, H(ab, cd) is called an open hourglass (see Exercise 5.3.4). Otherwise, H(ab, cd) is called a closed hourglass as no point of va vb is visible from any point of vc vd (see Figure 8.11(b)). This implies that H(ab, cd) is the union of two funnels with bases va vb and vc vd , and the shortest path connecting apexes of these two funnels. We know that SP (va , vc ) and SP (vb , vd ) can be computed by the algorithm of Lee and Preparata [235] in time proportional to the number of vertices of H(ab, cd) (see Section 3.6.1). For every edge of Td∗ connecting diagonals d and d0 , the hourglass for d and d0 is constructed during preprocessing. Computing all these hourglasses takes O(n2 ) preprocessing time and space as there are O(n) edges in Td∗ by Lemma 8.4.5. Consider the problem of combining hourglasses for adjacent pairs of diagonals in Dst . Let va vb , vc vd and ve vf three consecutive diagonals in Dst in the order from s to t (see Figure 8.11(a)). As before, we assume that vf , vc , va , vb , vd and vf , are in counterclockwise order on the boundary of P . Consider the case where both H(ab, cd) and H(cd, ef ) are open hourglasses (see Figure 8.11(a)). The problem is
8.4 Path Queries Between Points in Simple Polygons
283
Figure 8.11 (a) Both H(ab, cd) and H(cd, ef ) are open hourglasses. (b) H(ab, cd) is a closed hourglass whereas H(cd, ef ) is an open hourglass.
to compute SP (va , ve ) and SP (vb , vf ). Draw the tangent between SP (va , vc ) and SP (vc , ve ). Let vi vj be the tangent where vi ∈ SP (va , vc ) and vj ∈ SP (vc , ve ). If vi vj lies inside P , then SP (va , ve ) is the concatenation of SP (va , vi ), vi vj and SP (vj , ve ). If the tangent between SP (vb , vd ) and SP (vd , vf ) also lies inside P (see Figure 8.11(a)), SP (vb , vf ) can be computed analogously. Consider the other situation where vi vj does not lie inside P . So, vi vj is intersected by SP (vb , vd ) or SP (vd , vf ) (see Figure 8.12). If the cross-tangent between SP (vb , vd ) and SP (vc , ve ) is incident on a vertex vh ∈ SP (vc , vj ) (see Figure 8.12(a)), then SP (vb , vd ) has intersected vi vj . Similarly, if the cross-tangent between SP (va , vc ) and SP (vd , vf ) is incident on a vertex vh ∈ SP (vi , vc ) (see Figure 8.12(b)), then SP (vd , vf ) has intersected vi vj . In such a situation, SP (va , ve ) is the concatenation of SP (va , vi ), SP (vi , vj ) and SP (vj , ve ). Note that H(ab, ef ) is a closed hourglass. If vi vj has been intersected by SP (vb , vd ) or SP (vd , vf ), SP (vi , vj ) can be computed using appropriate cross-tangents between lower and upper chains of H(ab, cd) and H(cd, ef ). Exercise 8.4.2 Let H(ab, cd) and H(cd, ef ) be two open hourglasses such that the tangent between upper chains is intersected by both lower chains. Draw H(ab, cd) and H(cd, ef ) and mark all edges (including tangents) of SP (va , ve ). Consider the case where H(ab, cd) is a closed hourglass and H(cd, ef ) is an open hourglass (see Figure 8.11(b)). We know that H(ab, cd) consists two funnels and the shortest path connecting the apexes of these two funnels. Let vg ∈ SP (va , vc ) be the apex of the funnel with base vc vd . Treating vg as both va and vb , draw the tangents and cross-tangents as stated in the previous case. Using these tangents, compute
284
Visibility and Path Queries
Figure 8.12 The tangent vi vj between upper chains of H(ab, cd) and H(cd, ef ) is intersected by the lower chain of (a) H(ab, cd) or (b) H(cd, ef ).
SP (vg , ve ) and SP (vg , vf ). So, SP (va , ve ) is the concatenation of SP (va , vg ), and SP (vg , ve ). Similarly, SP (vb , vf ) is the concatenation of SP (vb , vg ) and SP (vg , vf ). If H(ab, cd) is an open hourglass and H(cd, ef ) is a closed hourglass, they can be combined to form H(ab, ef ) using the method analogous to the previous case. If both H(ab, cd) and H(cd, ef ) are closed hourglasses, tangents are drawn between those two funnels having vc vd as the common base. Exercise 8.4.3 Let H(ab, cd) and H(cd, ef ) be two closed hourglasses. Draw H(ab, cd) and H(cd, ef ) and mark all edges (including tangents) of SP (va , ve ) and SP (vb , vf ). In the procedure for combining H(ab, cd) and H(cd, ef ), the query algorithm uses binary search for computing the tangent or a cross-tangent between the convex parts of two chains following the method of Overmars and Leeuwen [277] for computing tangents between two convex chains of points for dynamic maintenance of the convex hull. Using their method, all tangents and cross-tangents for any pair of adjacent hourglasses (of total m vertices) during the process of combining can be located in O(log m) time. We have the following lemma. Lemma 8.4.10 Two adjacent hourglasses of total m vertices can be combined in O(log m) time. Using the above procedure, combine the adjacent pair of hourglasses formed by diagonals in Dst . Combine the resulting hourglasses again in the pairwise manner by the above procedure. Repeat this process till the hourglass (say, Hst ) for diagonals ds and dt is formed. Take the triangle formed by s with ds , and treating this triangle as a funnel with s as the apex and ds as the base, combine the funnel with Hst (see
8.4 Path Queries Between Points in Simple Polygons
285
Figure 8.13 (a) Two funnels with apexes s and t are combined with Hst to compute SP (s, t). + + − − + + (b) Hourglasses for diagonals (i) ds and d− s , (ii) ds and ds , (iii) ds and dt , (iv) dt and dt , − and (v) dt and dt are combined to form Hst .
Figure 8.13(a)). The resulting hourglass, consisting of a path (which can be empty) and a funnel with base dt , is again combined with the funnel whose apex is t and base is dt . It can be seen that the final hourglass has degenerated into a path which is SP (s, t). Exercise 8.4.4 Let q be a query point lying outside the given convex polygon C of m vertices. Design a query algorithm for computing both tangents from q to C in O(log m) query time and O(m) preprocessing time [291]. Let us calculate the query time required for computing SP (s, t). The lower (and upper) chain of every hourglass computed during preprocessing is stored as a concatenable queue which can be realized by a height-balanced tree. Concatenable queues support binary search, split and merge operations [14]. Since adjacent hourglasses are combined in a pairwise manner, which takes O(log n) time by Lemma 8.4.10, and there are O(log n) diagonals in Dst by Lemma 8.4.7, the entire process of combining adjacent hourglasses can be done in O(log 2 n) query time. Consider the problem of concatenating two chains of H(ab, cd) and H(ab, ef ) to form a chain of H(ab, ef ). Since chains of H(ab, cd) and H(ab, ef ) are stored as concatenable queues, two portions of the chains, connected by the tangent, can be concatenated in O(1) time without any extra space. In Figure 8.11(a), the upper chain of H(ab, cd) is split at vi to form two convex chains. Similarly, the upper chain of H(cd, ef ) is split at vj to form two convex chains. Now, the convex chain formed by SP (va , vi ) is concatenated with the convex chain formed by SP (vj , ve ) giving the upper chain of H(ab, ef ). Observe that the portions of chains of H(ab, cd)
286
Visibility and Path Queries
and H(ab, ef ), that are not included after concatenation, should be preserved because chains of H(ab, cd) and H(ab, ef ) before concatenation may again be required for subsequent queries. So, additional pointers to these portions are stored along with the tangent at the time of concatenation. Once the computation of SP (s, t) is complete, converse operations of concatenations are performed using the stored pointers to restore the starting concatenable queues [277, 291]. The entire process of restoration takes O(log2 n) time. We have the following theorem. Theorem 8.4.11 A simple polygon P of n vertices can be preprocessed in O(n2 ) time and space so that the shortest path between two query points s and t in P can be computed in O(log2 n + k) query time, where k is the number of edges in the shortest path. Exercise 8.4.5 Design a query algorithm for computing the shortest path between two query points s and t in a simple polygon P of n vertices taking O(log n + k) query time and O(n3 ) preprocessing time and space, where k is the number of edges in the shortest path. During preprocessing, hourglasses for pairs of diagonals corresponding to edges in Td∗ are constructed directly by the algorithm of Lee and Preparata [235]. Using the procedure for combining two adjacent hourglasses explained above, the preprocessing time and space for constructing hourglasses corresponding to edges in T d∗ can be reduced to O(n) as follows. Let P (d) be a sub-polygon of m vertices. Let P 0 (d) and P 00 (d) be two sub-polygons that can be obtained by cutting P (d) using the diagonal d. Assume that for every diagonal d0 on the boundary of P 0 (d), the hourglass for d and d0 has been computed. Similarly, we assume that for every diagonal d00 on the boundary of P 00 (d), the hourglass for d and d00 has been computed. Using the procedure for combining two adjacent hourglasses, all hourglasses across d can be computed. Observe that the diagonals of each combined hourglass are connected by an edge in Td∗ . We know that the time required for computing each such hourglass is O(log m), which is proportional to height(d). Using involved analysis, Guibas and Hershberger have shown that the additional space required to store each combined hourglass is also O(height(d)). This procedure of combining two hourglasses across their common diagonal d can be used in the bottom-up fashion starting with the diagonals represented in the leaves of Td . It can be seen that all hourglasses computed in this fashion are the hourglasses represented by edges in Td∗ . We know that the cost of combining two hourglasses across their common diagonal d is proportional to height(d), which in turn is less than height(w), where w and w0 are the diagonals of the combined hourglass with height(w) > height(w 0 ). Since there are O(height(w)) edges in Td∗ connecting w with the diagonals of lower height, the hourglasses corresponding to these edges can be constructed in O((height(w)) 2 )
8.4 Path Queries Between Points in Simple Polygons
time and space. proportional to X
w∈Td∗
287
So, the construction of all hourglasses takes time and space
(height(w))2 = O(
X
h≤1+log3/2 n
h2
µ ¶h
2 3
n) = O(n).
Let us explain how the query time for computing SP (s, t) can be improved to O(log n + k) without increasing the preprocessing time and space as suggested by Exercise 8.4.5. Observe that if many shortest path queries are answered, hourglasses for diagonals with low depths in T are used many times. In order to avoid combining these hourglasses over and over again, additional hourglasses are constructed during preprocessing to provide the necessary bypass structure for cutting a logarithmic factor off the query time for computing Hst . Consider Td . Since Td represents a balanced decomposition of P , there can be at most O(n/ log2 n) nodes in Td with at least α log2 n descendents, where α is a parameter which can be used to trade off between preprocessing time and query time. Let U denote the set of nodes of Td with at least α log2 n descendants (see Figure 8.13(b)). Since nodes in U have low depths in Td , they are referred to as upper nodes in Td . Note that all ancestors of every upper node are also upper nodes in Td . For every upper node d, add edges in Td∗ between d and all its ancestors. Since d has O(log n) ancestors, the number of edges added to Td∗ is O(n/ log n). Let us calculate the preprocessing time and space required for constructing hourglasses corresponding to additional edges in Td∗ . For every upper node d, (i) hourglasses are constructed for diagonals along the path from d to the root of T d , (ii) at most O(log n) hourglasses are combined during this construction, and (iii) the time required to compute each intermediate hourglass is O(log n). Since there are O(n/ log2 n) upper nodes, the construction of hourglasses corresponding to additional edges in Td∗ takes O(n) time and space. We have the following lemma. Lemma 8.4.12 Hourglasses in P corresponding to edges of Td∗ can be computed in O(n) time and space. With these additional hourglasses, computing Hst becomes faster. Consider the diagonals in Dst . If dmin does not belong to U , then there are O(log 2 n) edges in P (dmin ) by the definition of U , and ds and dt are diagonals on the boundary of P (dmin ). So, the number of hourglasses combined in order to produce Hst is O(log(log2 n)) = O(log log n) and the time required for combining a pair of hourglasses is O(log(log n)) = O(log log n). So, Hst can be computed in O(log log n)2 time. Consider the other situation where dmin belongs to U (see Figure 8.13(b)). Let d− s − is a child of d+ , d− does not belong be two ancestors of d in T such that d and d+ s d s s s s − / U is an ancestor of d having to U , and d+ s s belongs to U . In other words, ds ∈
288
Visibility and Path Queries
minimum depth in Td and d+ s ∈ U is an ancestor of ds having maximum depth in Td . Two such nodes d− and d+ t t for dt are defined analogously. The hourglass + − + for diagonals ds and ds , the hourglass for diagonals d+ s and dt and the hourglass + − for diagonals dt and dt are already computed during preprocessing. We know from the analysis mentioned earlier that the hourglass for diagonals d s and d− s and 2 time. By the hourglass for diagonals d− and d can be computed in O(log log n) t t combining these five hourglasses, Hst can be computed in O(log log n)2 + O(log n) = O(log n) time. We have the following lemma. Lemma 8.4.13 The hourglass Hst can be computed in O(log n) query time. Corollary 8.4.14 The next vertex of s and the previous vertex of t on SP (s, t) can be identified in O(log n) query time. Once Hst is computed in O(log n) time, computing SP (s, t) takes O(log n + k) query time as all other steps of the query algorithm take O(log n) time. In the following, we present the major steps of the query algorithm for computing SP (s, t) in P for a pair of query points s and t. Step 1. Triangulate P by the algorithm of Chazelle [71]. Step 2. Decompose P in a balanced fashion by the algorithm of Guibas et al. [178] and construct the corresponding decomposition tree Td . Step 3. For each pair of diagonals d and d0 on the boundary of every sub-polygon formed during the decomposition of P , add an edge between d and d0 in Td to form the factor graph Td∗ . Step 4. Identify upper nodes of Td and connect them to all their ancestors by edges in Td∗ . Step 5. Compute hourglasses corresponding to edges in Td∗ by combining hourglasses pairwise across their common diagonals in the button up fashion starting with the diagonals represented in the leaves of Td . Step 6. Construct the data structure by the algorithm of Kirkpatrick [216] for locating a query point in the triangle of the triangulation of P . Step 7. For each pair of query points s and t in P do Step 7a. Locate s and t in the triangles of the triangulation of P and identify diagonals ds and dt . Step 7b. Form the set Dst by locating principal separating diagonals between ds and dt . Identify the diagonal dmin in Dst . Step 7c. If dmin is not an upper node in Td then construct the hourglass Hst by combining hourglasses across the diagonals between ds and dt in Dst and goto Step 7e.
8.4 Path Queries Between Points in Simple Polygons
289
− + + Step 7d. Identify nodes d− s , ds , dt and dt in Td . Construct the hourglass Hst by combining hourglasses across a subset of diagonals between ds and dt in Dst .
Step 7e. Draw tangents from s and t to Hst and identify vertices of SP (s, t). Step 7f. Report SP (s, t). Step 8. Stop. The correctness and the time complexity of the query algorithm follow from Lemmas 8.4.1, 8.4.9, 8.4.10, 8.4.12 and 8.4.13. We summarize the result in the following theorem. Theorem 8.4.15 A simple polygon P of n vertices can be preprocessed in O(n) time and space so that the shortest path between two query points s and t in P can be computed in O(log n + k) query time, where k is the number of edges in the shortest path.
8.4.2 Link Paths: O(log n + k) Query Algorithm In this section, we present a query algorithm for computing the minimum link path M LP (s, t) between two query points s and t inside a simple polygon P in O(log n + k) query time (see Figure 7.1(a)), where k is the number of links in M LP (s, t). Preprocessing steps of the algorithm take O(n3 log n) time and space. We assume that the vertices of P are labeled v1 , v2 , . . . , vn in counterclockwise order. During preprocessing, the algorithm considers all pairs of vertices of P , and for each pair of vertices vi and vj , a sub-polygon Rij ⊂ P is computed by the algorithm of Ghosh [155] (see Section 7.2.2) such that turning points of M LP (vi , vj ) lie on the boundary of Rij and links of M LP (vi , vj ) pass through vertices of SP (vi , vj ) (see Figure 8.14(a)). Then, using the algorithm of Aggarwal et al. [12] (see Section 7.5.1), the edges on the boundary of Rij are divided into intervals such that the link sequence of the greedy path in Rij from any point of an interval is same. From link sequences, projection functions of intervals in Rij are composed and stored along with the intervals. For a pair of query points s and t, the algorithm locates the sub-polygon containing all turning points of M LP (s, t) on its boundary and then locates these turning points using projection functions of intervals on the boundary of the sub-polygon. Let us explain the preprocessing step of the algorithm for computing Rij using the algorithm of Ghosh [155] presented in Section 7.2.2. Compute SP (vi , vj ) (see Figure 8.14(a)). Let ui and uj be adjacent vertices of vi and vj on SP (vi , vj ), respectively. Extend vi ui from ui to bd(P ) meeting it at a point z. Take a point wi arbitrary close to z on bd(P ) such that vi wi meets SP (vi , vj ) only at vi and vi wi lies inside P . Analogously, extend vj uj from uj to bd(P ) meeting it at a point z 0 . Take a point
290
Visibility and Path Queries
Figure 8.14 (a) The sub-polygon Pij is obtained by cutting P by vi wi , vj wj and those edges of SP (vi , vj ) that are not eaves of SP (vi , vj ). (b) The vertices vi , ui , vj and uj are identified for a pair of points s and t.
wj arbitrary close to z 0 on bd(P ) such that vj wj meets SP (vi , vj ) only at vj and vj wj lies inside P . Cut P by vi wi , vj wj and those edges of SP (vi , vj ) that are not eaves of SP (vi , vj ). So, P is split into several parts and the part containing both vi and vj is denoted as Pij . If SP (vi , vj ) does not contain an eave, compute the sub-polygon Rij ⊆ Pij such that both tangents from any point z ∈ Rij to SP (vi , vj ) lie inside Rij . If SP (vi , vj ) contains eaves, Pij is partitioned by extending eaves and from these parts of Pij , the sub-polygon Rij is computed. Consider a pair of points s and t in P such the adjacent vertices of s and t on SP (s, t) are ui and uj respectively, and sui and twj intersect vi wi and vj uj , respectively (see Figure 8.14(b)). Extend sui from ui to the boundary of Rij meeting it at zs . Similarly, extend tuj from uj to the boundary of Rij meeting it at zt . Construct the greedy path from zs to a point of uj zj in Rij by the algorithm of Ghosh [155], which gives M LP (s, t). Let us use this method to compute M LP (s, t) for any pair of query points s and t in P . Using the query algorithm of Guibas and Hershberger [177] (see Section 8.4.1), locate the adjacent vertices of s and t on SP (s, t) and call them ui and uj , respectively (see Figure 8.14(b)). Take the adjacent vertex of ui on bd(P ) as vi , where sui intersects vi wi . Similarly, take the adjacent vertex of uj on bd(P ) as vj , where tuj intersects vj wj . Since Rij has been computed for all pairs of vertices vi and vj of P during preprocessing, M LP (s, t) can be computed in Rij by the above method. We know from Corollary 8.4.14 that for a pair of query points s and t, locating ui and uj takes O(log n) query time. However, computing M LP (s, t) in Rij by the algorithm of Ghosh [155] takes time proportional to the size of Rij . We show that M LP (s, t) can be computed in Rij in O(log n + k) query time. After the
8.4 Path Queries Between Points in Simple Polygons
291
computation of Rij for all pairs of vertices vi and vj of P during preprocessing, each Rij is considered again. By the algorithm of Aggarwal et al. [12] presented in Section 7.5.1, the edges on the boundary of Rij are divided into intervals. From link sequences of these intervals, projection functions of intervals in Rij are composed and stored along with intervals. Once zs is located by binary search on an interval I of Rij during query, the forward projection point of zs on uj zt (say, zp ) can be located using the projection function (say, f ) of I. Therefore, the link distance between s and t can be computed in O(log n) query time. To compute turning points of M LP (s, t), we follow the method suggested by Chandru et al. [69]. Assume that f has been composed of projection functions f1 , f2 , . . . , fg , where f1 is composed with f2 , (f1 ∗ f2 ) is composed with f3 and so on. This means that (f1 ) gives the first turning point of zs , (f1 ∗ f2 ) gives the second turning point of zs , (f1 ∗ f2 ∗ f3 ) gives the fourth turning point of zs , and so on. We know that f3 is composed of two projection functions (say, f30 and f300 ). So, the third turning point of zs can be computed by the projection function (f1 ∗ f2 ∗ f30 ). Therefore, turning points of M LP (s, t) between zs and zp can be computed using these intermediate projection functions in time proportional to the number of turning points. Thus all turning points of M LP (s, t) can be computed in O(log n + k) query time. In the following, we present the major steps of the query algorithm for computing M LP (s, t) in P for a pair of query points s and t. Step 1. Triangulate P by the algorithm of Chazelle [71]. Step 2. Construct the data structure by the algorithm of Kirkpatrick [216] for locating a query point in the triangle of the triangulation of P . Step 3. For every pair of vertices vi and vj of P do Step 3a. Compute SP (vi , vj ) by the algorithm of Lee and Preparata [235]. Step 3b. Let ui and uj be adjacent vertices of vi and vj on SP (vi , vj ), respectively. Extend vi ui from ui to bd(P ) and take a point wi ∈ bd(P ) close to the intersection point. Extend vj uj from uj to bd(P ) and take a point wj ∈ bd(P ) close to the intersection point. Step 3c. Cut P by vi wi , vj wj and the edges of SP (vi , vj ) that are not eaves of SP (vi , vj ) and identify the sub-polygon Pij containing both vertices vi and vj . Step 3d. Compute the sub-polygon Rij from Pij by the algorithm of Ghosh [155]. Step 3e. By the algorithm of Aggarwal et al. [12], compute intervals on the boundary of Rij , compose projection functions of these intervals and store them along with intervals. Step 4. For each pair of query points s and t in P do Step 4a. Locate s and t in the triangles of the triangulation of P .
292
Visibility and Path Queries
Step 4b. Locate adjacent vertices of s and t on SP (s, t) by the algorithm of Guibas and Hershberger [177] and label them as ui and uj , respectively. Step 4c. Choose the appropriate adjacent vertices of ui and uj on bd(P ) as vi and vj , respectively. Step 4d. Extend sui from ui to the boundary of Rij meeting it at a point zs . Extend tuj from uj to the boundary of Rij meeting it at a point zt . Step 4e. Locate the interval containing zs on the boundary of Rij by binary search. Using the projection function of the interval, compute the forward projection point zp of zs on uj zt . Step 4f. Compute turning points of M LP (s, t) between zp to zs by intermediate projection functions associate with intervals of Rij . Step 4g. Report M LP (s, t). Step 5. Stop. The correctness of the algorithm follows from the algorithms of Ghosh [155], Aggarwal et al. [12], Guibas and Hershberger [177] and Chandru et al. [69]. Let us analyze the time complexity of the algorithm. We know that Steps 1 and 2 take O(n) time. Since Steps 3a and 3d take O(n) time and Step 3e takes O(n log n) time and space, Step 3 can be executed in O(n3 log n) time and space. So, the preprocessing of P can be done in O(n3 log n) time and space. It has already been shown that the query time for Step 4 is O(log n + k). We summarize the result in the following theorem. Theorem 8.4.16 A simple polygon P of n vertices can be preprocessed in O(n3 log n) time and space so that the minimum link path between two query points s and t in P can be computed in O(log n + k) query time, where k is the number of links in the path.
8.5 Notes and Comments The algorithm of Kirkpatrick [216] has been used for locating positions of query points in a given triangulated polygon P in query algorithms presented in this chapter. Kirkpatrick’s algorithm builds subdivision hierarchies of P using triangulation in O(n) time and space. These hierarchies are represented as a layered, directed graph, where the degree of each node of the graph is constant and the total depth of the graph is O(log n). Using this graph, the query point is located in a triangle inside P in O(log n) query time. There are other query algorithms for locating query points in a given planar subdivision P . The first algorithm for this problem was given by Dobkin and Lipton [112]. Their algorithm partitions P into slabs by drawing vertical lines through
8.5 Notes and Comments
293
vertices of P taking O(n2 log n) preprocessing time and O(n2 ) space. During a query, the slab containing a query point is located by binary search and then another binary search is performed to locate the position of the query point in the region of the slab bounded by two edges of P . Thus, the algorithm answers a query in O(log n) query time. Preparata [290] showed that by partitioning P into trapezoids in place of slabs, preprocessing time and space can be reduced to O(n log n) keeping the query time the same. Lee and Preparata [233] introduced an alternative method and their method partitions P into monotone chains taking O(n log n) preprocessing time and O(n) space. During a query, discrimination of a query point with monotone chains is performed by binary search to locate the region of P containing the point. However, the query time of the algorithm is O(log2 n). Using fractional cascading, the query time of this chain method was improved to O(log n) by Edelsbrunner et al. [119] keeping the preprocessing time and space requirements the same. Sarnak and Tarjan [302] gave another algorithm for point location in O(log n) query time taking O(n log n) preprocessing time and O(n) space. Their method combined techniques of slab method, plane sweep and persistence to build a data structure for answering queries. A similar method was also suggested by Cole [94]. Let us mention parallel algorithms for query problems considered in this chapter. Consider the problem of ray shooting in a simple polygon P . For this problem, Goodrich et al. [173, 174] gave an algorithm following the sequential algorithm of Chazelle and Guibas [76]. They also gave an algorithm for computing the shortest path between query points in a simple polygon P following the sequential algorithm of Guibas and Hershberger [177]. Both these algorithms run in O(log n) time using O(n) processors in the CREW-PRAM model of computations. If the triangulation of P is given, Hershberger [187] showed that both these problems can be solved in O(log n) time using O(n/ log n) processors in the CREW-PRAM model of computations. A parallel algorithm for the problem of computing the minimum link path between two query points in a simple polygon P can be designed by parallelizing each step of the sequential algorithm presented in Section 8.4.2.
Bibliography
[1] J. Abello, O. Egecioglu, and K. Kumar. Visibility graphs of staircase polygons and the weak Bruhat order, I: from visibility graphs to maximal chains. Discrete & Computational Geometry, 14:331–358, 1995. [2] J. Abello and K. Kumar. Visibility graphs and oriented matroids. In Proceedings of Graph Drawing, Lecture Notes in Computer Science, volume 894, pages 147–158. SpringerVerlag, Berlin, Germany, 1995. [3] J. Abello and K. Kumar. Visibility graphs and oriented matroids. Discrete & Computational Geometry, 28:449–465, 2002. [4] J. Abello, H. Lin, and S. Pisupati. On visibility graphs of simple polygons. Congressus Numerantium, 90:119–128, 1992. [5] J. Adegeest, M. H. Overmars, and J. Snoeyink. Minimum-link c-oriented path: Singlesource queries. International Journal of Computational Geometry and Applications, 4:39–51, 1994. [6] P. K. Agarwal. Ray shooting and other applications of spanning trees with low stabbing number. SIAM Journal on Computing, 21:540–570, 1992. [7] P. K. Agarwal, N. Alon, B. Aronov, and S. Suri. Can visibility graphs be represented compactly? Discrete & Computational Geometry, 12:347–365, 1994. [8] P. K. Agarwal and M. Sharir. Circle shooting in a simple polygon. Journal of Algorithms, 14:69–87, 1993. [9] P. K. Agarwal and M. Sharir. Circular visibility from a point in a simple polygon. International Journal of Computational Geometry and Applications, 3:1–25, 1993. [10] P.K. Agarwal, T. Biedl, S. Lazard, S. Robbins, S. Suri, and S. Whitesides. Curvatureconstrained shortest paths in a convex polygon. SIAM Journal on Computing, 31:1814– 1851, 2002. [11] A. Aggarwal. The art gallery theorem: its variations, applications, and algorithmic aspects. Ph.D. Thesis, Johns Hopkins University, Baltimore, MD, USA, 1984. [12] A. Aggarwal, H. Booth, J. O’Rourke, S. Suri, and C. K. Yap. Finding minimal convex nested polygons. Information and Computing, 83:98–110, 1989. [13] A. Aggarwal, S. Moran, P. Shor, and S. Suri. Computing the minimum visible vertex distance between two polygons. In Proceedings of the 1st Workshop on Algorithms and Data Structures, Lecture Notes in Computer Science, volume 382, pages 115–134. Springer-Verlag, Berlin, Germany, 1989. [14] A. Aho, J. H. Hopcroft, and J. D. Ullman. The Design and Analysis of Algorithms. Addison-Wesley, Reading, MA, USA, 1974. [15] A. Aho, J. H. Hopcroft, and J. D. Ullman. Data Structures and Algorithms. AddisonWesley, Reading, MA, USA, 1983. [16] L. Aleksandrov, H. Djidjev, and J. Sack. An O(n log n) algorithm for finding a shortest central link segment. International Journal of Computational Geometry and Applica-
295
296
Bibliography
tions, 10:157–188, 2000. [17] M. H. Alsuwaiyel and D. T. Lee. Minimal link visibility paths inside a simple polygon. Computational Geometry: Theory and Applications, 3:1–25, 1993. [18] M. H. Alsuwaiyel and D. T. Lee. Finding an approximate minimum-link visibility path inside a simple polygon. Information Processing Letters, 55:75–79, 1995. [19] N. M. Amato. Finding a closest visible vertex pair between two polygons. Algorithmica, 14:183–201, 1995. [20] T. Andreae. Some results on visibility graphs. Discrete Applied Mathematics, 40:5–18, 1992. [21] E. Arkin, M. Held, J. S. B. Mitchell, and S. Skiena. Hamiltonian triangulations for fast rendering. Visual Computers, 12:429–444, 1996. [22] E. Arkin, J. S. B. Mitchell, and C. Piatko. Minimum-link watchman tours. Information Processing Letters, 86:203–207, 2003. [23] E. Arkin, J. S. B. Mitchell, and S. Suri. Logarithmic-time link path queries in a simple polygon. International Journal of Computational Geometry and Applications, 5:369– 395, 1995. [24] B. Aronov, A. Davis, T. Dey, S. P. Pal, and D. Prasad. Visibility with multiple reflections. Discrete & Computational Geometry, 20:61–78, 1998. [25] B. Aronov, A. Davis, T. Dey, S. P. Pal, and D. Prasad. Visibility with one reflection. Discrete & Computational Geometry, 19:553–574, 1998. [26] B. Aronov, L. J. Guibas, M. Teichmann, and L. Zhang. Visibility and maintenance in simple polygons. Discrete & Computational Geometry, 27:461–483, 2002. [27] T. Asano. Efficient algorithms for finding the visibility polygons for a polygonal region with holes. Transactions of IECE of Japan, E68:557–559, 1985. [28] T. Asano, T. Asano, L. J. Guibas, J. Hershberger, and H. Imai. Visibility of disjoint polygons. Algorithmica, 1:49–63, 1986. [29] T. Asano, T. Asano, and R. Pinter. Polygon triangulation: Efficiency and minimality. Journal of Algorithms, 7:221–231, 1986. [30] T. Asano, S. K. Ghosh, and T. Shermer. Visibility in the plane. In J.-R. Sack and J. Urrutia, editors, Handbook of Computational Geometry, pages 829–876. North-Holland, Amsterdam, The Netherlands, 2000. [31] T. Asano and G. Toussaint. Computing the geodesic center of a simple polygon. In D. S. Johnson, editor, Discrete Algorithms and Complexity, Perspectives in Computing, pages 65–79. Academic Press, New York, 1987. [32] M. Atallah and D. Z. Chen. Optimal parallel algorithm for visibility of a simple polygon from a point. In Proceedings of the 5th Annual ACM Symposium on Computational Geometry, pages 114–123. ACM Press, New York, USA, 1989. [33] M. Atallah and D. Z. Chen. Parallel rectilinear shortest paths with rectangular obstacles. Computational Geometry: Theory and Applications, 1:79–113, 1991. [34] M. Atallah and D. Z. Chen. On parallel rectilinear obstacle-avoiding paths. Computational Geometry: Theory and Applications, 3:307–313, 1993. [35] M. Atallah and D. Z. Chen. Determistic parallel computational geometry. In J.-R. Sack and J. Urrutia, editors, Handbook of Computational Geometry, pages 155–200. North-Holland, Amsterdam, The Netherlands, 2000. [36] M. Atallah, D. Z. Chen, and H. Wagener. Optimal parallel algorithm for visibility of a simple polygon from a point. Journal of the ACM, 38:516–553, 1991. [37] M. Atallah, R. Cole, and M. T. Goodrich. Cascading divide-and-conquer: A technique for designing parallel algorithms. SIAM Journal on Computing, 18:499–532, 1989. [38] M. Atallah and M. T. Goodrich. Efficient plane sweeping in parallel. In Proceedings of the 2nd Annual ACM Symposium on Computational Geometry, pages 216–225. ACM Press, New York, USA, 1986. [39] D. Avis and H. ElGindy. A combinatorial approach to polygon similarity. IEEE Transactions on Information Theory, IT-2:148–150, 1983.
Bibliography
297
[40] D. Avis and D. Rappaport. Computing the largest empty convex subset of a set of points. In Proceedings of the 1st ACM Symposium on Computational Geometry, pages 161–167. ACM Press, New York, USA, 1985. [41] D. Avis and G. T. Toussaint. An efficient algorithm for decomposing a polygon into star-shaped polygons. Pattern Recognition, 13:395–398, 1981. [42] D. Avis and G. T. Toussaint. An optimal algorithm for determining the visibility of a polygon from an edge. IEEE Transactions on Computers, C-30:910–1014, 1981. [43] R. Bar-Yehuda and B. Chazelle. Triangulating disjoint Jordan chains. International Journal of Computational Geometry and Applications, 4:475–481, 1994. [44] B. Ben-Moshe, O. Hall-Holt, M. J. Katz, and J. S. B. Mitchell. Computing the visibility graph of points within a polygon. In Proceedings of the 20th Annual ACM Symposium on Computational Geometry, pages 27–35. ACM Press, New York, USA, 2004. [45] P. Bertolazzi, S. Salza, and C. Guerra. A parallel algorithm for the visibility problem from a point. Journal of Parallel and Distributed Computing, 9:11–14, 1990. [46] J. Bhadury, V. Chandru, A. Maheshwari, and R. Chandrasekran. Art gallery problems for convex nested polygons. INFORMS Journal on Computing, 9:100–110, 1997. [47] B. K. Bhattacharya, G. Das, A. Mukhopadhyay, and G. Narasimhan. Optimally computing a shortest weakly visible line segment inside a simple polygon. Computational Geometry: Theory and Applications, 23:1–29, 1997. [48] B. K. Bhattacharya and S. K. Ghosh. Characterizing LR-visibility polygons and related problems. Computational Geometry: Theory and Applications, 18:19–36, 2001. [49] B. K. Bhattacharya, S. K. Ghosh, and T. Shermer. A linear time algorithm to remove winding of a simple polygon. Computational Geometry: Theory and Applications, 33:165–173, 2006. [50] B. K. Bhattacharya and A. Mukhopadhyay. Computing in linear time a chord from which a simple polygon is weakly internally visible. In Proceedings of the 6th International Symposium on Algorithms and Computation, Lecture Notes in Computer Science, volume 1004, pages 22–31. Springer-Verlag, Berlin, Germany, 1995. [51] B. K. Bhattacharya, A. Mukhopadhyay, and G. Narasimhan. Optimal algorithms for two-guard walkability of simple polygons. In Proceedings of the 12th Workshop on Algorithms and Data Structures, Lecture Notes in Computer Science, volume 2125, pages 438–449. Springer-Verlag, Berlin, Germany, 2001. [52] B. K. Bhattacharya, A. Mukhopadhyay, and G. T. Toussaint. A linear time algorithm for computing the shortest line segment from which a polygon is weakly externally visible. In Proceedings of the 2nd Workshop on Algorithms and Data Structures, Lecture Notes in Computer Science, volume 519, pages 412–424. Springer-Verlag, Berlin, Germany, 1991. [53] B. K. Bhattacharya, A. Mukhopadhyay, and G. T. Toussaint. Computing a shortest weakly externally visible line segment for a simple polygon. International Journal of Computational Geometry and Applications, 9:81–96, 1999. [54] B. K. Bhattacharya and G. T. Toussaint. Computing shortest transversals. Computing, 46:93–119, 1991. [55] I. Bjorling-Sachs. Edge guards in rectilinear polygons. Computational Geometry: Theory and Applications, 11:111–123, 1998. [56] I. Bjorling-Sachs and D. L. Souvaine. An efficient algorithm for guard placement in polygons with holes. Discrete & Computational Geometry, 13:77–109, 1995. [57] J.-D. Boissonnat, S. K. Ghosh, T. Kavitha, and S. Lazard. An algorithm for computing a convex path of bounded curvature in a simple polygon. Algorithmica, 34:109–156, 2002. [58] J. A. Bondy and U. S. R. Murty. Graph Theory with Applications. North Holland, New York, USA, 1985. [59] K. S. Booth and G. S. Lueker. Testing for consecutive ones property, interval graphs and graph planarity using pq-tree algorithms. Journal of Computer and Systems Sciences,
298
Bibliography
13:335–379, 1976. [60] P. Bose, A. Lubiw, and J. Munro. Efficient visibility queries in simple polygons. Computational Geometry: Theory and Applications, 23:313–335, 2002. [61] A. Brandstadt, J. Spinrad, and L. Stewart. Bipartite permutation graphs are bipartite tolerance graphs. Congressus Numerantium, 58:165–174, 1987. [62] M. Breen. Clear visibility and the dimension of kernels of starshaped sets. Proceedings of the American Mathematical Society, 85:414–418, 1982. [63] M. Breen. Clear visibility and unions of two starshaped sets in the plane. Pacific Journal of Mathematics, 115:267–275, 1984. [64] D. Bremner. Point Visibility Graphs and Restricted-Orientation Polygon Covering. M.Sc. Thesis, School of Computing Science, Simon Fraser University, Burnaby, BC, Canada, 1993. [65] D. Bremner and T. Shermer. Point visibility graphs and o-convex cover. International Journal of Computational Geometry and Applications, 10:55–71, 2000. [66] A. Briggs and B. Donald. Visibility-based planning of sensor control strategies. Algorithmica, 26:364–388, 2000. [67] H. Brunn. Uber kerneigebiete. Mathematische Annalen, 73:436–440, 1913. [68] M. Buckinghan. Circle graphs. Ph.D. Dissertation, Courant Institute of Mathematical Sciences, New York, USA, 1980. [69] V. Chandru, S. K. Ghosh, A. Maheshwari, V. T. Rajan, and S. Saluja. NC-algorithms for minimum link path and related problems. Journal of Algorithms, 19:173–203, 1995. [70] B. Chazelle. A theorem on polygon cutting with applications. In Proceedings of the 23rd IEEE Symposium on the Foundations of Computer Science, pages 339–349. IEEE Computer Society Press, Los Alamitos, CA, USA, 1982. [71] B. Chazelle. Triangulating a simple polygon in linear time. Discrete & Computational Geometry, 6:485–524, 1991. [72] B. Chazelle and H. Edelsbrunner. An optimal algorithm for intersecting line segments in the plane. Journal of the ACM, 39:1–54, 1992. [73] B. Chazelle, H. Edelsbrunner, M. Grigni, L. J. Guibas, J. Hershberger, M. Sharir, and J. Snoeyink. Ray shooting in polygons using geodesic triangulations. Algorithmica, 12:54–68, 1994. [74] B. Chazelle and L. J. Guibas. Fractional cascading: I. A data structuring technique. Algorithmica, 1:133–162, 1986. [75] B. Chazelle and L. J. Guibas. Fractional cascading: II. Applications. Algorithmica, 1:163–191, 1986. [76] B. Chazelle and L. J. Guibas. Visibility and intersection problems in plane geometry. Discrete & Computational Geometry, 4:551–581, 1989. [77] B. Chazelle, L. J. Guibas, and D.T. Lee. The power of geometric duality. BIT, 25:76–90, 1985. [78] B. Chazelle and J. Incerpi. Triangulation and shape-complexity. ACM Transactions of Graphics, 3:135–152, 1984. [79] O. Chein and L. Steinberg. Routing past unions of disjoint barriers. Networks, 13:389– 398, 1983. [80] D. Chen, K. Klenk, and H.-Y. Tu. Shortest path queries among weighted obstacles in the rectilinear plane. SIAM Journal on Computing, 29:1223–1246, 2000. [81] D. Z. Chen. Efficient geometric algorithms on EREW-PRAM. IEEE Transactions on Parallel and Distributed Systems, 6:41–47, 1995. [82] D. Z. Chen. An optimal parallel algorithm for detecting weak visibility of a simple polygon. International Journal of Computational Geometry and Applications, 5:93– 124, 1995. [83] D. Z. Chen. Optimally computing the shortest weakly visible subedge of a simple polygon. Journal of Algorithms, 20:459–478, 1996. [84] D. Z. Chen. Determining weak visibility of a polygon from an edge in parallel. Interna-
Bibliography
299
tional Journal of Computational Geometry and Applications, 8:277–304, 1998. [85] D. Z. Chen, O. Daescu, and K. Klenk. On geometric path query problems. International Journal of Computational Geometry and Applications, 11:617–645, 2001. [86] Y.-J. Chiang and J. S. B. Mitchell. Two-point Euclidean shortest path queries in the plane. In Proceedings of the 10th Annual ACM-SIAM Symposium on Discrete Algorithms, pages 215–224. ACM and SIAM, USA, 1999. [87] Y.-J. Chiang and R. Tamassia. Optimal shortest path and minimum-link path queries between two convex polygons inside a simple polygonal obstacle. International Journal of Computational Geometry and Applications, 7:85–121, 1997. [88] F. Chin, J. Sampson, and C. A. Wang. A unifying approach for a class of problems in the computational geometry of polygons. The Visual Computer, 1:124–132, 1985. [89] S.-H. Choi, S. Y. Shin, and K.-Y. Chwa. Characterizing and recognizing the visibility graph of a funnel-shaped polygon. Algorithmica, 14:27–51, 1995. [90] S.-Y. Chou and R. C. Woo. A linear-time algorithm for constructing a circular visibility diagram. Algorithmica, 14:203–228, 1995. [91] V. Chv´atal. A combinatorial theorem in plane geometry. Journal of Combinatorial Theory, Series B, 18:39–41, 1975. [92] K. L. Clarkson, S. Kapoor, and P. Vaidya. Rectilinear shortest paths through polygonal obstacles in O(n log2 n) time. In Proceedings of the 3rd Annual ACM Symposium on Computational Geometry, pages 251–257. ACM Press, New York, USA, 1987. [93] M. Cohen and J. Wallace. Radiosity and Realistic Image Synthesis. Academic Press Professional, Boston, MA, USA, 1993. [94] R. Cole. Searching and storing similar lists. Journal of Algorithms, 7:202–220, 1986. [95] P. Colley, A. Lubiw, and J. Spinrad. Visibility graphs of towers. Computational Geometry: Theory and Applications, 7:161–172, 1997. [96] T. H. Cormen, C. E. Leiserson, R. L. Rivest, and C. Stein. Introduction to Algorithms. MIT Press, Cambridge, MA, USA, 2001. [97] C. Coullard and A. Lubiw. Distance visibility graphs. International Journal of Computational Geometry and Applications, 2:349–362, 1992. [98] D. Crass, I. Suzuki, and M. Yamashita. Search for a mobile intruder in a corridor-the open edge variant of the polygon search propblem. International Journal of Computational Geometry and Applications, 5:397–412, 1995. [99] J. Culberson and R. Reckhow. Orthogonally convex coverings of orthogonal polygons without holes. Journal of Computer and Systems Science, 39:166–204, 1989. [100] G. Das, P. Heffernan, and G. Narasimhan. Finding all weakly-visible chords of a polygon in linear time. Nordic Journal of Computing, 1:433–456, 1994. [101] G. Das, P. Heffernan, and G. Narasimhan. LR-visibility in polygons. Computational Geometry: Theory and Applications, 7:37–57, 1997. [102] G. Das and G. Narasimhan. Geometric searching and link distance. In Proceedings of the 2nd Workshop on Algorithms and Data Structures, Lecture Notes in Computer Science, volume 519, pages 262–272. Springer-Verlag, Berlin, Germany, 1991. [103] G. Das and G. Narasimhan. Optimal linear-time algorithm for the shortest illuminating line segment in a polygon. In Proceedings of the 10th Annual ACM Symposium on Computational Geometry, pages 259–266. ACM Press, New York, USA, 1994. [104] D. Dasgupta and C.E. Veni Madhavan. An approximate algorithm for the minimum vertex nested polygon problem. Information Processing Letters, 33:35–44, 1989. [105] P. Dasgupta, P. Chakrabarti, and S. De Sarkar. A new competitive algorithm for agent searching in unknown streets. In Proceeding of the 16th Symposium on Foundation of Software Technology and Theoretical Computer Science, Lecture Notes in Computer Science, volume 1180, pages 32–41. Springer-Verlag, Berlin, Germany, 1995. [106] A. Datta and C. Icking. Competitive searching in a generalized street. Computational Geometry: Theory and Applications, 13:109–120, 1997. [107] L. Davis and M. Benedikt. Computational models of space: Isovists and isovist fields.
300
Bibliography
Computer Graphics and Image Processing, 11:49–72, 1979. [108] M. de Berg. On rectilinear link distance. Computational Geometry: Theory and Applications, 1:13–34, 1991. [109] P. de Rezende, D. T. Lee, and Y. F. Wu. Rectilinear shortest paths with rectangular barriers. Discrete & Computational Geometry, 4:41–53, 1989. [110] J. Dean, A. Lingas, and J.-R. Sack. Recognizing polygons, or how to spy. The Visual Computer, 3:344–355, 1988. [111] H. N. Djidjev, A. Lingas, and J. Sack. An O(n log n) algorithm for computing the link center of a simple polygon. Discrete & Computational Geometry, 8:131–152, 1992. [112] D. Dobkin and R. Lipton. Multidimensional searching problems. SIAM Journal on Computing, 5:181–186, 1975. [113] D. Dobkin and S. Teller. Computer graphics. In J. Goodman and J. O’Rourke, editors, Handbook of Discrete and Computational Geometry, pages 779–814. CRC Press, New York, USA, 1997. [114] J.-I. Doh and K.-Y. Chwa. An algorithm for determining visibility of a simple polygon from an internal line segment. Journal of Algorithms, 14:139–168, 1993. [115] S. E. Dorward. A survey of object-space hidden surface removal. International Journal of Computational Geometry and Applications, 4:325–362, 1994. [116] H. Edelsbrunner. Finding extreme distance between convex polygons. Journal of Algorithms, 6:213–224, 1985. [117] H. Edelsbrunner. Algorithms in Combinatorial Geometry. Springer-Verlag, Berlin, Germany, 1987. [118] H. Edelsbrunner, L. J. Guibas, and M. Sharir. The complexity and construction of many faces in arrangements of lines and segments. Discrete & Computational Geometry, 5:161–196, 1990. [119] H. Edelsbrunner, L. J. Guibas, and J. Stolfi. Optimal point location in a monotone subdivision. SIAM Journal on Computing, 15:317–340, 1986. [120] H. Edelsbrunner, J. O’Rourke, and R. Seidel. Constructing arrangements of lines and hyperplanes with applications. SIAM Journal on Computing, 15:341–363, 1986. [121] H. Edelsbrunner, J. O’Rourke, and E. Welzl. Stationing guards in rectilinear art galleries. Computer Vision, Graphics, Image Processing, 27:167–176, 1984. [122] A. Efrat and S. Har-Peled. Guarding galleries and terrains. In Proceedings of the 2nd IFIP International Conference on Theoretical Computer Science, pages 181–192. Kluwer Academic Publishers, Norwell, MA, USA, 2002. [123] S. Eidenbenz. Inapproximability results for guarding polygons without holes. In Proceedings of International Symposium on Algorithms and Computations, Lecture Notes in Computer Science, volume 1533, pages 427–436. Springer-Verlag, Berlin, Germany, 1998. [124] S. Eidenbenz. In-approximability of visibility problems on polygons and terrains. Ph.D. Thesis, Institute for Theoretical Computer Science, ETH, Zurich, Switzerland, 2000. [125] S. Eidenbenz. In-approximability of finding maximum hidden sets on polygons and terrains. Computational Geometry: Theory and Applications, 21:139–153, 2002. [126] H. ElGindy. Hierarchical decomposition of polygons with applications. Ph.D. Thesis, McGill University, Montreal, Quebec, Canada, 1985. [127] H. ElGindy. Efficient algorithms for computing the weak visibility polygon from an edge. Technical Report MS-CIS-86-04, University of Pennsylvania, Philadelphia, USA, 1986. [128] H. ElGindy and D. Avis. A linear algorithm for computing the visibility polygon from a point. Journal of Algorithms, 2:186–197, 1981. [129] H. ElGindy and M. Goodrich. Parallel algorithms for shortest path problems in polygons. Visual Computer, 3:371–378, 1988. [130] H. ElGindy and P. Mitra. Orthogonal shortest route queries among axis parallel rectangular obstacles. International Journal of Computational Geometry and Applications,
Bibliography
301
4:3–24, 1994. [131] H. ElGindy and G. T. Toussaint. On geodesic properties of polygons relevant to linear time triangulation. The Visual Computer, 5:68–74, 1989. [132] S. Even, A. Pnueli, and A. Lempel. Permutation graphs and transitive graphs. Journal of the ACM, 19:400–410, 1972. [133] H. Everett. Visibility graph recognition. Ph.D. Thesis, University of Toronto, Toronto, Canada, 1990. [134] H. Everett and D. G. Corneil. Recognizing visibility graphs of spiral polygons. Journal of Algorithms, 11:1–26, 1990. [135] H. Everett and D. G. Corneil. Negative results on characterizing visibility graphs. Computational Geometry: Theory and Applications, 5:51–63, 1995. [136] H. Everett, C. T. Hoang, K. Kilakos, and M. Noy. Planar segment visibility graphs. Computational Geometry: Theory and Applications, 16:235–243, 2000. [137] H. Everett, F. Hurtado, and M. Noy. Stabbing information of a simple polygon. Discrete Applied Mathematics, 91:67–92, 1999. [138] H. Everett, A. Lubiw, and J. O’Rourke. Recovery of convex hulls from external visibility graphs. In Proceedings of the 5th Canadian Conference on Computational Geometry, pages 309–314, 1993. [139] O. Faugeras. Three Dimensional Computer Vision. MIT Press, Cambridge, MA, USA, 1993. [140] E. Fink and D. Wood. Planar strong visibility. International Journal of Computational Geometry and Applications, 13:173–187, 2003. [141] S. Fisk. A short proof of Chvatal’s watchman theorem. Journal of Combinatorial Theory, Series B, 24:374, 1978. [142] A. Fournier and D. Y. Montuno. Triangulating simple polygons and equivalent problems. ACM Transactions of Graphics, 3:153–174, 1984. [143] M. L. Fredman and R. E. Tarjan. Fibonacci heaps and their uses in improved network optimization algorithms. Journal of the ACM, 34:596–615, 1987. [144] D. R. Fulkerson and O. A. Gross. Incident matrics and interval graphs. Pacific Journal of Mathematics, 15:835–855, 1965. [145] C. P. Gabor, W. Hsu, and K. J. Supowit. Recognizing circle graphs in polynomial time. Journal of the ACM, 36:435–473, 1989. [146] H. N. Gabow and R. E. Tarjan. A linear-time algorithm for a special case of disjoint set union. Journal of Computer Systems and Science, 30:209–221, 1985. [147] J. Garcia-Lopez and P. Ramos-Alonso. Circular visibility and separability. In Proceedings of the 5th Canadian Conference on Computational Geometry, pages 18–23, 1993. [148] M. R. Garey, D. S. Johnson, F. P. Preparata, and R. E. Tarjan. Triangulating a simple polygon. Information Processing Letters, 7:175–179, 1978. [149] L. Gewali. Efficient algorithms for path planning and visibility problems. Ph.D. Thesis, University of Texas, Dallas, Texas, USA, 1989. [150] L. Gewali, M. Keil, and S. Ntafos. On covering orthogonal polygons with star-shaped polygons. Information Sciences, 65:45–63, 1992. [151] S. K. Ghosh. A linear time algorithm for determining the intersection type of two star polygons. In Proceedings of the 4th Symposium on Foundation of Software Technology and Theoretical Computer Science, Lecture Notes in Computer Science, volume 181, pages 317– 330. Springer Verlag, Berlin, Germany, 1984. [152] S. K. Ghosh. Approximation algorithms for art gallery problems. In Proceedings of the Canadian Information Processing Society Congress, pages 429–434, 1987. [153] S. K. Ghosh. Computing a viewpoint of a set of points inside a polygon. In Proceedings of the 8th Symposium on Foundation of Software Technology and Theoretical Computer Science, Lecture Notes in Computer Science, volume 338, pages 18–29. Springer Verlag, Berlin, Germany, 1988.
302
Bibliography
[154] S. K. Ghosh. On recognizing and characterizing visibility graphs of simple polygons. In Proceedings of Scandinavian Workshop on Algorithm Theory, Lecture Notes in Computer Science, volume 318, pages 96–104. Springer-Verlag, Berlin, Germany, 1988. (Also In Report JHU/EECS-86/14, The Johns Hopkins University, Baltimore, MD, USA, 1986). [155] S. K. Ghosh. Computing visibility polygon from a convex set and related problems. Journal of Algorithms, 12:75–95, 1991. [156] S. K. Ghosh. A note on computing the visibility polygon from a convex chain. Journal of Algorithms, 21:657–662, 1996. [157] S. K. Ghosh. On recognizing and characterizing visibility graphs of simple polygons. Discrete & Computational Geometry, 17:143–162, 1997. [158] S. K. Ghosh. Approximation algorithms for art gallery problems in polygons. Manuscript, Tata Institute of Fundamental Research, Mumbai, India, January 2006. [159] S. K. Ghosh and A. Maheshwari. An optimal algorithm for computing a minimum nested nonconvex polygon. Information Processing Letters, 36:277–280, 1990. [160] S. K. Ghosh and A. Maheshwari. An optimal parallel algorithm for determining the intersection type of two star-shaped polygons. In Proceedings of the 3rd Canadian Conference on Computational Geometry, pages 2–6, 1991. [161] S. K. Ghosh and A. Maheshwari. Parallel algorithms for all minimum link paths and link center problems. In Proceedings of the 3rd Scandinavian Workshop on Algorithm Theory, Lecture Notes in Computer Science, volume 621, pages 106– 117. SpringerVerlag, Berlin, Germany, 1992. [162] S. K. Ghosh, A. Maheshwari, S. P. Pal, S. Saluja, and C. E. Veni Madhavan. Computing the shortest path tree in a weak visibility polygon. In Proceedings of the 11th Symposium on Foundation of Software Technology and Theoretical Computer Science, Lecture Notes in Computer Science, volume 560, pages 369–389. Springer-Verlag, Berlin, Germany, 1991. [163] S. K. Ghosh, A. Maheshwari, S. P. Pal, S. Saluja, and C. E. Veni Madhavan. Characterizing and recognizing weak visibility polygons. Computational Geometry: Theory and Applications, 3:213–233, 1993. [164] S. K. Ghosh, A. Maheshwari, S. P. Pal, and C. E. Veni Madhavan. An algorithm for recognizing palm polygons. The Visual Computer, 10:443–451, 1994. [165] S. K. Ghosh and D. M. Mount. An output-sensitive algorithm for computing visibility graphs. SIAM Journal on Computing, 20:888–910, 1991. [166] S. K. Ghosh and S. Saluja. Optimal on-line algorithms for walking with minimum number of turns in unknown streets. Computational Geometry: Theory and Applications, 8:241–266, 1997. [167] S. K. Ghosh, T. Shermer, B. K. Bhattacharya, and P. Goswami. Computing the maximum clique in the visibility graph of a simple polygon. Journal of Discrete Algorithms, to appear, 2007. [168] Z. Gigus, J. Canny, and R. Seidel. Efficiently computing and representing aspect graphs of polyhedral objects. IEEE Transactions on Pattern Analysis and Machine Intelligence, 13:542–551, 1991. [169] P. C. Gilmore and A. J. Hoffman. A characterization of comparability graphs and of interval graphs. Canadian Journal of Mathematics, 16:539–548, 1964. [170] M.C. Golumbic. Algorithmic Graph Theory and Perfect Graphs. Academic Press, New York, USA, 1980. [171] M. T. Goodrich. Triangulating a polygon in parallel. Journal of Algorithms, 10:327–351, 1989. [172] M. T. Goodrich. Parallel algorithms in geometry. In J. Goodman and J. O’Rourke, editors, Handbook of Discrete and Computational Geometry, pages 953–967. CRC Press, New York, USA, 1997. [173] M. T. Goodrich, S. Shauck, and S. Guha. Parallel methods for visibility and shortest
Bibliography
303
path problems in simple polygons. Algorithmica, 8:461–486, 1992. [174] M. T. Goodrich, S. Shauck, and S. Guha. Addendum to ‘parallel methods for visibility and shortest path problems in simple polygons’. Algorithmica, 9:515–516, 1993. [175] R. L. Graham and F. F. Yao. Finding the convex hull of a simple polygon. Journal of Algorithms, 4:324–331, 1983. [176] P. M. Gruber and J. M. Wills, editors. Handbook of Convex Geometry. North-Holland, Amsterdam, The Netherlands, 1993. [177] L. J. Guibas and J. Hershberger. Optimal shortest path queries in a simple polygon. Journal of Computer and System Science, 39:126–152, 1989. [178] L. J. Guibas, J. Hershberger, D. Leven, M. Sharir, and R. E. Tarjan. Linear-time algorithms for visibility and shortest path problems inside triangulated simple polygons. Algorithmica, 2:209–233, 1987. [179] L. J. Guibas, J. Hershberger, J. S. B. Mitchell, and J. Snoeyink. Approximating polygons and subdivisions with minimum-link paths. International Journal of Computational Geometry and Applications, 3:383–415, 1993. [180] L. J. Guibas, J. C. Latombe, S. M. LaValle, D. Lin, and R. Motwani. Visibility-based pursuit-evasion in a polygonal environment. International Journal of Computational Geometry and Applications, 9:471–494, 1999. [181] L. J. Guibas, R. Motwani, and P. Raghavan. The robot localization problem. SIAM Journal on Computing, 26:1120–1138, 1997. [182] E. Gy¨ori, F. Hoffmann, K. Kriegel, and T. Shermer. Generalized guarding and partitioning for rectilinear polygons. Computational Geometry: Theory and Applications, 6:21–44, 1996. [183] P. J. Heffernan. Linear-time algorithms for weakly-monotone polygons. Computational Geometry: Theory and Applications, 3:121–137, 1993. [184] P. J. Heffernan. An optimal algorithm for the two-guard problems. International Journal of Computational Geometry and Applications, 6:15–44, 1996. [185] P. J. Heffernan and J. S. B. Mitchell. An optimal algorithm for computing visibility in the plane. SIAM Journal on Computing, 24:184–201, 1995. [186] J. Hershberger. Finding the visibility graph of a polygon in time proportional to its size. Algorithmica, 4:141–155, 1989. [187] J. Hershberger. Optimal parallel algorithms for triangulated simple polygons. International Journal of Computational Geometry and Applications, 5:145–170, 1995. [188] J. Hershberger and J. Snoeyink. Computing minimum link paths of a given homotopy class. Computational Geometry: Theory and Applications, 4:63–97, 1994. [189] J. Hershberger and S. Suri. Efficient computation of Euclidean shortest paths in the plane. In Proceedings of the 34th IEEE Symposium on the Foundations of Computer Science, pages 508–517. IEEE Computer Society Press, Los Alamitos, CA, USA, 1993. [190] J. Hershberger and S. Suri. A pedestrain approach to ray shooting: shoot a ray, take a walk. Journal of Algorithms, 18:403–413, 1995. [191] J. Hershberger and S. Suri. Matrix searching with the shortest path metric. SIAM Journal on Computing, 26:1612–1634, 1997. [192] J. Hershberger and S. Suri. An optimal-time algorithm for Euclidean shortest paths in the plane. SIAM Journal on Computing, 28:2215–2256, 1999. [193] S. Hertel and K. Mehlhorn. Fast triangulation of the plane with respect to simple polygons. Information and Control, 64:52–76, 1985. [194] F. Hoffmann, M. Kaufmann, and K. Kriegel. The art gallery theorem for polygons with holes. In Proceedings of the 32nd IEEE Symposium on the Foundation of Computer Science, pages 39–48. IEEE Computer Society Press, Los Alamitos, CA, USA, 1991. [195] K. Hoffmann, K. Mehlhorn, P. Rosenstiehl, and R. E. Tarjan. Sorting Jordan sequences in linear time using level-linked search trees. Information and Control, 68:170–184, 1986. [196] M. Hoffmann and C. Toth. Alternating paths through disjoint line segments. Information Processing Letters, 87:287–294, 2003.
304
Bibliography
[197] M. Hoffmann and C. Toth. Segment endpoint visibility graphs are hamiltonian. Computational Geometry: Theory and Applications, 26:47–68, 2003. [198] R. Honsberger. Mathematical Gems II. Mathematical Associations for America, New York, USA, 1979. [199] F. R. Hsu, R. C. Chang, and R. C. T. Lee. Parallel algorithms for computing the closest visible vertex pair between two polygons. International Journal of Computational Geometry and Applications, 2:135–162, 1992. [200] C. Icking and R. Klein. The two guards problem. International Journal of Computational Geometry and Applications, 2:257–285, 1992. [201] C. Icking and R. Klein. Searching for the kernel of a polygon: A competitive strategy. In Proceedings of the 11th Annual ACM Symposium on Computational Geometry, pages 258–266. ACM Press, New York, USA, 1995. [202] C. Icking, R. Klein, E. Langetepe, S. Schuierer, and I. Semrau. An optimal competitive strategy for walking in streets. SIAM Journal on Computing, 33:462–486, 2004. [203] L. Jackson and S. K. Wismath. Orthogonal polygon reconstruction from stabbing information. Computational Geometry: Theory and Applications, 23:69–83, 2002. [204] B. Joe. On the correctness of a linear-time visibility polygon algorithm. International Journal of Computer Mathematics, 32:155–172, 1990. [205] B. Joe and R. B. Simpson. Corrections to Lee’s visibility polygon algorithm. BIT, 27:458–473, 1987. [206] S. Kahan and J. Snoeyink. On the bit complexity of minimum link paths: superquadratic algorithms for problems solvable in linear time. In Proceedings of the 12th Annual ACM Symposium on Computational Geometry, pages 151–158. ACM Press, New York, USA, 1996. [207] J. Kahn, M. Klawe, and D. Kleitman. Traditional galleries require fewer watchmen. SIAM Journal of Algebraic and Discrete Methods, 4:194–206, 1983. [208] G. Kant. A more compact visibility representation. International Journal of Computational Geometry and Applications, 7:197–210, 1997. [209] S. Kapoor and S. N. Maheshwari. Efficiently constructing the visibility graph of a simple polygon with obstacles. SIAM Journal on Computing, 30:847–871, 2000. [210] S. Kapoor, S. N. Maheshwari, and J. S. B. Mitchell. An efficient algorithm for Euclidian shortest paths among polygonal obstacles in the plane. Discrete & Computational Geometry, 18:377–383, 1997. [211] R. M. Karp and V. Ramachandran. Parallel algorithms for shared-memory machines. In J. Van Leeuwen, editor, Handbook of Theoretical Computer Science, volume 1, pages 869–941. Elsevier/The MIT Press, Cambridge, MA, USA, 1990. [212] Y. Ke. An efficient algorithm for link distance problems inside a simple polygon. Technical Report Report JHU-87/28, Department of Computer Science, The Johns Hopkins University, Baltimore, MD, USA, 1988. [213] M. Keil. Finding a hamiltonian circits in interval graphs. Information Processing Letters, 20:201–206, 1985. [214] M. Keil. Minimally covering a horizontally convex polygon. In Proceedings of the 2nd Annual ACM Symposium on Computational Geometry, pages 43–51. ACM Press, New York, USA, 1986. [215] S.-H. Kim, S. Y. Shin, and K.-Y. Chwa. Efficient algorithms for solving diagonal visibility problems in a simple polygon. International Journal of Computational Geometry and Applications, 5:433–458, 1995. [216] D. Kirkpatrick. Optimal search in planar subdivision. SIAM Journal on Computing, 12:28–35, 1983. [217] D. Kirkpatrick, M. Klawe, and R. E. Tarjan. Polygon triangulation in O(n log log n) time with simple data structures. Discrete & Computational Geometry, 7:329–346, 1992. [218] D. Kirkpatrick and S. Wismath. Determining bar-representability for ordered weighted
Bibliography
305
graphs. Computational Geometry: Theory and Applications, 6:99–122, 1996. [219] R. Klein. Walking an unknown street with bounded detour. Computational Geometry: Theory and Applications, 1:325–351, 1992. [220] J. Kleinberg. On-line search in a simple polygon. In Proceedings of the 5th ACM-SIAM Symposium on Discrete Algorithms, pages 8–15. ACM and SIAM, USA, 1994. [221] D. Kozen. The Design and Analysis of Algorithms. Springer-Verlag, New York, USA, 1992. [222] E. Kranakis, D. Krizanc, and L. Meertens. Link length of rectilinear Hamiltonian tours in grids. Ars Combinatoria, 38:177–192, 1994. [223] M. A. Krasnosel’skii. Sur un critere pour qu’un domaine soit etoile. Matematicheskij Sbornik, 19:309–310, 1946. [224] C. Kuratowski. Sur le probl´eme des courbes gauches en topologie. Fundamental Mathematics, 15:271–283, 1930. [225] R. Larson and V. Li. Finding minimum rectilinear distance paths in the presence of barriers. Networks, 11:285–304, 1981. [226] J. C. Latombe. Robot Motion Planning. Kluwer Academic Publishers, Boston, MA, USA, 1991. [227] S. M. LaValle. Planning Algorithms. Cambridge University Press, New York, USA, 2006. [228] S. M. LaValle, B. Simov, and G. Slutzki. An algorithm for searching a polygonal region with a flashlight. International Journal of Computational Geometry and Applications, 12:87–113, 2002. [229] D. T. Lee. Proximity and reachability in the plane. Ph.D. Thesis, Coordinated Science Laboratory, University of Illinois, Urbana-Champaign, IL, USA, 1978. [230] D. T. Lee. Visibility of a simple polygon. Computer Vision, Graphics, and Image Processing, 22:207–221, 1983. [231] D. T. Lee and A. K. Lin. Computational complexity of art gallery problems. IEEE Transactions on Information Theory, IT–32:276–282, 1986. [232] D. T. Lee and A. K. Lin. Computing the visibility polygon from an edge. Computer Vision, Graphics, and Image Processing, 34:1–19, 1986. [233] D. T. Lee and F. P. Preparata. Location of a point in a planar subdivision and its applications. SIAM Journal on Computing, 6:594–606, 1977. [234] D. T. Lee and F. P. Preparata. An optimal algorithm for finding the kernel of a polygon. Journal of the ACM, 26:415–421, 1979. [235] D. T. Lee and F. P. Preparata. Euclidean shortest paths in the presence of rectilinear barriers. Networks, 14:393–415, 1984. [236] J. Lee, S. Park, and K. Chwa. Searching a polygonal room with one door by a 1-searcher. International Journal of Computational Geometry and Applications, 10:201–220, 2000. [237] J. Lee, S. Park, and K. Chwa. Simple algorithms for searching a polygon with flashlights. Information Processing Letters, 81:265–270, 2002. [238] J. Lee, C. Shin, J. Kim, S. Shin, and K. Chwa. New competitive strategies for searching in unknown star-shaped polygons. In Proceedings of the 13th Annual ACM Symposium on Computational Geometry, pages 427–429. ACM Press, New York, USA, 1997. [239] S. H. Lee and K.-Y. Chwa. A new triangulation-linear class of simple polygons. International Journal of Computer Mathematics, 22:135–147, 1987. [240] C. G. Lekkerkerker and J. Ch. Representation of a finite graphs by a set of intervals on the real line. Fundamental Mathematics, 51:45–64, 1962. [241] W. Lenhart, R. Pollack, J.-R. Sack, R. Seidel, M. Sharir, S. Suri, G. T. Toussaint, S. Whitesides, and C. K. Yap. Computing the link center of a simple polygon. Discrete & Computational Geometry, 3:281–293, 1988. [242] N. J. Lennes. Theorems on the simple finite polygon and polyhedron. American Journal of Mathematics, 33:37–62, 1911. [243] S. Y. Lin and C. Y. Chen. Planar visibility graphs. In Proceedings of the 6th Canadian
306
Bibliography
Conference on Computational Geometry, pages 30–35, 1994. [244] S. Y. Lin and S. Skiena. Complexity aspects of visibility graphs. International Journal of Computational Geometry and Applications, 5:289–312, 1995. [245] A. Lingas, A. Maheshwari, and J.-R. Sack. Optimal parallel algorithms for rectilinear link-distance problems. Algorithmica, 14:261–289, 1995. [246] A. Lopez-Ortiz. On-line target searching in bounded and unbounded domains. Ph.D. Thesis, University of Waterloo, Waterloo, Ont., Canada, 1996. [247] A. Lopez-Ortiz and S. Schuierer. Lower bounds for streets and generalized streets. International Journal of Computational Geometry and Applications, 11:401–421, 2001. [248] A. Lopez-Ortiz and S. Schuierer. Searching and on-line recognition of star-shaped polygons. Information and Computation, 185:66–88, 2003. [249] T. Lozano-Perez and M. A. Wesley. An algorithm for planning collision-free paths among polyhedral obstacles. Communications of ACM, 22:560–570, 1979. [250] A. Lubiw. Decomposing polygons into convex quadrilaterals. In Proceedings of the 1st ACM Symposium on Computational Geometry, pages 97–106. ACM Press, New York, USA, 1985. [251] G. MacDonald and T. Shermer. Isomorphism of spiral polygons. Discrete & Computational Geometry, 16:277–304, 1996. [252] A. Maheshwari and J.-R. Sack. Simple optimal algorithms for rectilinear link path and polygon separation problems. Parallel Processing Letters, 9:31–42, 1999. [253] A. Maheshwari, J.-R. Sack, and H. Djidjev. Link distance problems. In J.-R. Sack and J. Urrutia, editors, Handbook of Computational Geometry, pages 519–558. NorthHolland, Amsterdam, The Netherlands, 2000. [254] K. McDonald and J. Peters. Smallest paths in simple rectilinear polygons. IEEE Transactions on Computer Aided Design, 11:264–273, 1992. [255] M. McKenna and G. T. Toussaint. Finding the minimum vertex distance between two disjoint convex polygons in linear time. Computers and Mathematics with Applications, 11:1227–1242, 1985. [256] K. Mehlhorn. Data Structures and Algorithms, Volume 1: Sorting and searching. Springer-Verlag, Berlin, Germany, 1984. [257] K. Mehlhorn. Data Structures and Algorithms, Volume 3: Multi-Dimensional Searching and Computational Geometry. Springer-Verlag, Berlin, Germany, 1984. [258] J. S. B. Mitchell. L1 shortest paths among obstacles in the plane. Algorithmica, 8:55–88, 1992. [259] J. S. B. Mitchell. Shortest paths among obstacles in the plane. International Journal of Computational Geometry and Applications, 6:309–332, 1996. [260] J. S. B. Mitchell. Geometric shortest paths and network optimization. In J.-R. Sack and J. Urrutia, editors, Handbook of Computational Geometry, pages 633–701. NorthHolland, Amsterdam, The Netherlands, 2000. [261] J. S. B. Mitchell, C. Piatko, and E. Arkin. Computing a shortest k-link path in a polygon. In Proceedings of the 33rd IEEE Symposium on the Foundations of Computer Science, pages 573–582. IEEE Computer Society Press, Los Alamitos, CA, USA, 1992. [262] J. S. B. Mitchell, G. Rote, and G. Woeginger. Minimum-link paths among obstacles in the plane. Algorithmica, 8:431–459, 1992. [263] R. Motwani, A. Raghunathan, and H. Saran. Perfect graphs and orthogonally convex covers. SIAM Journal on Discrete Mathematics, 2:431–459, 1989. [264] R. Motwani, A. Raghunathan, and H. Saran. Covering orthogonal polygons with star polygons: the perfect graph approach. Journal of Computer and Systems Science, 40:19–48, 1990. [265] J. I. Munro, M. H. Overmars, and D. Wood. Variations on visibility. In Proceedings of the 3rd Annual ACM Symposium on Computational Geometry, pages 291–299. ACM Press, New York, USA, 1987. [266] G. Narasimhan. On hamiltonian triangulations of simple polygons. International Jour-
Bibliography
307
nal of Computational Geometry and Applications, 9:261–275, 1999. [267] B. J. Nilsson and S. Schuierer. Computing the rectilinear link diameter of a polygon. In Proceedings of International Workshop on Computational Geometry 1991, Computational Geometry-Methods, Algorithms and Applications, Lecture Notes in Computer Science, volume 553, pages 203–215. Springer-Verlag, Berlin, Germany, 1991. [268] B. J. Nilsson and S. Schuierer. An optimal algorithm for the rectilinear link center of a rectilinear polygon. Computational Geometry: Theory and Applications, 6:169–194, 1996. [269] J. O’Rourke. An alternative proof of the rectilinear art gallery theorem. Journal of Geometry, 211:118–130, 1983. [270] J. O’Rourke. Galleries need fewer mobile guards: A variation on Chvatal’s theorem. Geometricae Dedicata, 4:273–283, 1983. [271] J. O’Rourke. Art Gallery Theorems and Algorithms. Oxford University Press, New York, USA, 1987. [272] J. O’Rourke. Computational Geometry in C. Cambridge University Press, New York, USA, 1998. [273] J. O’Rourke and J. Rippel. Two segment classes with Hamiltonian visibility graphs. Computational Geometry: Theory and Applications, 4:209–218, 1994. [274] J. O’Rourke and I. Streinu. Vertex-edge pseudo-visibility graphs: characterization and recognition. In Proceedings of the 13th Annual ACM Symposium on Computational Geometry, pages 119–128. ACM Press, New York, USA, 1997. [275] J. O’Rourke and I. Streinu. The vertex edge visibility graph of a polygon. Computational Geometry: Theory and Applications, 10:105–120, 1998. [276] J. O’Rourke and K. Supowit. Some NP-hard polygon decomposition problems. IEEE Transactions on Information Theory,, IT-29:181–190, 1983. [277] M. H. Overmars and J. V. Leeuwen. Maintenance of configurations in the plane. Journal of Computer and Systems Sciences, 23:166–204, 1981. [278] M. H. Overmars and E. Welzl. New methods for computing visibility graphs. In Proceedings of the 4th Annual ACM Symposium on Computational Geometry, pages 164–171. ACM Press, New York, USA, 1988. [279] M. H. Overmars and D. Wood. On rectangular visibility. Journal of Algorithms, 9:372– 390, 1988. [280] S. P. Pal. Weak visibility and related problems on simple polygons. Ph.D. Thesis, Indian Institute of Science, Bangalore, India, September 1990. [281] S. P. Pal, S. Brahma, and D. Sarkar. A linear worst-case lower bound on the number of holes in regions visible due to multiple diffuse reflections. Journal of Geometry, 81:5–14, 2004. [282] S. Park, J. Lee, and K. Chwa. Searching a room by two guards. International Journal of Computational Geometry and Applications, 12:339–352, 2002. [283] M. A. Peshkin and A. C. Sanderson. Reachable grasps on a polygon: the convex rope algorithm. IEEE Journal on Robotics and Automation, RA-2:53–58, 1986. [284] A. Pnueli, A. Lempel, and S. Even. Transitive orientation of graphs and identification of permutation graphs. Canadian Journal of Mathematics, 23:160–175, 1971. [285] M. Pocchiola and G. Vegter. Minimal tangent visibility graphs. Computational Geometry: Theory and Applications, 6:303–314, 1996. [286] M. Pocchiola and G. Vegter. Topologically sweeping visibility complexes via pseudotriangulations. Discrete & Computational Geometry, 16:419–453, 1996. [287] M. Pocchiola and G. Vegter. The visibility complex. International Journal of Computational Geometry and Applications, 6:279–308, 1996. [288] R. Pollack, M. Sharir, and G. Vegter. Computing of the geodesic center of a simple polygon. Discrete & Computational Geometry, 4:611–626, 1989. [289] D. Prasad, S. P. Pal, and T. Dey. Visibility with multiple diffuse reflections. Computational Geometry: Theory and Applications, 10:187–196, 1998.
308
Bibliography
[290] F. P. Preparata. A new approach to planar point location. SIAM Journal on Computing, 10:473–482, 1981. [291] F. P. Preparata and M. I. Shamos. Computational Geometry: An Introduction. Springer-Verlag, New York, USA, 1990. [292] D. Rappaport. Computing simple circuits from a set of line segments is NP-complete. SIAM Journal on Computing, 18:1128–1139, 1989. [293] D. Rappaport, H. Imai, and G. T. Toussaint. Computing simple circuits from a set of line segments. Discrete & Computational Geometry, 5:289–304, 1990. [294] G. Rawlins. Explorations in Restricted-Orientation Geometry. Ph.D. Thesis, Universtiy of Waterloo, Waterloo, Ont., Canada, 1987. [295] G. Rawlins and D. Wood. Computational geometry with restricted orientations. In Proceedings of the 13th IFIP Conference on System Modelling and Optimization, Lecture Notes in Control and Information Science, volume 113, pages 375–384. Springer-Verlag, Berlin, Germany, 1988. [296] R. Reckhow and J. Culberson. Covering a simple orthogonal polygon with a minimum number of orthogonally convex polygons. In Proceedings of the 3rd Annual ACM Symposium on Computational Geometry, pages 268–277. ACM Press, New York, USA, 1987. [297] J. H. Reif and J. A. Storer. Minimizing turns for discrete movement in the interior of a polygon. IEEE Journal on Robotics and Automation, RA-3:194–206, 1987. [298] H. Rohnert. Shortest paths in the plane with convex polygonal obstacles. Information Processing Letters, 23:71–76, 1986. [299] J.-R. Sack. An O(nlogn) algorithm for decomposing simple rectilinear polygons into quadrilaterals. In Proceedings of the 20th Allerton Conference, pages 64–75. Chicago, USA, 1982. [300] J.-R. Sack and S. Suri. An optimal algorithm for detecting weak visibility of a polygon. IEEE Transactions on Computers, 39:1213–1219, 1990. [301] J.-R. Sack and G. T. Toussaint. Guard placement in rectilinear polygons. In G. T. Toussaint, editor, Computational Morphology, pages 153–175. North-Holland, Amsterdam, The Netherlands, 1988. [302] N. Sarnak and R. E. Tarjan. Planar point location using persistent search trees. Communications of ACM, 29:669–679, 1986. [303] S. Schuierer. An optimal data structure for shortest rectilinear path queries in a simple rectilinear polygon. International Journal of Computational Geometry and Applications, 6:205–226, 1996. [304] S. Schuierer, G. Rawlins, and D. Wood. A generalization of staircase visibility. In Computational Geometry — Methods, Algorithms and Applications: Proc. Internat. Workshop Comput. Geom. CG ’91, Lecture Notes in Computer Science, volume 553, pages 277–287. Springer-Verlag, Berlin, Germany, 1991. [305] S. Schuierer and D. Wood. Staircase visibility and computation of kernels. Algorithmica, 14:1–26, 1995. [306] L.G. Shapiro and R.M. Haralick. Decomposition of two-dimensional shape by graphtheoretic clustering. IEEE Transactions on Pattern Analysis and Machine Intelligence, PAMI-1:10–19, 1979. [307] M. Sharir and A. Schorr. On shortest paths in polyhedral spaces. SIAM Journal on Computing, 15:193–215, 1986. [308] X. Shen and H. Edelsbrunner. A tight lower bound on the size of visibility graphs. Information Processing Letters, 26:61–64, 1987. [309] T. Shermer. Hiding people in polygons. Computing, 42:109–131, 1989. [310] T. Shermer. Recent results in art galleries. Proceedings of the IEEE, 80:1384–1399, 1992. [311] S. Y. Shin and T. C. Woo. An optimal algorithm for finding all visible edges in a simple polygon. IEEE Journal on Robotics and Automation, RA-5:202–207, 1989.
Bibliography
309
[312] D. Sleator and R. E. Tarjan. Amortized efficiency of list update and paging rules. Communications of ACM, 28:202–208, 1985. [313] J. Spinrad, A. Brandstadt, and L. Stewart. Bipartite permutation graphs. Discrete Applied Mathematics, 18:279–292, 1987. [314] G. Srinivasaraghavan and A. Mukhopadhyay. A new necessary condition for the vertex visibility graphs of simple polygons. Discrete & Computational Geometry, 12:65–82, 1994. [315] G. Srinivasaraghavan and A. Mukhopadhyay. Orthogonal edge visibility graphs of polygons with holes. International Journal of Computational Geometry and Applications, 10:79–102, 2000. [316] I. Streinu. Non-stretchable pseudo-visibility graphs. In Proceedings of the 11th Canadian Conference on Computational Geometry, pages 22–25, 1999. [317] I. Streinu. Non-stretchable pseudo-visibility graphs. Computational Geometry: Theory and Applications, 31:195–206, 2005. [318] S. Suri. A linear time algorithm for minimum link paths inside a simple polygon. Computer Graphics, Vision, and Image Processing, 35:99–110, 1986. [319] S. Suri. Minimum link paths in polygons and related problems. Ph.D. Thesis, Department of Computer Science, Johns Hopkins University, Baltimore, MD, USA, 1987. [320] S. Suri. On some link distance problems in a simple polygon. IEEE Journal on Robotics and Automation, 6:108–113, 1990. [321] S. Suri and J. O’Rourke. Worst-case optimal algorithms for constructing visibility polygons with holes. In Proceedings of the 2nd Annual ACM Symposium on Computational Geometry, pages 14–23. ACM Press, New York, USA, 1986. [322] I. Suzuki, Y. Tazoe, M. Yamashita, and T. Kameda. Searching a polygonal region from the boundary. International Journal of Computational Geometry and Applications, 11:529–553, 2001. [323] I. Suzuki and M. Yamashita. Search for a mobile intruder in a polygonal region. SIAM Journal on Computing, 21:863–888, 1992. [324] I. Suzuki, M. Yamashita, H. Umemoto, and T. Kameda. Bushiness and a tight worstcase upper bound on the search number of a simple polygon. Information Processing Letters, 66:49–52, 1998. [325] R. Tamassia and I. Tollis. A unified approach to visibility representations of planar graphs. Discrete & Computational Geometry, 1:321–341, 1986. [326] R. E. Tarjan and C. J. Van Wyk. An O(n log log n)-time algorithm for triangulating a simple polygon. SIAM Journal on Computing, 17:143–178, 1988. Erratum in 17 (1988), 106. [327] H. Tietze. Uber konvexheit im kleinen und im grossen und uber gewisse den punkten einer menge zugeordnete dimensionszahlen. Math. Z., 28:679–707, 1929. [328] G. T. Tokarsky. Polygonal rooms not illuminable from every point. American Mathematical Monthly, 102:867–879, 1995. [329] G. T. Toussaint. An optimal algorithm for computing the minimum vertex distance between two crossing convex polygons. Computing, 32:357–364, 1984. [330] G. T. Toussaint. Shortest path solves edge-to-edge visibility in a polygon. Pattern Recognition Letters, 4:165–170, 1986. [331] G. T. Toussaint and D. Avis. On a convex hull algorithm for polygons and its application to triangulation problems. Pattern Recognition, 15:23–29, 1982. [332] L. H. Tseng, P. J. Heffernan, and D. T. Lee. Two-guard walkability of simple polygons. International Journal of Computational Geometry and Applications, 8:85–116, 1998. [333] J. Urrutia. Art gallery and illumination problems. In J.-R. Sack and J. Urrutia, editors, Handbook of Computational Geometry, pages 973–1023. North-Holland, Amsterdam, The Netherlands, 2000. [334] F. A. Valentine. Convex Sets. McGraw-Hill, New York, USA, 1964. [335] G. Vegter. The visibility diagram: a data structure for visibility problems and motion
310
[336] [337]
[338] [339] [340] [341] [342] [343] [344] [345] [346] [347]
Bibliography planning. In Proceedings of the 2nd Scandinavian Workshop on Algorithm Theory, Lecture Notes in Computer Science, volume 447, pages 97–110. Springer-Verlag, Berlin, Germany, 1990. C. A. Wang. Finding minimal nested polygons. BIT, 31:230–236, 1991. C. A. Wang and E. P. F. Chan. Finding the minimum visible vertex distance between two nonintersecting simple polygons. In Proceedings of the 2nd Annual ACM Symposium on Computational Geometry, pages 34–42. ACM Press, New York, USA, 1986. R. Wein, P. den Berg, and D. Halperin. The visibility-Voronoi complex and its applications. In Proceedings of the 21th Annual ACM Symposium on Computational Geometry, pages 63–72. ACM Press, New York, USA, 2005. E. Welzl. Constructing the visibility graph for n line segments in O(n 2 ) time. Information Processing Letters, 20:167–171, 1985. S. K. Wismath. Characterizing bar line-of-sight graphs. In Proceedings of the 1st ACM Symposium on Computational Geometry, pages 147–152. ACM Press, New York, USA, 1985. S. K. Wismath. Point and line segment reconstruction from visibility information. International Journal of Computational Geometry and Applications, 10:189–200, 2000. T. C. Woo and S. Y. Shin. A linear time algorithm for triangulating a point-visible polygon. ACM Transactions of Graphics, 4:60–69, 1985. D. Wood and P. Yamamoto. Dent and staircase visibility. In Proceedings of the 5th Canadian Conference on Computational Geometry, pages 297–302, 1993. M. Yamashita, H. Umemoto, I. Suzuki, and T. Kameda. Searching for mobile intruders in a polygonal region by a group of mobile searchers. Algorithmica, 31:208–236, 2001. C.-K. Yap. Parallel triangulation of a polygon in two calls to the trapezoidal map. Algorithmica, 3:279–288, 1988. A. Zarei and M. Ghodsi. Efficient computation of query point visibility in polygons with holes. In Proceedings of the 21th Annual ACM Symposium on Computational Geometry, pages 314–320. ACM Press, New York, USA, 2005. Z. Zhang. Applications of visibility space in polygon search problems. Ph.D. Thesis, School of Computing Science, Simon Fraser University, Burnaby, BC, Canada, 2005.
Index
O-staircase path, 11 O-visibility, 11 O-visible, 11 3-clique ordering, 172, 185 3-tree, 172 Abello, J., 171, 172, 174, 178, 183, 185, 186 Adegeest, J., 221 Agarwal, P. K., 12, 173, 253, 256 Aggarwal, A., 9, 170, 220, 242, 250, 289, 291, 292 Aho, A., 31, 35, 36, 64, 66, 86, 285 Aleksandrov, L., 102, 220 algorithm approximation, 10 on-line, 135 optimal, 6 output-sensitive, 137 parallel, 5–6, 43–44, 103, 169, 254, 293 query, 259, 267, 272, 278, 289 sequential, 5 set-union, 276 Alon, N., 173 Alsuwaiyel, M. H., 220 Amato, N., 170 Andreae, T., 173 angular sweep, 32–34, 36 apex of a funnel, 82, 140, 150, 168, 195 Approximation ratio, 10 APX-hard, 10 Arkin, E., 107, 220, 221, 258, 259 Aronov, B., 44, 173, 257 arrangement of line segments, 4, 13, 234 lines, 146 psuedo-lines, 173 art gallery problem, 2, 8, 46, 173 Asano, Ta., 8, 15, 67, 137, 255, 257, 272 Asano, Te., 8, 13, 15, 31, 67, 137, 138, 143, 162, 164, 169, 231, 255–257, 272, 273 asteroidal triple, 190 Atallah, M., 6, 43, 259 Avis, D., 8, 9, 14, 46, 49, 50, 96, 209, 217 Bar-Yehuda, R., 8, 138, 166, 168 base of a funnel, 82, 150, 167, 195 Ben-Moshe, B., 170 Benedikt, M., 14
Bertolazzi, P., 43 Bhadury, J., 220 Bhattacharya, B. K., 8, 15, 23, 49–51, 57, 73, 95, 105–108, 113, 115, 120, 122–124, 173, 174, 208, 214 Biedl, T., 253 bilinear function, 245 Bjorling-Sachs, I., 9 Boissonnat, J., 254 Bondy, J., 202 Booth, H., 220, 242, 250, 289, 291, 292 Booth, K., 191, 194, 195 Bose, P., 256, 257, 267 bounded curvature path, 253 bounding chord, 73–82, 113–124 Brahma, S., 44 Brandstadt, A., 196, 197, 200 Breen, M., 11 Bremner, D., 11, 173 Briggs, A., 2, 102 Brunn, H., 2, 4 Buckinghan, M., 184 C-polygon, 115–124 clockwise, 57, 58, 73–82, 110 counterclockwise, 57, 58, 73–82, 110 Canny, J., 2 cell, 233 Ch, J., 190 chain front, 262 lower, 150, 162, 175, 182, 282 method, 293 opposite, 108 same, 108 side, 262 upper, 150, 162, 175, 182, 282 Chakrabarti, P., 135 Chan, E., 170, 220, 250 Chandrasekran, R., 220 Chandru, V., 104, 220, 226, 229, 244–246, 254, 291, 292 Chang, R., 170 Chazelle, B., 8, 48, 49, 82, 84, 138, 146, 166, 168, 221, 224, 251, 252, 256, 259, 264, 269, 273, 277, 279, 288, 291, 293 Chein, O., 51
311
312 Chen, C. Y., 172 Chen, D. Z., 6, 43–44, 49, 104, 258, 259 Chiang, Y., 258 Chin, F., 170 Choi, S., 172 chord, 49, 174, 180 Chou, S., 12 chromatic number, 184 Chv´ atal, V., 9 Chwa, K., 8, 44, 50, 135, 172 Clarkson, K. L., 170 Cohen, M., 2 Cole, R., 43, 293 Colley, P., 172, 195 competitive ratio, 135 complexity asymptotic, 5 operations, 5 polylogarithmic time, 6 polynomial time, 5 processor number, 6 space, 5 time, 5 component non-redundant, 57, 58 redundant, 57, 58 conductor, 191, 194 convex hull, 16, 95, 165, 202, 230, 249 link path, 226 path, 226 quadrilateral, 9, 201 quadrilaterization, 9 set, 103, 229 Cormen, T. H., 5 Cornell, D. G., 171, 172, 174, 178, 183, 185–187, 194 corridor, 167 Coullard, C, 183 Coullard, C., 172, 173, 185 counter-example, 174, 178, 179, 183 Crass, D., 44 cross-tangent, 92, 127, 266, 283 cross-visible sub-graph, 197, 200 Culberson, J., 11 cutset of a graph, 202 cycle Hamiltonian, 172, 174, 184, 188, 198, 208, 214, 216 ordered, 174, 180, 184 outer, 186 unordered, 184 Daescu, O., 258 Das, G., 49, 50, 57, 73, 106, 221, 259 Dasgupta, D., 220 Dasgupta, P., 135 Datta, A., 135 Davis, A., 44 Davis, L., 14 de Berg, M., 221, 259 de Rezende, P., 170, 259 De Sarkar, S., 135 Dean, J., 12 decomposition
Index balanced, 279 of a polygon, 279 tree, 279 delete operation, 33, 35–37, 164 den Berg, M., 169 Dey, T., 44 diagonal, 6, 82, 278 depth, 280 height, 281 lower, 162 principal separating, 281–288 separating, 281 upper, 162 Djidjev, H., 102, 218–220, 254 Dobkin, D., 2, 292 Doh, J., 50 Donald, B., 2, 102 Dorward, S. E., 1, 2, 13 downward point, 25–29 dual of a planar subdivision, 271 of a triangulation, 6, 82, 85, 166 of an arrangement, 146 duality point-line, 256, 257, 273 eave, 56, 224, 226, 252, 290 Edelsbrunner, H., 9, 146, 162, 234, 236, 256, 259, 262, 269, 272, 273, 293 edge active, 32, 35 constructed, 13, 222, 232, 236, 267–272 convex, 53–56, 58 extension, 141, 224 forward, 18 incoming, 211 inward, 61, 64 left constructed, 69, 141, 267 outgoing, 211 potential, 68 right constructed, 69, 141, 267 valid pair, 211 Efrat, A., 10 Egecioglu, O., 172 Eidenbenz, S., 10, 174 ElGindy, H., 8, 14, 48, 103, 172, 217, 218, 258, 259 envelope, 99–102 equivalent order type, 173 evader, 44 Even, S., 196 Everett, H., 171–174, 178, 183, 185–187, 194, 201 face, 234 fan, 184, 209 convex, 173, 184, 209, 214, 216 vertex, 184, 209, 214, 216 Faugeras, O., 2 Fink, E., 11 Fisk, S., 9 fixed point, 245 forbidden sub-graph, 172, 185 Fournier, A., 8, 173 fractional cascading, 256, 259, 264, 293 Fredman, M. L., 138, 162, 166, 168 Fulkerson, D. R., 189
Index funnel, 82, 140, 150, 167, 195, 258, 278 linear order, 151 sequence, 147, 149, 151, 236 splitting, 83–87 Gabor, C. P., 184 Gabow, N. H., 160, 276 Garcia-Lopez, J., 12 Garey, M. R., 7 geodesic center, 169 diameter, 169, 261 distance, 169 height, 261 path, 169 tree, 261 triangle, 256, 259–267 Gewali, L., 12 Ghodsi, M., 257 Ghosh, S. K., 8, 10, 13, 15, 23, 43, 45, 49, 50, 54–56, 67, 68, 72–74, 80, 87, 102–106, 108, 113, 123, 124, 135, 137, 138, 146, 171, 172, 174, 178–180, 183, 186, 208, 214, 215, 218, 220, 224, 226, 229, 236, 237, 244–246, 248–250, 252, 254, 274, 277, 289, 291, 292 Gigus, Z., 2 Gilmore, P. C., 191 Golumbic, M. C., 184, 189, 190 Goodrich, M. T., 6, 43, 103, 104, 169, 293 Goswami, P., 173, 174, 208, 214 Graham, R. L., 16, 51, 95, 101, 249, 250 graph 3-connected, 172, 185, 204 4-connected, 202 acyclic directed, 146 assignment, 178, 187 bipartite, 195, 196, 200, 205 characterization, 172, 183, 187, 201, 205 chord, 174, 180 chordal, 172, 184, 189 circle, 172, 184 complete, 173 cover, 192 directed, 275 factor, 280 interval, 172, 187, 190, 194 k-connected, 202 layered directed, 292 perfect, 172, 184, 187 permutation, 195, 196, 200 planar, 172, 201 quasi-persistent, 186 recognition, 171, 174, 179, 187, 195, 200, 201, 205 reconstruction, 171 sparse, 170 triangulated, 202 greedy path, 229, 230, 243, 247, 289 Grigni, M., 256, 259 Gross, O. A., 189 Gruber, P. M., 4 guard edge, 8–10 mobile, 8, 9 point, 8–10 stationary, 8, 9
313
vertex, 8–10 Guerra, C., 43 Guha, S., 103, 104, 169, 293 Guibas, L. J., 15, 44, 48, 49, 53, 65, 67, 82, 106, 110, 112, 113, 137, 139, 143, 146, 220, 224, 234, 236, 240, 255–259, 262, 264, 272, 273, 277–279, 288, 290, 292, 293 Gy¨ ori, E., 9 half-plane exterior, 38–40, 42 interior, 38–40, 42, 43 Hall-Holt, O., 170 Halperin, D., 169 Har-Peled, S., 10 Haralick, R. M., 136 Heffernan, P. J., 15, 49, 50, 105–108, 115 Held, M., 107 Hershberger, J., 15, 48, 49, 53, 65, 67, 72, 82, 103, 104, 106, 110, 112, 113, 127, 137–139, 143, 169, 170, 206, 218, 220, 221, 224, 230, 240, 241, 255–259, 264, 272, 278, 279, 288, 290, 292, 293 Hertel, S., 8 hidden vertex set, 173 Hoang, C. T., 173, 201 Hoffman, A. J., 191 Hoffmann, F., 9 Hoffmann, K., 24 Hoffmann, M., 173 hole convex, 161 non-convex, 165, 169 homotopy, 220 Hopcroft, J. H., 31, 35, 36, 64, 66, 86, 285 hourglass, 157, 167, 256, 258, 278–289 closed, 282 open, 282 Hsu, F., 170 Hsu, W., 184 Icking, C., 49, 105, 107, 108, 110, 115, 117, 135 Imai, H., 15, 67, 137, 173, 255, 257, 272 Incerpi, J., 8 induced path, 192 sub-graph, 183, 185, 189, 208 insert operation, 33, 35–37, 164 interval, 243, 289 left, 70 right, 70 inverse Ackermann function, 218 isomorphism of graphs, 174, 216 of polygons, 253 Jackson, L., 173 Joe, B., 14 Johnson, D. S., 7 junction triangle, 167 Kahan, S., 221 Kahn, J., 9 Kameda, T., 44 Kant, G., 173 Kapoor, S., 137, 138, 165, 170
314
Index
Karp, R. M., 5 Katz, M. J., 170 Kaufmann, M., 9 Kavitha, T., 254 Ke, Y., 102 Keil, M., 12, 195 kernel of a polygon, 4, 15, 17, 21, 38, 44 Kilakos, K., 173, 201 Kim, J., 135 Kim, S., 50 Kirkpatrick, D., 8, 173, 262, 264, 269, 272, 274, 277, 282, 288, 291, 292 kite, 260 Klawe, M., 8, 9 Klee, V., 9 Klein, R., 49, 105, 107, 108, 110, 115, 117, 135 Kleinberg, J., 135 Kleitman, D., 9 Klenk, K., 258, 259 Kozen, D., 146, 194, 195, 276 Kranakis, E., 221 Krasnosel’skii, M. A., 4 Kriegel, K., 9 Krizanc, D., 221 Kumar, K., 171, 172, 174, 178, 183, 185, 186 Kuratowski, C., 201 Langetepe, E., 135 Latombe, J. C., 1, 2, 44 LaValle, S. M., 44 Lazard, S., 253 least common ancestor, 82, 111, 140, 281 Lee, D. T., 7, 10, 14–16, 38, 43, 48, 51, 58, 82, 85, 106, 107, 115, 124, 137, 138, 146, 167, 170, 173, 220, 221, 223, 224, 231, 249, 251, 252, 256, 259, 269, 271–273, 277, 282, 286, 291, 293 Lee, J., 44, 135 Lee, R. C. T., 170 Lee, S., 8 Leeuwen, J. V., 284, 286 Leiserson, C. E., 5 Lekkerkerker, C. G., 190 Lempel, A., 196 Lenhart, W., 219, 238 Lennes, N. J., 6 Leven, D., 48, 49, 53, 65, 82, 106, 110, 112, 113, 139, 143, 224, 240, 256, 257, 264, 279, 288 Lin, A. K., 10, 48, 58, 173, 272 Lin, D., 44 Lin, S. Y., 172–174, 214, 217 Lingas, A., 12, 219, 254, 259 link center, 220, 238, 240, 242, 254 diameter, 219, 238, 242 distance, 218, 223, 232, 238 longest, 219 path, 218, 221, 224, 231, 254, 293 radius, 220, 238, 242 sequence, 244, 245, 289 link distance, 258 Lipton, R., 292 Lopez-Ortiz, A., 135 lowest segment, 276 Lozano-Perez, T., 2, 51, 136 Lubiw, A., 9, 172, 173, 183, 185, 195, 256, 257, 267
Lueker, G., 191, 194, 195 MacDonald, G., 173, 253 Maheshwari, A., 8, 43, 49, 50, 54–56, 68, 72–74, 80, 87, 103–105, 124, 174, 215, 218, 220, 221, 226, 229, 244–246, 248, 254, 259, 291, 292 Maheshwari, S. N., 137, 138, 165 maximal clique, 191, 194, 198, 200 outerplanar graph, 172 planar graph, 205 maximum clique, 174, 184, 208, 214, 216 dominating set, 174 hidden vertex set, 173, 214, 216 independent set, 173 McDonald, K., 259 McKenna, M., 170 Meertens, L., 221 Mehlhorn, K., 8, 24, 86, 147, 256, 259 metric, 170, 259 minimal visibility cell, 270–272 minimum convex nested polygon, 220 dominating set, 174 edge guard problem, 10 link path, 218, 221, 224, 231, 238, 240, 254, 258, 289, 292, 293 nested convex polygon, 242, 245, 248, 251 nested non-convex polygon, 248, 252 nested polygon, 220, 254 non-convex nested polygon, 220 point guard problem, 10 rectilinear link path, 221 set-covering problem, 10 vertex cover, 174 vertex guard problem, 10 minor of a graph, 173, 201 Mitchell, J. S. B., 15, 107, 138, 165, 169, 170, 218–221, 231, 258, 259 Mitra, P., 259 Montuno, D. Y., 8, 173 Moran, S., 170 Motwani, R., 11, 44, 256 Mount, D. M., 8, 67, 137, 138, 146, 236, 237, 274, 277 Mukhopadhyay, A., 49–51, 57, 73, 95, 107, 115, 120, 122, 123, 171, 173, 178 Munro, J. I., 12, 256, 257, 267 Murty, U., 202 Narasimhan, G., 49, 50, 57, 73, 106, 107, 115, 120, 122, 123, 221, 259 necessary condition, 172, 180, 183, 184, 186, 190, 193 neighbor of a vertex, 189 Nilsson, B. J., 221 notation A1 , 246 A2 , 246 Aq , 246 C, 268 C(vj , vm ), 209 CCW (vq uj ), 152 CCX(uj vq ), 153
Index CW (vq uj ), 153 CX(uj vq ), 153 Dst , 281 E, 137 Ei , 232 F N L(vs vt ), 151 G(Tq ), 275 GT , 261 Ge , 208 Gf , 202 Gs , 201 Gv , 206 Gve , 206 H(vj , vk ), 215 Hst , 284 K, 242 K5 , 201 K5 -free, 201 K3,3 , 202 L, 188 Lij , 226 M C, 213 M LP (s, t), 221 O(f (n)), 5 P (d), 280 Pij , 226, 290 Q0 , 251 Q0i , 235 Qi , 234 R, 188 R10 , 275 R20 , 275 R30 , 275 REV (uj vq ), 153 RSP (s, t), 259 R1 , 195, 246, 275 R2 , 195, 246, 275 R3 , 275 Rq , 246 Rij , 228, 289 SP (s, t), 51 SP LIT , 155 SP T (s), 82 SP Tc (p, v2 ), 63 SP Tcc (q, vi−1 ), 59 SPc (vj , vk ), 58 SPcc (vj , vk ), 58 Sq , 274 T (P ), 82 Td , 279 Td∗ , 280 Tq , 275 U , 287 V (pq), 58 V (q), 13 Vc (q), 17 Wj , 267 Ω(f (n)), 5 α(n), 231 α, 287 ≺q , 274 bV (vi vi+1 ), 69 bd(P ), 16 bd(vj , vk ), 17 bdc (a, b), 58
315
bdp (z1 , z2 ), 243 bdcc (a, b), 58 chain(vi , vj ), 175 chain(z1 , zk ), 234 d+ s , 287 d− s , 287 d+ t , 288 d− t , 288 dmin , 281 depth(d), 280 f ind(k), 276 gc , 115 gcc , 115 height(d), 281 high(vk ), 192 k(G), 202 link(k), 277 low(vk ), 192 mpath(z1 , zk ), 234 polyc (vi+1 ), 73 polycc (vj−1 ), 73 span, 182 ui di , 222 d1 , 275 d2 , 275 d3 , 275 vi−1 vi , 38 − qv→ k , 16 → − q , 255 Noy, M., 173, 201 NP-hard, 10 Ntafos, S., 12 O’Rourke, J., 2, 5, 6, 9, 10, 14, 15, 49, 66, 137, 146, 172, 173, 205, 220, 233, 242, 250, 273, 289, 291, 292 occluding path, 187 opposite type, 25–29 order of rotation, 146 partial, 274 topological, 276 total, 274 oriented matroid, 173 orthogonal representation, 276 outward convex, 52 Overmars, M. H., 12, 137, 221, 284, 286 pair closest visible, 170 invisible, 175, 180, 187, 206 minimal invisible, 176 potential, 68 separable, 177 visible, 175, 180, 207 Pal, S. P., 8, 44, 49, 50, 54–56, 68, 72–74, 80, 87, 103, 105, 124, 174, 215 Park, S., 44 perfect vertex elimination scheme, 189 Peshkin, M. A., 2 Peters, J., 259 Piatko, C., 220, 221 Pinter, R., 8 Pisupati, S., 171, 174, 178, 185 planar point location, 262, 269, 275, 282, 292
316
Index
planar subdivision, 262, 267, 273, 292 plane sweep, 8, 236, 293 Pnueli, A., 196 Pocchiola, M., 137, 138, 257 pocket, 124–134 left, 267 right, 267 polar angle, 31, 36 Pollack, R., 169, 219, 238 polygon, 2 c-oriented, 221 y-monotone, 7 convex, 4, 39, 170, 242, 245, 248 critical, 74–82 cutting theorem, 279 funnel-shaped, 172 largest convex, 208 nested, 220, 242, 248 non-winding, 14 palm, 103 pruned, 23 rectilinear, 9 similar, 217 simple, 2 smallest perimeter, 166 spiral, 172, 187, 195, 253 staircase, 172 star-shaped, 4, 15, 17, 21, 38, 43, 249 tower, 172, 195, 200, 205 with holes, 2, 31, 66, 146, 161, 165, 231 polygonal subdivision, 220 PRAM CRCW, 6 CREW, 5, 43, 103, 169, 254, 293 EREW, 5, 43–44 Prasad, D., 44 Preparata, F. P., 5, 7, 15, 38, 39, 43, 51, 82, 85, 92, 96, 138, 148, 149, 167, 224, 231, 251, 252, 255, 272, 282, 285, 286, 291, 293 projection function, 245, 246, 289 projection point backward, 243, 246 forward, 243, 246, 291 proper order, 25–29 pursuer, 44 query problems, 255 queue concatenable, 64, 285 merge, 64, 285 split, 64, 285 Raghavan, P., 256 Raghunathan, A., 11 Rajan, V. T., 104, 226, 229, 244–246, 254, 291, 292 RAM, 5 Ramachandran, V., 5 Ramos-Alonso, P., 12 rank, 274, 276 Rappaport, D., 173, 209 Rawlins, G., 11 ray shooting, 255–256, 259–267, 293 Reckhow, R., 11 rectilinear link center, 221
link diameter, 221 link path, 221, 254 nested polygon, 221 path, 259 polygon, 9, 11, 172, 221, 254, 259 shortest path, 170 reflection diffused, 44 specular, 44 Reif, J. H., 258 relation, 274 relative convex hull, 166, 235, 251 reverse greedy path, 244 reverse turn, 60, 88, 96, 126 revolution number, 14, 23, 38, 58 Rippel, J., 173 Rivest, R. L., 5 Robbins, S., 253 Rohnert, H., 138, 161, 165, 168 Rosenstiehl, P., 24 Rote, G., 218, 219, 231 s-deadlock, 117–124 Sack, J., 9, 12, 49, 102, 218–221, 238, 254, 259 Saluja, S., 8, 49, 50, 54–56, 68, 72–74, 80, 87, 104, 105, 124, 135, 174, 215, 226, 229, 244–246, 254, 291, 292 Salza, S., 43 same type, 25–29 Sampson, J., 170 Sanderson, A. C., 2 Saran, H., 11 Sarkar, D., 44 Sarnak, N., 293 Schiuerer, S., 11 Schorr, A., 137 Schuierer, S., 11, 135, 221, 259 search binary, 64, 85, 284, 285 linear, 64, 84 Seidel, R., 2, 146, 219, 238, 273 Semrau, I., 135 separating path, 203 set-union operation, 257 Shamos, M. I., 5, 39, 92, 96, 148, 149, 255, 285, 286 Shapiro, L. G., 136 Sharir, M., 12, 48, 49, 53, 65, 82, 106, 110, 112, 113, 137, 139, 143, 169, 219, 224, 234, 236, 238, 240, 256, 257, 259, 264, 279, 288 Shauck, S., 103, 104, 169, 293 Shermer, T., 2, 9–11, 13, 15, 23, 173, 174, 208, 214, 253 Shin, C., 135 Shin, S., 8, 49, 50, 135, 172 Shor, P., 170 shortest path, 49, 51–55, 103, 138–169, 176, 186, 187, 215, 224, 251, 258, 259, 278–289, 293 map, 141, 224, 241 tree, 49, 82, 103, 111, 207, 224, 229, 240, 258 Simov, B., 44 Simpson, R. B., 14 Skiena, S., 107, 172–174, 214, 217 slab method, 292 Sleator, D., 135 sleeve, 167
Index Slutzki, G., 44 smallest path, 259 Snoeyink, J., 218, 220, 221, 224, 230, 256, 259 sorted angular order, 4, 17, 21, 43, 249, 257, 272, 276 Souvaine, D. L., 9 Spinrad, J., 172, 195–197, 200 Srinivasaraghavan, G., 171, 173, 178 staircase path, 11 Stein, C., 5 Steinberg, L., 51 Stewart, L., 196, 197, 200 Stolfi, J., 262, 293 Storer, J. A., 258 straight path, 192, 194 street, 105, 135 Streinu, I., 171–174, 179, 205 strong ordering, 196 sub-graph, 183 Supowit, K. J., 10, 184 Suri, S., 15, 49, 66, 169, 170, 173, 218–221, 224, 231, 233, 238, 242, 250, 253, 256, 258, 259, 289, 291, 292 Suzuki, I., 44 t-deadlock, 117–124 tail, 260 Tamassia, R., 173, 258 tangent, 161, 166, 265, 283 left, 227, 242 lower, 162 right, 227, 242 upper, 163 Tarjan, R. E., 7, 8, 24, 48, 49, 53, 65, 82, 106, 110, 112, 113, 135, 138, 139, 143, 160, 162, 166, 168, 224, 240, 256, 257, 264, 276, 279, 288, 293 Tazoe, Y., 44 Teichmann, M., 257 Teller, S., 2 theorems LR-visibility characterization, 108 LR-visibility computation, 113 LR-visibility recognition, 115 hidden vertex set, 216 link center computation, 242 link diameter computation, 242 link path computation, 224, 231, 238 link path query, 292 link radius computation, 242 maximum clique, 214 nested polygon, 245, 248, 249, 251, 252 point visibility computation, 23, 35, 38 point visibility query, 269, 272, 278 point visibility recognition, 43 polygon triangulation, 8, 149 polygon walk, 117, 122, 124 polygon winding, 31 ray-shooting query, 262, 267 shortest path computation, 138, 165, 169 shortest path query, 286, 289 shortest path tree computation, 85, 87, 95, 134 visibility graph computation, 143, 146, 161, 165, 168 visibility graph construction, 207, 208
317
visibility graph recognition, 183, 194, 195, 197, 201, 205 weak visibility characterization, 55, 56 weak visibility computation, 64, 66, 68 weak visibility recognition, 73, 82, 102 Tietze, H., 4 Tokarsky, G.T., 44 Tollis, I., 173 topological sorting, 146, 276 Toth, C.,, 173 Toussaint, G. T., 8, 9, 46, 48–51, 53, 95, 96, 103, 169, 170, 173, 219, 238 trapezoid method, 293 traversal depth-first, 194 postorder, 151 preorder, 151 tree, 6 balanced, 32, 34, 163 binary, 31, 34 decomposition, 279 finger search, 86, 160 free, 261, 263 geodesic, 261 height, 31 height balanced, 149, 285 level-linked, 24 lower, 151 search, 85, 86 upper, 151 weight-balanced binary, 259, 263 window, 258 triangulation balanced geodesic, 259 Hamiltonian, 107, 188 of a polygon, 6, 82, 103, 224, 251, 274, 278 plane sweep, 147 Tseng, L. H., 106, 107, 115 Tu, H., 259 turning point, 222, 227, 232, 243, 289 Ullman, J. D., 31, 35, 36, 64, 66, 86, 285 Umemoto, H., 44 update operation, 33, 35–37 upper node, 287 upward point, 25–29 Urrutia, J., 2, 9, 10 Vaidya, P., 170 Valentine, F. A., 4 Van Wyk, C. J., 8 Vegter, G., 137, 138, 169, 257 Veni Madhavan, C. E., 8, 49, 50, 54–56, 68, 72–74, 80, 87, 103, 105, 124, 174, 215, 220 vertex antipodal, 96–102 blocking, 175, 181, 192, 208, 210 consecutive visible, 180 convex, 2 cut, 202 furthest adjacent, 211 labeled, 198 overlaying, 193, 194 reflex, 2 simplicial, 189
318
Index
unlabeled, 198 vertical ordering, 147 visibility LR, 105–135 k, 220, 238 cell, 256, 267–272 chord, 49, 50, 68, 72–82, 87 circular, 12 clear, 11 complete, 46, 49, 218, 224, 250 complex, 257 external, 50 omni-directional, 44 rectangular, 11, 12 staircase, 11 strong, 46 weak, 46, 48, 49, 59, 103, 218, 221 with reflection, 44 X-ray, 12 visibility graph, 136, 161, 169–171, 174, 183, 187, 195, 200, 206, 208, 214, 216, 218, 234, 236, 238 edge-edge, 173, 208 enhanced, 147, 152 non-isomorphic, 216 point, 173 segment, 173, 201, 205 tangent, 161, 165, 168 vertex, 206 vertex-edge, 173, 205, 208 visibility polygon LR, 105–135 complete, 47, 48, 103, 229 external, 51, 95–102 of a point, 13, 16, 43, 124, 221, 231, 249, 255, 267–278 of a segment, 49, 232 of a set, 102 weak, 47–49, 51–55, 58, 64, 66, 68, 73, 75–77, 87, 103, 222, 257 visible apex, 155 clearly, 11 rectangularly, 12 segment, 139, 143, 195, 201 staircase, 11 X-ray, 12 Voronai diagram, 169 Wagner, H., 43 walk, 107–108, 115–124 discretely straight, 107 straight, 107 walkable, 107 Wallace, J., 2 Wang, C. A., 170, 220, 250 watchman tour, 220, 221 wedge, 39, 249 Wein, R., 169 Welzl, E., 9, 67, 137, 143 Wesley, M. A., 2, 51, 136 Whitesides, S., 219, 238, 253 Wills, J. M., 4 window, 148 window partition, 238, 241 Wismath, S., 173
Woeginger, G., 218, 219, 231 Woo, R. C., 12 Woo, T. C., 8, 49 Wood, D., 11, 12 Wu, Y. F., 170, 259 Yamamoto, P., 11 Yamashita, M., 44 Yao, F. F., 16, 51, 95, 101, 249, 250 Yap, C. K., 103, 219, 220, 238, 242, 250, 289, 291, 292 Zarei, A., 257 Zhang, L., 257 Zhang, Z., 44