Visibility Queries in Simple Polygons
Abstract
Given a simple polygon with vertices, we consider the problem of constructing a data structure for visibility queries: for any query point , compute the visibility polygon of in . To obtain query time, where is the size of the visibility polygon of , the previous best result requires space. In this paper, we propose a new data structure that uses space, for any , while achieving the same query time. If only space is available, the best known result provides query time. We improve this to time. When restricted to space, the only previously known approach, aside from the -time algorithm that computes the visibility polygon without preprocessing, is an -space data structure that supports -time queries. We construct a data structure using space that answers visibility queries in time. In addition, for the special case in which lies on the boundary of , we build a data structure of space supporting query time; alternatively, we achieve query time using space. To achieve our results, we propose a new method for decomposing simple polygons, which may be of independent interest.
Keywords and phrases:
simple polygons, visibility polygons, visibility queries, polygon decompositionsCategory:
Track A: Algorithms, Complexity and GamesFunding:
Sujoy Bhore: Work supported in part by ANRF ARG-MATRICS, Grant 002465.Copyright and License:
André van Renssen, Frank Staals, Haitao Wang, and Jie Xue; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Computational geometry ; Theory of computation Design and analysis of algorithmsAcknowledgements:
This work originated at Shonan Meeting No. 234, “Path Planning and Routing in Geometric Environments.” We thank the participants for their valuable discussions, and we are also grateful to the organizers and the National Institute of Informatics for hosting the event.Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele PuppisSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Let be a simple polygon with vertices. A point is said to be visible to a point if the line segment lies entirely inside . The visibility polygon of is the set of all points in that are visible to ; see Figure 1. It is well known that is a star-shaped polygon whose vertices are either: (i) vertices of , or (ii) intersection points between edges of and rays from passing through reflex vertices of .
In this paper, we study data structures for visibility queries: given a query point , compute the visibility polygon efficiently.
Previous work.
can be computed in time without any preprocessing [10, 18, 16]. If -time ray-shooting queries are available, then can be computed in time [2], where is the size of . Such ray-shooting data structures can be constructed in time [10, 9, 20]. Ideally, one would like a query algorithm whose running time is linear in the output size, i.e., . Data structures achieving this are known, but at the cost of larger space. Bose, Lubiw, and Munro [3], and independently Guibas, Motwani, and Raghavan [19], obtained query time using space and preprocessing time. Aronov, Guibas, Teichmann, and Zhang [2] constructed a data structure of space in time that supports -time visibility queries. Note that is the optimal query time [3, 19].
Our results.
There has been no progress on this problem for almost three decades since the conference version of [2] was published in 1998. In this paper, we present the following new results.
-
First, we give the first-known subquadratic-space structure that achieves a query time linear in the output size: a data structure of space, preprocessing time, and query time. Throughout the paper, represents an arbitrarily small positive constant. Furthermore, we obtain the following trade-offs between the query time and preprocessing: for a parameter satisfying , we can build a data structure of space , preprocessing time, and query time. Note that this result implies that for a large (e.g., ), we can achieve query time with sub-quadratic preprocessing.
-
Third, under an space budget, we improve the query time in [2] to , with a preprocessing time of .
Table 1 summarizes these bounds alongside prior work.
| Results | Query time | Space | Preprocessing time |
|---|---|---|---|
| [9, 20] | |||
| [3, 19] | |||
| [2] | |||
| Ours (near-linear space) | |||
| Ours (optimal query time) | |||
| Ours (quadratic space) |
In addition, we study a natural special case in which the query point lies on the boundary of . To the best of our knowledge, this boundary case has not been treated separately in the literature. We obtain a data structure of space and preprocessing time that answers queries in time. Alternatively, we can achieve query time using space and preprocessing time.
Other related work.
Several related visibility query problems have also been studied. Chen and Daescu [11] considered a segment-restricted version, where the query point lies on a given segment in . Their data structure uses space and supports queries in time. However, their approach does not appear to extend to arbitrary query points.
Given a segment , a point is weakly visible to if it is visible to at least one point of . The weak visibility polygon of consists of all points of visible to , and can be computed in time [18]. The corresponding weak visibility query problem, i.e., computing this polygon for an arbitrary query segment, has been investigated in several works [13, 2, 4, 3]. Using space and preprocessing time, one can support queries in time; alternatively, using space and preprocessing time, queries can be answered in time [13].
1.1 An overview of our approach
The methods of [3, 19] decompose into cells such that the combinatorial structure of is the same for every point in the same cell. Since the decomposition itself has cubic size, these approaches cannot be directly adapted when one wishes to use subcubic space.
The approach [2] instead builds on the balanced decomposition of [18, 17, 10] (see Section 2 for more details). Their method achieves query time using space. The factor in query time appears inherent to the balanced decomposition: each subpolygon may be connected to the “outside world”, i.e., the rest of , by diagonals and the decomposition has recursive levels.
To obtain query time with subcubic space, we therefore require a new strategy. Our main idea is to introduce a new polygon decomposition with a crucial structural feature (which we call the gate property): every subpolygon connects to the outside world through a single diagonal, which we call its gate. As in the balanced decomposition, we recursively divide into subpolygons whose sizes shrink geometrically; however, the gate property fundamentally changes how visibility information propagates across subregions.
Intuitively, suppose a query point lies in a subpolygon with gate . If we have already computed the portion of visible to , denoted by , then the remaining part of the visibility region, , is exactly the portion of visible through the diagonal . We refer to computing this region as the diagonal-separated subproblem. The entire query algorithm reduces to solving this subproblem and recursing inside (i.e., to compute , we can apply the algorithm recursively).
Our optimal-query-time data structure is built on this decomposition and uses recursive steps by choosing a parameter . This yields space and query time. Our quadratic-space data structure also relies on our new decomposition but groups its levels into super-levels. This reduces the space to at the cost of increasing the query time to . In contrast, the balanced decomposition of [2] has levels, resulting in an unavoidable factor.
Our near-linear space data structure follows the high-level strategy of [2] but solves the diagonal-separated subproblem more efficiently. While [2] used an -space data structure supporting queries for this subproblem, we instead reduce the problem to simplex stabbing queries and adapt the recent structure of Chan and Zhang [5]. This gives an -space structure supporting queries in time, yielding our result.
For the boundary case, the diagonal-separated subproblem simplifies substantially: with constrained to lie on the boundary of , the remaining computation becomes essentially one-dimensional. We obtain a solution of space and query time. Plugging this into the balanced decomposition method of [2], we obtain our first data structure for the boundary case. Plugging this into our new decomposition yields our second data structure.
Outline.
In the following, after introducing notation in Section 2, we present our near-linear space data structure in Section 3. In Section 4, we describe our new polygon decomposition, which serves as a key component for the optimal-query-time data structure in Section 5 and the quadratic-space solution in Section 6. Due to the space limit, many details and proofs are omitted, but can be found in the full paper. The boundary case is also in the full paper.
2 Preliminaries
We follow the notation introduced in Section 1, e.g., , , and . For any subpolygon , we define , i.e., the portion of contained in .
For convenience, we assume that each edge of is an open segment that does not include its endpoints; thus, the vertices of are disjoint from its edges. We refer to either a vertex or an edge of as an element of . For any geometric object , let denote its boundary. For two points and , denotes the line segment connecting them.
It is well known that is star-shaped and can be represented by a cyclic (say, clockwise) list of its vertices. Alternatively, given the cyclic list of vertices and edges of that appear on the boundary , one can reconstruct in time [2, 3]. Hence, to compute , it suffices to determine this cyclic list, called the combinatorial representation of [2]. It is also known that this cyclic order of vertices and edges of on is consistent with their order along . In the following, depending on the context, we may use to refer to its combinatorial representation.
Balanced decomposition.
We will use the balanced decomposition of , which has been applied to various problems in simple polygons [2, 18, 17, 10]. A diagonal is a line segment connecting two vertices of that is fully contained in but not an edge of . Chazelle [6] proved that always admits a diagonal that splits it into two subpolygons, each having between and vertices. The balanced decomposition of is obtained by recursively partitioning each subpolygon using such diagonals until all subpolygons are triangles. This decomposition can be represented by a tree , called the BD-tree. Each node of corresponds to a subpolygon of : the root corresponds to itself, and each leaf corresponds to a triangle. The diagonal used to partition into its two child subpolygons is stored at and denoted by . The triangles at all leaves of form a triangulation of . The entire decomposition and BD-tree can be computed in time [17, 7].
Convention on stating query time.
For simplicity, when we state that a data structure supports queries in time for computing (or a portion thereof, e.g., for a subpolygon ), we mean that a (balanced) binary search tree storing the combinatorial representation of can be computed in time, and the full visibility polygon can then be output in an additional time.
For conciseness, we say that a data structure has complexity if its preprocessing time, space, and query time are , , and , respectively.
3 A near-linear space data structure
In this section, we present our near-linear space data structure. Our algorithm follows the general framework of [2], but we address a key component, the diagonal-separated subproblem, in a different way, as discussed in Section 1.1. This subproblem arises in essentially all of our subsequent data structures. The same framework will also be partially used in our quadratic-space data structure in Section 6 and in the boundary case. Therefore, the discussions in this section are also instrumental to the later parts of the paper.
We first discuss the diagonal-separated subproblem in Section 3.1, present its linear-space solution in Section 3.2, and finally describe the general algorithmic framework in Section 3.3.
3.1 A diagonal-separated subproblem
Let be a diagonal that divides into two subpolygons and . Without loss of generality, assume that is vertical and lies locally to the left of . The diagonal-separated subproblem is to compute for any query point . We describe our solution below.
Since , for any point , must cross . In other words, the visibility of within occurs “through” . Because is a simple polygon, is a contiguous segment of [2]. Let . If , then . Otherwise, let denote the cone formed by the rays from through all points ; we say that is defined by and , and refer to as the apex of the cone (see Figure 2).
Using the two-point shortest path data structure of Guibas and Hershberger [17] (henceforth referred to as the GH data structure), the two bounding rays of can be computed in time via shortest-path queries. To compute , it thus suffices to determine the portion of visible to through the cone .
We use to denote . We also define an analogous notion , which consists of all points such that crosses and , where . Note that whether the segment lies inside is irrelevant. See Figure 3.
Following [2], we first compute a binary search tree that stores the combinatorial representation of , i.e., the cyclic order of the elements of (recall that an element refers to either a vertex or an edge of ) appearing on . We then perform a clipping operation on this tree using ; the resulting tree represents .
Observation 1.
We sort all elements of along its boundary and assign each of them an index in this order. Let denote the set of elements of that appear on . By Observation 1, the elements of are sorted in index order in the combinatorial representation of .
For each vertex , as discussed above, all points of visible to within form a segment of . Let denote the cone defined by and . Observe that belongs to if and only if . For each edge of , as discussed in [18], the points of weakly visible to also form a segment of , such that belongs to if and only if lies in the cone defined by and a point to the left of (see Figure 4).
For reference, we summarize the above discussion in the following observation.
Observation 2.
For each vertex (resp., edge ) of , (resp., ) appears in the combinatorial representation of if and only if lies in the cone (resp., ).
All cones and for the vertices and edges of can be computed in time using the shortest path trees of the two endpoints of [18]. Let denote the set of all these cones. We refer to (resp., ) as the generator of (resp., ). To compute , by Observation 2, the problem reduces to the following cone stabbing query: given , compute all cones of that are stabbed by (we say that a cone is stabbed by if the cone contains ). To accommodate the clipping operation with , we require the data structure to return a binary search tree storing the generators of the stabbed cones in their index order.
A quadratic-space solution.
A quadratic-space solution is given in [2]. We briefly review it below as it also serves as a subroutine in some of our later algorithms.
Let denote the halfplane to the right of the supporting line of . If , then , so we assume . Let be the arrangement in formed by the supporting lines of the bounding rays of all cones in . By Observation 2, points in the same cell of share the same (combinatorial representation of) , and of in adjacent cells differ by at most one element of . Since there are cones, has cells.
We use persistent binary search trees [26, 14] to store the combinatorial representations of for all cells of in a total of space and preprocessing time. Additionally, we construct a point location data structure on in time and space [26, 22, 15]. Given a query point , we can locate the cell of containing in time and thereby obtain access to the corresponding binary search tree that stores . This yields a data structure of complexity , i.e., preprocessing time, space, and query time for computing for any .
The boundary case.
In the boundary case, each query point is on . In this case the cone stabbing queries become 1D interval stabbing queries on . Using persistent trees [26, 14], we obtain a data structure of complexity . This result combining with the algorithmic framework given in Section 3.3 yields a data structure of complexity for computing . See the full paper for details.
3.2 A linear-space solution to the diagonal-separated subproblem
We now present our solution to the cone stabbing problem and thus solve the diagonal-separated subproblem.
Overview.
Our algorithm computes a collection of “canonical subsets” of , where each subset is represented by a binary search tree storing the cone generators in their index order. We perform a clipping operation on each tree using the cone . The elements remaining in the clipped trees of all canonical subsets collectively form the set , which consists of the elements of lying on . We then sort the elements of by their index order to obtain . Finally we build a binary search tree to store them and return this tree as the answer to the query. The details are given below.
We adapt Chan and Zhang’s data structure [5, Section 3.1] for simplex stabbing queries (given a query point , compute all simplices stabbed by among a set of given simplices; each of our cones is a special simplex in 2D). The data structure has multiple levels and it is constructed using Matoušek’s simplicial partition [24]. To solve our problem, we can build the data structure on the cones of with levels. We briefly discuss this and the reader is referred to [5, Section 3.1] for details.
Determining whether is in a cone is equivalent to testing whether is in the intersection of two halfplanes bounded by the cone’s bounding lines. In the dual plane, this is to check whether the dual line of lies in the “correct” side of the two dual points of the bounding lines of the cone. We apply Matoušek’s simplicial partition [24] on the dual points of the -th halfplanes of the cones of , with . For each cell of the partition that intersects , we recurse on the canonical subset of the dual points of . For each cell lying entirely below (or above , depending on which is the correct side), we recurse on the canonical subset of but as a level-() problem. For each canonical subset in a level-0 problem, we build a binary search tree to store all generators of cones in the subset. Following the analysis in [5, Section 3.1], the resulting data structure is of space and can be constructed in time.
Given a query point , the query algorithm returns canonical subsets whose union corresponds to the set of cones of stabbed by . For each canonical subset, we perform a clipping operation using the cone , taking additional time. Hence, we can compute in time, which simplies to since the factor is absorbed by .
Once is obtained, we must sort its elements by their index order. A straightforward comparison sort would require time, introducing an undesired logarithmic factor in the overall query time. However, since the index of each element of is an integer in , we can perform the sorting in time using radix sort in the following lemma.
Lemma 3.
For any , the elements of can be sorted by their indices in time.
Proof.
Let denote the set of indices of the elements in , and our goal is to sort the integers in . Since each index in is an integer in , it can be represented using at most bits. We partition these bits into groups, each consisting of bits. We refer to each such group as a digit. Hence, each integer in has digits. We apply radix sort on the integers of using these digits. Sorting by a single digit requires time. Since there are only digits, the entire sorting process takes passes, resulting in a total running time of .
After is sorted, we obtain the combinatorial representation of . We then construct a binary search tree to store this representation in an additional time. Combining all the above results yields the following lemma.
Lemma 4.
Given a simple polygon of vertices and a diagonal dividing into two subpolygons and , a data structure of space can be constructed in time such that can be computed in time for any point .
3.3 A general algorithmic framework
We now describe the algorithmic framework. In the preprocessing, we compute a balanced decomposition of together with the BD-tree as defined in Section 2.
Given a query point , let be the leaf of whose triangle contains . The query algorithm proceeds in a bottom-up manner along the path from to the root of . For each node on this path, let denote the parent of and the sibling of (i.e., the other child of ). Suppose that has already been computed (this is true initially when since ). Our goal at node is to compute , which equals the union of and .
By definition, is partitioned into and by the diagonal . Since is known, we next compute and then merge and along to obtain . Computing is precisely an instance of the diagonal-separated subproblem. Therefore, in the preprocessing, for each node , we construct a diagonal-separated data structure for both and (with respect to ). During a query, these data structures allow us to compute efficiently.
Once is computed, we obtain by merging and along . Note that if , then ; otherwise, must be an edge of . Merging and can be done in time. For reference purpose, we use Lemma 5 to summarize this merging step (see the full paper for the proof). After computing , the algorithm continues upward until reaching the root of , at which point is obtained.
Lemma 5.
Suppose a diagonal divides into two subpolygons and . Let be a point in . Given a binary search tree storing and a binary search tree storing , we can obtain a binary search tree storing in time.
If we plug the quadratic-space diagonal-separated data structure of [2] (also reviewed in Section 3.1) into the framework, then, since the sizes of the subpolygons decrease geometrically along any root-to-leaf path of , we obtain a data structure of complexity for computing for any . This is the result of [2].
If we instead apply our linear-space result from Lemma 4, then, because the total size of all subpolygons at each level of is (as they form a partition of ), we obtain a data structure of complexity . Furthermore, by applying a somewhat standard tradeoff technique based on hierarchical cuttings [8] in conjunction with Lemma 4, we can obtain the following result (see the full paper for the detailed proof).
Theorem 6.
Given a simple polygon with vertices, let be a parameter satisfying for any constant . A data structure of size can be constructed in time such that can be computed in time for any query point . In particular, setting yields a data structure of space, preprocessing time, and query time.
4 A new polygon decomposition
In this section, we introduce a new decomposition of together with its associated data structure for answering visibility queries.
Our decomposition decomposes into geodesic triangles, a concept first introduced in [9], in which a balanced geodesic triangulation of was proposed and it also decomposes into geodesic triangles. However, our decomposition differs fundamentally from the balanced geodesic triangulation in [9] and possesses several key properties, such as the gate property described in Section 1.1, that are essential for the efficiency of our visibility query algorithm.
In the following, after defining geodesic triangles, we present a data structure for handling visibility queries with respect to a single geodesic triangle in Section 4.1. We then describe our new polygon decomposition in Section 4.2.
Geodesic triangles.
The geodesic path is a shortest path in between two points and . For three vertices , , and of ordered clockwise along , consider the three geodesic paths , , and . If we remove the subpaths shared by any two of these three paths, then the region bounded by the remaining portions of the three paths is a geodesic triangle; see Figure 5. A geodesic triangle has three sides, each being a concave chain that is a subpath of one of the three geodesic paths, and three apexes, corresponding to the endpoints of its sides. In general, a geodesic triangle has exactly three apexes, although it may degenerate to an empty region when one of the three vertices , , or lies on the geodesic path connecting the other two.
4.1 A data structure for geodesic triangles
Consider a geodesic triangle , defined by three vertices , , and as discussed above. Each edge of is either an edge of or a diagonal. For each diagonal on , let denote the subpolygon of bounded by that does not contain . We refer to as the pocket of separated by from . For simplicity, if is an edge of , we let denote itself. When is clear from context, we simply write .
We study two subproblems with respect to . In the first subproblem, the query point lies in , and the goal is to compute . In the second subproblem, the query point lies in for some diagonal of , and we wish to compute , i.e., the portion of that lies outside the pocket . Our result is summarized in the following lemma, which will be used later. The proof is in the full paper.
Lemma 7.
With respect to a geodesic triangle , a data structure of size can be constructed in time such that, for any query point , if , then can be computed in time, and if for some diagonal on the boundary of , then can be computed in time.
Intuitively, the motivation for having a query algorithm that computes is as follows. If is already available, then after obtaining , we can compute by merging the two. To compute itself, we would like to apply the same algorithm recursively. For this recursive approach to work, we require an “appropriate” polygon decomposition of . This motivates the new decomposition introduced in Section 4.2.
4.2 The new decomposition
We now introduce a new decomposition of , defined with respect to a designated edge of . Let be the vertices of ordered clockwise along . In the following, we describe the decomposition with respect to the edge .
We represent the decomposition by a decomposition tree . Let denote the root of . Each node of corresponds to a subpolygon and a gate , where is a diagonal of that separates from the “outside world” , and all other edges of are edges of . Initially, we have and (since is the root, as a special case we allow not to be a diagonal, i.e., we assume connects with the outside).
Each node also corresponds to a subpolygon , called the core of , which is the union of a collection of geodesic triangles. The core and the subpolygons of all children of form a partition of (thus for each child ). Moreover, for every child of , we have . Hence, the sizes of the subpolygons decrease geometrically along any root-to-leaf path in , and the height of is .
At each node of , we explicitly store the edges of . The cores of all nodes are interior-disjoint and together form a partition of . Since no new vertices are introduced and no two edges of the decomposition intersect, the overall size of the decomposition and thus the total size of all cores is . Because each core consists of geodesic triangles, our decomposition effectively partitions into geodesic triangles.
As will be seen later, when our decomposition is used to answer visibility queries, the property that the gate separates from plays a crucial role. We refer to this as the gate property. Moreover, for any node and any ancestor of , since , the gate property also implies that separates from .
Section 4.3 presents the detailed construction of the decomposition . The following Theorem 8 is our main result for answering visibility queries using . Our results in Sections 5 and 6 will build upon this theorem.
Theorem 8.
A data structure of size can be constructed in time for the decomposition such that, for any query point , if lies in the core of a node , then can be computed in time; and if lies in for a child of , then can be computed in time.
Proof.
We only sketch the proof here; full details can be found in the full paper.
Consider the root of . For each geodesic triangle in the core , we build the data structure of Lemma 7 for in (which equals ). We can show that this construction requires space and preprocessing time. Afterward, for any query point , if , we can compute in time; and if for a child of , we can compute in time.
In general, for each node , and for each geodesic triangle in , we build the data structure of Lemma 7 for within . This requires space and preprocessing time, where . Since the sizes of the subpolygons decrease geometrically along every root-to-leaf path, and since the subpolygons of nodes at the same level of are interior disjoint, the total space over all nodes of is , and the total preprocessing time is . After this preprocessing, the queries can be answered as stated in the theorem.
4.3 The construction of the decomposition
We present the details of our decomposition and the decomposition tree .
During the discussion, instead of directly arguing the gate property, we will establish two other properties that together guarantee the gate property as shown in the following lemma.
Lemma 9.
Suppose that the following two properties hold for each non-root node : (1) separates from , where is the parent of ; (2) the gate of is not in . Then, the gate property holds for , i.e., separates from .
Proof.
We prove the lemma by induction. Initially, if is a child of the root , then since separates from , , and , it is vacuously true that separates from .
We now inductively assume that separates from . We next argue that separates from . Indeed, consider two points and with and . It suffices to show that the geodesic path must intersect . If is in , then since separates from , then must intersect . If , then . In this case, since , , and separates from , if we traverse from to along , we must first cross and then . The lemma thus follows.
We next describe our decomposition. We will focus on explaining the children of . Specifically, we will define the core , the subpolygons , and the gate for every child of . In particular, we will argue that the following three key properties hold for each : (1) is separated from by ; (2) is not in ; (3) has no more than edges other than the gate . Note that the first two properties are those required in Lemma 9. To define the whole tree , we simply apply the same decomposition recursively on for each child of .
Let , the middle point of (recall that vertices of are indexed from to clockwise around ). We consider the geodesic triangle formed by the three geodesic paths , , and . Note that is the edge . We first consider the general case where is not empty, and we will discuss later that the empty case can be treated similarly. We add to the core .
Note that is one side of and thus and are two apexes of . Let be the third apex (see Figure 6). Note that is the union of the other two sides of .
Let denote the boundary of from clockwise to and the boundary of from clockwise to . We let both and contain . Hence, . We say that a diagonal is a bridge if one vertex of it is in while the other is in . By definition, if , then has no bridge; otherwise, has exactly one bridge, denoted by , which must have as a vertex (see Figure 6, where ).
For each diagonal of , if is not a bridge, then it connects two vertices either both on or both on . Recall we defined in Section 4.1 that the notation refer to the pocket of separated by from (see Figure 6). Observe that the edges of other than are all in or all in . Hence, has no more than edges other than . We create a child for in with and the gate . In this way, separates from and is not an edge of . Hence, all three key properties hold for .
If is a bridge, i.e., , then . In this case, contains vertices from both and (see Figure 6), and therefore, may have more than edges other than . We therefore cannot simply create a child for as above and need to resort to other approaches as follows.
Decomposing into subpockets.
Let be the vertex of other than (see Figure 6). Then, is a subpath of either or . To simplify the notation, let and .
The geodesic path decomposes the pocket into subpockets each of which is bounded by a subpath of and a sequence of edges of or . If a subpocket is bounded by a subpath of and a sequence of edges of (resp., ), we call it a -bounded subpocket (resp., -bounded subpocket); see Figure 7. For each subpocket , the subpath of on the boundary of is called the base of . We say that is closed if its base is a single edge; otherwise, it is open (see Figure 7).
For a closed subpocket , since its edges other than its base edge are either all from or all from , the number of its edges other than its base is at most , and is separated from by its base edge. Hence, we create a child for in with and as the base edge of . Clearly, is not in . Hence, all three key properties hold for .
If is open, then we will need to further decompose it. The situation in this case becomes significantly more complicated and our main effort is to handle this case. Without loss of generality, we assume that is -bounded.
Decomposing an open subpocket .
Define . We consider a special subpocket. Following our above definition, is a closed subpocket since it has only one edge of . To differentiate, when we say “subpockets of ”, we refer to all subpockets of and also ; when we say “subpockets of ”, we only refer to the subpockets inside . Unless otherwise stated, a subpocket of refers to any subpocket of .
To simplify the discussion, we assume that each edge of is a diagonal. Indeed, this is the most general case because if is an edge of then we can assume there is an infinitely small subpocket separated by . With this assumption, is on the boundaries of two subpockets of . In particular, if is a vertex of , then one subpocket bounded by is closed while the other is open. In this case, we consider a bridge in the open subpocket but not a bridge in the closed one. In this way, we have the following observation.
Observation 10.
Each open subpocket of has exactly two bridges, which are the first and last edges of its base (see Figure 7).
Proof.
To see this, since the base of is a geodesic path (because it is a subpath of ) and is a simple polygon, the base of must be a concave chain, meaning that if we traverse on it, either we always make right turns or we always make left turns. Hence, the two end vertices of the base of must be in while all other vertices are in because is -bounded (see Figure 7). This implies that among all edges on the base of , only the first and last edges are bridges. For other edges of not on its base, by definition, each of them connects two vertices of , meaning that it is not a bridge.
We say that two subpockets of are neighboring if they share a common edge of . By definition, for two neighboring subpockets of , one of them is -bounded while the other is -bounded. Also, a closed subpocket has exactly one neighboring subpocket while an open one has multiple. For any open subpocket , since only the first and last edges of its base are bridges, has at most two neighboring open subpockets. The following simple observation implies that to compute for a point , it suffices to consider and its neighboring subpockets.
Observation 11.
For any point , if a point is visible to , then is either in or in a neighboring subpocket of .
Proof.
Assume to the contrary is in other subpockets. Then, must cross two edges of . Since is a geodesic path in , no line segment in can cross two edges of . We thus obtain contradiction.
With the above concepts, we next discuss how to further decompose an open subpocket (again assume that is -bounded).
Let denote the base of . Let be the end vertex of that is closer to along and the other end vertex (see Figure 7). By definition, . Note that if we traverse from to , we always make right turns. For simplicity of discussion, we consider the order of vertices of from to as the left-to-right order so that we can use “left” and “right” to refer to the directions of . Note that could be spiral. Let denote the portion of in . Hence, is the first vertex and is the last vertex of if we order vertices of along clockwise (and we also consider it the left-to-right order of ). Also, the union of and forms the boundary of .
We pick the middle vertex of with , and connect to and by geodesic paths, which yields a geodesic triangle, denoted by . Since the base is a geodesic path and is not on , cannot be empty. One side of is on and we call it the base side; the other two sides are called the non-base sides. Among the two non-base sides, the one that connects the leftmost vertex of the base side is called the left side while the other is called the right side (recall that we have a left-to-right order of ; since the base side is a subpath of , we can talk about the “leftmost” and “rightmost” vertices). We add to the core of the root of .
Consider the left side of , denoted by . Let be the leftmost vertex of the base side of . Depending on whether , there are two cases.
-
If , then no edge of is a bridge and every edge of connects two vertices of ; see Figure 8. In this case, for each diagonal of , all vertices of are in , where is the subpolygon of divided by that does not contain . Hence, has no more than edges other than . We create a child for in with and gate . Since does not contain , all three key properties hold for . In this case, the processing of the left side is done.
-
If , then is in and the edge of incident to must be a bridge (see Figure 9); let denote the other vertex of the edge. Note that none of the other edges of is a bridge. For each diagonal of with , we create a child for in the same way as above. For , the pocket now also contains vertices of (see Figure 9), and thus we cannot create a child for in the same way as above. Instead, we process recursively. The reason we can do this is the following. By definition, the union of , which is the portion of between and , and is a subpath of and thus it is the geodesic path . In fact, is tangent to at . Since is a simple polygon with on its boundary, is also a concave chain and we can consider as the base of (note that also contains exactly two bridges at the two ends). Hence, has the same “structure” as and thus we can apply the above processing recursively. Note that the number of vertices of in is at most .
The right side of can be processed symmetrically.
The above process can be better represented by a tree . Each node of corresponds to a subpolygon of and also a non-empty geodesic triangle , which is added to the core of for . If is the root, then we have and . In the above processing of , if has a bridge , then the root of has a left subtree by processing recursively (if is the left child of the root, then ). The right subtree is defined similarly. The tree height is , or more precisely since every time we pick the middle vertex of the portion of in the current subpolygon to further decompose . Note that as the base case, if contains a single vertex other than and , then the two non-base sides of are line segments and , which are edges of , and therefore the recursive step stops at .
Summary.
The above defines the children of in the decomposition tree . As mentioned before, the entire tree can be obtained by applying the same decomposition recursively on for every child of the root . Since our decomposition does not introduce any new vertices and no two edges of the geodesic paths in the decomposition cross each other, the total size of the decomposition is .
The above discusses the case where the geodesic triangle is not empty. If it is empty, then it becomes a special case and can be handled similarly. Indeed, in this case, either is in or is in . We let be in the first case and in the second case. Hence, holds in either case. We can simply treat the entire as , and then apply the above decomposition. Since is in , according to our decomposition, it must lie on the base side of a geodesic triangle that is added to the core . Hence, can never be in for any child of . This ensures the second key property. The other two key properties follow from the same analysis.
As computing a geodesic path in can be done in linear time [18], a straightforward algorithm can decompose each open subpocket in time since the height of is . As such, decomposing all subpockets of takes time, and thus computing all the children of the root of the decomposition tree can be done in time. As the height of is and the subpolygons of all nodes in the same level of are interior disjoint, the total time for computing can be bounded by .
5 A data structure of optimal query time
In this section, we present our visibility query data structure of complexity, based on the new decomposition introduced in Section 4.
Preprocessing.
We first construct the decomposition tree and build the data structure of Theorem 8. This requires space and preprocessing time.
For each node , recall that all edges of the subpolygon are edges of , except for the gate . For simplicity, let denote the number of edges of that belong to .
Let be a parameter with . A node of is called a border node if and , where denotes the parent of . By definition, each leaf-to-root path in contains at most one border node. This further implies that the subpolygons corresponding to all border nodes are edge-disjoint.
The border nodes, together with all their ancestors in , form a subtree of . Note that includes the root and has all border nodes as its leaves (hence, the border nodes indeed form the “border” of ). We use to denote the set of all border nodes of . We further have the following lemma.
Lemma 12.
The number of internal nodes of is .
Proof.
Let denote the subtree of obtained by removing all its leaves. Our goal is to show that contains nodes.
By definition, holds for every node of . Since the edges of for all leaves are disjoint, has leaves. According to our decomposition, holds for every non-root node .
For any value , let denote the set of nodes satisfying . For any two nodes , it is impossible for one to be an ancestor of the other. Indeed, suppose to the contrary that is an ancestor of . Then we would have , contradicting the condition . Hence, and are interior disjoint, which implies that .
The total number of nodes in is therefore bounded by
The lemma thus follows.
We further perform the following preprocessing. For each internal node , we construct a data structure with respect to the gate such that, for any point , can be computed in time. This corresponds to a diagonal-separated subproblem and requires space and preprocessing time [2], as described in Section 3.1. Since has internal nodes by Lemma 12, constructing the data structures for all these nodes takes space and preprocessing time in total.
For each leaf , we recursively preprocess and the subtree of rooted at . This completes the preprocessing phase.
We now analyze the overall space. Let denote the total space of the preprocessing (excluding the data structure of Theorem 8). We have the following recurrence:
Since for every node , and the subpolygons for all are edge-disjoint (implying that ), by setting for any constant , the recurrence solves to .
Similarly, the preprocessing time is also . Including the data structure of Theorem 8, the total preprocessing requires space and time.
Queries.
Recall that the data structure of Theorem 8 includes a point location structure for the cores of the nodes , which together form a decomposition of .
Given a query point , we first perform a point location query to determine the node of whose core contains . Then, by Theorem 8, we compute in time. Depending on whether is an internal node of , we distinguish two cases.
-
If is an internal node of , then using the data structure , we compute in time. Finally, by Lemma 5, we merge and in time to obtain . Thus, in this case, computing takes time in total.
-
If is not an internal node of , then by following the path from to the root of , we find a border node . Using the recursively constructed data structure for , we compute recursively. Let be the parent of . By definition, is an internal node of . By Theorem 8, we compute in time, and by Lemma 5, we merge and in time to obtain . Finally, using the data structure , we compute in time and merge it with , again in time, to obtain .
Let denote the query time. Since , the recursive computation of takes time. Hence, the recurrence relation is
which solves to for , where is a constant.
The following theorem summarizes our result.
Theorem 13.
Given a simple polygon with vertices, a data structure of size can be constructed in time such that the visibility polygon can be computed in time for any query point .
Remark.
One may wonder whether the balanced decomposition from Section 3.3 could replace our decomposition to achieve the same result. This, however, appears challenging because does not satisfy the gate property. Indeed, each subpolygon in may connect to the “outside world” through up to diagonals. This limitation is precisely why we introduce a new decomposition for .
6 A quadratic-space data structure
In this section, we present our data structure of complexity . We will first give a data structure of using our decomposition . By integrating it with the framework in Section 3.3, we will reduce the space to and reduce the preprocessing time to , while keeping the same query time.
In the preprocessing phrase, we compute the decomposition tree and the data structure of Theorem 8. This takes space and preprocessing time.
Super-levels.
We partition into super-levels. Each super-level consists of a collection of subtrees of , and we refer to each such subtree as a component subtree of the super-level. The -th super-level , with , is defined as follows.
We assume that the set of the roots of all component subtrees of is already known and that the following algorithm invariants hold for : (1) for every node ; (2) the subpolygons for all are edge-disjoint; and (3) for each node with , its parent lies in the -th super-level. Initially, when , the set consists of a single node that is the root of , and thus all invariants hold for .
We now define . Consider a node . Let denote the subtree of rooted at . We borrow several concepts from Section 5. A non-root node of is called a border node of if and , where is the parent of . The border nodes, together with all their ancestors in , form a subtree of . Let denote the subtree of obtained by removing all its leaves, and let denote the set of border nodes of . We then define
We have the following observation.
Observation 14.
All algorithm invariants hold for .
Proof.
Consider a node for some . By definition, . Since , we obtain . This proves the first invariant.
For the second invariant, by definition, of all nodes are edge disjoint (this is because the path from any leaf to the root of has exactly one border node). Since for all nodes are edge disjoint, we obtain that for all nodes are edge disjoint. This proves the second invariant.
By definition, the parent of each node of is in the -th super-level . Therefore, the third invariant also holds.
Finally, note that if for any , we simply set , which marks the last super-level. Since , this occurs for , implying that the total number of super-levels is .
Preprocessing.
With the super-levels defined above, we perform the following preprocessing.
Consider the -th super-level . For each node and each node , note that is an ancestor of in . By the gate property, is separated from by the gate of . We construct a data structure for with respect to in , such that, for any query point , can be computed in time. This is a diagonal-separated subproblem and such a data structure can be constructed in space and preprocessing time [2], as described in Section 3.1.
We now analyze the total space required for the data structures in . By the same argument as in Lemma 12, we have since consists of the internal nodes of . Hence, the total space for all data structures , over all nodes and all , is . Because the subpolygons for all are edge-disjoint, we have . Moreover, since , it follows that . Therefore, the total space of all data structures in the -th super-level is , and the total preprocessing time is .
Hence, building the data structures for all super-levels takes space and preprocessing time. Including the preprocessing for Theorem 8, the total space becomes and the total preprocessing time is .
Queries.
Given a query point , by a point location query, we find the node of whose core contains . We then compute in time using Theorem 8.
Assume that belongs to the -th super-level for some , i.e., . Let be the node in such that . Using the data structure , we compute in time. Since is separated from by the gate , we can obtain by merging and in time using Lemma 5.
If , then , and thus is already computed. Otherwise, let be the parent of . By the algorithm invariants, lies in the -th super-level. By Theorem 8, we can compute in time. Since is separated from by the gate , we can merge and in time to obtain . As lies in the -th super-level, we repeat the same procedure until reaching the -th super-level, after which is obtained.
Since there are super-levels and each super-level requires time, the total query time is . For reference, we summarize the result below.
Lemma 15.
We can construct a data structure of size in time for such that can be computed in time for any query point .
We further reduce the preprocessing complexities in the following theorem.
Theorem 16.
Given a simple polygon with vertices, a data structure of size can be constructed in time such that the visibility polygon can be computed in time for any query point .
Proof.
We follow the framework of Section 3.3 to construct the balanced decomposition and solve the diagonal-separated subproblems using the quadratic-space method of [2], as reviewed in Section 3.1. This requires space and preprocessing time.
Let denote the subtree of consisting of its top levels, where is the smallest integer such that the subpolygon at every node of the -th level has size at most . By the definition of , we have .
For each leaf , we construct a data structure as in Lemma 15 for . Each such data structure requires space and preprocessing time. Hence, the total preprocessing time for all data structures of the leaves is , where denotes the set of leaves of . Since the subpolygons for all leaves form a partition of , we have . Furthermore, because for all , it follows that . Thus, the total preprocessing time of all is , and the total space is also .
This completes the preprocessing, which requires space and time in total.
For a query point , we first locate the leaf node such that contains , which takes time using a point location query. Then, by Lemma 15, we compute in time using . Next, as described in Section 3.3, we use the diagonal-separated data structure to compute in time for the parent of . In general, by following the path from to the root in , can be computed in an additional time since the path has nodes. Therefore, the total query time for computing is .
References
- [1] Pankaj K. Agarwal and Micha Sharir. Ray shooting amidst convex polygons in 2D. Journal of Algorithms, 21(3):508–519, 1996. doi:10.1006/jagm.1996.0056.
- [2] Boris Aronov, Leonidas J. Guibas, Marek Teichmann, and Li Zhang. Visibility queries and maintenance in simple polygons. Discrete and Computational Geometry, 27(4):461–483, 2002. doi:10.1007/s00454-001-0089-9.
- [3] Prosenjit Bose, Anna Lubiw, and J. Ian Munro. Efficient visibility queries in simple polygons. Computational Geometry: Theory and Applications, 23(3):313–335, 2002. doi:10.1016/S0925-7721(01)00070-0.
- [4] Mojtaba Nouri Bygi and Mohammad Ghodsi. Weak visibility queries in simple polygons. In Proceedings of the 23rd Canadian Conference on Computational Geometry (CCCG), 2011. URL: https://www.cccg.ca/proceedings/2011/papers/paper95.pdf.
- [5] Timothy M. Chan and Da Wei Zheng. Simplex range searching revisited: How to shave logs in multi-level data structures. In Proceedings of the 34th Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1493–1511, 2023. doi:10.1137/1.9781611977554.ch54.
- [6] Bernard Chazelle. A theorem on polygon cutting with applications. In Proceedings of the 23rd Annual Symposium on Foundations of Computer Science (FOCS), pages 339–349, 1982. doi:10.1109/SFCS.1982.58.
- [7] Bernard Chazelle. Triangulating a simple polygon in linear time. Discrete and Computational Geometry, 6:485–524, 1991. doi:10.1007/BF02574703.
- [8] Bernard Chazelle. Cutting hyperplanes for divide-and-conquer. Discrete and Computational Geometry, 9:145–158, 1993. doi:10.1007/BF02189314.
- [9] Bernard Chazelle, Herbert Edelsbrunner, Michelangelo Grigni, Leonidas J. Guibas, John Hershberger, Micha Sharir, and Jack Snoeyink. Ray shooting in polygons using geodesic triangulations. Algorithmica, 12:54–68, 1994. doi:10.1007/BF01377183.
- [10] Bernard Chazelle and Leonidas J. Guibas. Visibility and intersection problems in plane geometry. Discrete and Computational Geometry, 4:551–589, 1989. doi:10.1007/BF02187747.
- [11] Danny Z. Chen and Ovidiu Daescu. Maintaining visibility of a polygon with a moving point of view. Information Processing Letters, 65:269–275, 1996. doi:10.1016/S0020-0190(97)00211-1.
- [12] Danny Z. Chen and Haitao Wang. Visibility and ray shooting queries in polygonal domains. Computational Geometry: Theory and Applications, 48:31–41, 2015. doi:10.1016/j.comgeo.2014.08.003.
- [13] Danny Z. Chen and Haitao Wang. Weak visibility queries of line segments in simple polygons. Computational Geometry: Theory and Applications, 48:443–452, 2015. doi:10.1016/j.comgeo.2015.02.001.
- [14] James R. Driscoll, Neil Sarnak, Daniel D. Sleator, and Robert E. Tarjan. Making data structures persistent. Journal of Computer and System Sciences, 38(1):86–124, 1989. doi:10.1016/0022-0000(89)90034-2.
- [15] Herbert Edelsbrunner, Leonidas J. Guibas, and Jorge Stolfi. Optimal point location in a monotone subdivision. SIAM Journal on Computing, 15(2):317–340, 1986. doi:10.1137/0215023.
- [16] Hossam A. ElGindy and David Avis. A linear algorithm for computing the visibility polygon from a point. Journal of Algorithms, 2(2):186–197, 1981. doi:10.1016/0196-6774(81)90019-5.
- [17] Leonidas J. Guibas and John Hershberger. Optimal shortest path queries in a simple polygon. Journal of Computer and System Sciences, 39(2):126–152, 1989. doi:10.1016/0022-0000(89)90041-X.
- [18] Leonidas J. Guibas, John Hershberger, Daniel Leven, Micha Sharir, and Robert E. Tarjan. Linear-time algorithms for visibility and shortest path problems inside triangulated simple polygons. Algorithmica, 2(1-4):209–233, 1987. doi:10.1007/BF01840360.
- [19] Leonidas J. Guibas, Rajeev Motwani, and Prabhakar Raghavan. The robot localization problem in two dimensions. In Proceedings of the 3rd Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 259–268, 1992. doi:10.5555/139404.139460.
- [20] John Hershberger and Subhash Suri. A pedestrian approach to ray shooting: Shoot a ray, take a walk. Journal of Algorithms, 18:403–431, 1995. doi:10.1006/jagm.1995.1017.
- [21] Rajasekhar Inkulu and Sanjiv Kapoor. Visibility queries in a polygonal region. Computational Geometry: Theory and Applications, 42(9):852–864, 2009. doi:10.1016/j.comgeo.2009.02.004.
- [22] David G. Kirkpatrick. Optimal search in planar subdivisions. SIAM Journal on Computing, 12(1):28–35, 1983. doi:10.1137/0212002.
- [23] Lin Lu, Chenglei Yang, and Jiaye Wang. Point visibility computing in polygons with holes. Journal of Information and Computational Science, 8(16):4165–4173, 2011. URL: https://www.researchgate.net/publication/282763094_Point_visibility_computing_in_polygons_with_holes.
- [24] Jir̆í Matoušek. Efficient partition trees. Discrete and Computational Geometry, 8(3):315–334, 1992. doi:10.1007/BF02293051.
- [25] Michel Pocchiola. Graphics in flatland revisited. In Proceedings of the 2nd Scandinavian Workshop on Algorithm Theory (SWAT), pages 85–96, 1990. doi:10.1007/3-540-52846-6_80.
- [26] Neil Snarnak and Robert E. Tarjan. Planar point location using persistent search trees. Communications of the ACM, 29:669–679, 1986. doi:10.1145/6138.6151.
- [27] Alireza Zarei and Mohammad Ghodsi. Query point visibility computation in polygons with holes. Computational Geometry: Theory and Applications, 39(2):78–90, 2008. doi:10.1016/j.comgeo.2007.02.005.
