Abstract 1 Introduction 2 Preliminaries 3 A near-linear space data structure 4 A new polygon decomposition 5 A data structure of optimal query time 6 A quadratic-space data structure References

Visibility Queries in Simple Polygons

Sujoy Bhore ORCID Department of Computer Science and Engineering, Indian Institute of Technology Bombay, Mumbai, India    Chih-Hung Liu ORCID Department of Electrical Engineering, National Taiwan University, Taipei, Taiwan    Anurag Murty Naredla ORCID Department of Computer Science, University of Manitoba, Winnipeg, Canada    Yakov Nekrich ORCID Michigan Technological University, Houghton, MI, USA    Eunjin Oh ORCID POSTECH, Pohang, Republic of Korea    André van Renssen ORCID The University of Sydney, Australia    Frank Staals ORCID Department of Information and Computing Sciences, Utrecht University, The Netherlands    Haitao Wang ORCID Kahlert School of Computing, University of Utah, Salt Lake City, UT, USA    Jie Xue ORCID New York University Shanghai, China
Abstract

Given a simple polygon P with n vertices, we consider the problem of constructing a data structure for visibility queries: for any query point qP, compute the visibility polygon of q in P. To obtain O(logn+k) query time, where k is the size of the visibility polygon of q, the previous best result requires O(n3) space. In this paper, we propose a new data structure that uses O(n2+ϵ) space, for any ϵ>0, while achieving the same query time. If only O(n2) space is available, the best known result provides O(log2n+k) query time. We improve this to O(lognloglogn+k) time. When restricted to o(n2) space, the only previously known approach, aside from the O(n)-time algorithm that computes the visibility polygon without preprocessing, is an O(n)-space data structure that supports O(klogn)-time queries. We construct a data structure using O(nlogn) space that answers visibility queries in O(n1/2+ϵ+k) time. In addition, for the special case in which q lies on the boundary of P, we build a data structure of O(nlogn) space supporting O(log2n+k) query time; alternatively, we achieve O(logn+k) query time using O(n1+ϵ) 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 decompositions
Category:
Track A: Algorithms, Complexity and Games
Funding:
Sujoy Bhore: Work supported in part by ANRF ARG-MATRICS, Grant 002465.
Chih-Hung Liu: Supported by Ministry of Education, Taiwan under Yushan Fellow Program with the grant number MOE-111-YSFEE-0003-006-P1.
Yakov Nekrich: Supported by the National Science Foundation under NSF grant 2203278.
Eunjin Oh: Supported by Institute of Information & Communications Technology Planning & Evaluation (IITP) grant funded by the Korea government (MSIT) (No.RS-2024-00440239, Sublinear Scalable Algorithms for Large-Scale Data Analysis) and the National Research Foundation of Korea (NRF) grant funded by the Korea government (MSIT) (No.RS-2024-00358505).
André van Renssen: This research was partially funded by the Australian Government through the Australian Research Council (project number DP240101353).
Copyright and License:
[Uncaptioned image] © Sujoy Bhore, Chih-Hung Liu, Anurag Murty Naredla, Yakov Nekrich, Eunjin Oh,
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 algorithms
Related Version:
Full Version: https://arxiv.org/abs/2605.03334
Acknowledgements:
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 Puppis

1 Introduction

Let P be a simple polygon with n vertices. A point pP is said to be visible to a point qP if the line segment pq¯ lies entirely inside P. The visibility polygon Vis(q) of q is the set of all points in P that are visible to q; see Figure 1. It is well known that Vis(q) is a star-shaped polygon whose vertices are either: (i) vertices of P, or (ii) intersection points between edges of P and rays from q passing through reflex vertices of P.

In this paper, we study data structures for visibility queries: given a query point qP, compute the visibility polygon Vis(q) efficiently.

Previous work.

Vis(q) can be computed in O(n) time without any preprocessing [10, 18, 16]. If O(logn)-time ray-shooting queries are available, then Vis(q) can be computed in O(klogn) time [2], where k is the size of Vis(q). Such ray-shooting data structures can be constructed in O(n) time [10, 9, 20]. Ideally, one would like a query algorithm whose running time is linear in the output size, i.e., O(k). 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 O(logn+k) query time using O(n3) space and O(n3logn) preprocessing time. Aronov, Guibas, Teichmann, and Zhang [2] constructed a data structure of O(n2) space in O(n2logn) time that supports O(log2n+k)-time visibility queries. Note that O(logn+k) is the optimal query time [3, 19].

Figure 1: The grey region is Vis(q). Each edge of it is either a portion of an edge of P or a dotted segment (which is called a window in the literature [3]).

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 O(nlogn) space, O(nlog2n) preprocessing time, and O(n1/2+ϵ+k) 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 r satisfying 1rn1ϵ, we can build a data structure of space O(nr+nlog(n/r)), O((nr+nlog(n/r))logn) preprocessing time, and O((n/r)1/2+ϵ+k) query time. Note that this result implies that for a large k (e.g., k=Ω(nϵ)), we can achieve O(k) query time with sub-quadratic preprocessing.

  • Second, to achieve the optimal O(logn+k) query time, we construct a data structure of O(n2+ϵ) space and preprocessing time, for any ϵ>0. This improves the space bound of the previous O(n3)-space structures [3, 19] by nearly a linear factor.

  • Third, under an O(n2) space budget, we improve the O(log2n+k) query time in [2] to O(lognloglogn+k), with a preprocessing time of O(n2logn).

    We remark that even a near-logarithmic improvement in query time is often considered significant. Indeed, for the closely related ray-shooting problem, reducing the query time from O(log2n) to O(logn) required substantial technical effort [10, 9, 20].

Table 1 summarizes these bounds alongside prior work.

Table 1: Summary of the results for visibility queries (k is the output size).
Results Query time Space Preprocessing time
[9, 20] O(klogn) O(n) O(n)
[3, 19] O(logn+k) O(n3) O(n3logn)
[2] O(log2n+k) O(n2) O(n2logn)
Ours (near-linear space) O(n1/2+ϵ+k) O(nlogn) O(nlog2n)
Ours (optimal query time) O(logn+k) O(n2+ϵ) O(n2+ϵ)
Ours (quadratic space) O(lognloglogn+k) O(n2) O(n2logn)

In addition, we study a natural special case in which the query point q lies on the boundary of P. To the best of our knowledge, this boundary case has not been treated separately in the literature. We obtain a data structure of O(nlogn) space and O(nlog2n) preprocessing time that answers queries in O(log2n+k) time. Alternatively, we can achieve O(logn+k) query time using O(n1+ϵ) 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 q lies on a given segment in P. Their data structure uses O(n) space and supports queries in O(logn+k) time. However, their approach does not appear to extend to arbitrary query points.

Given a segment sP, a point is weakly visible to s if it is visible to at least one point of s. The weak visibility polygon of s consists of all points of P visible to s, and can be computed in O(n) 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 O(n) space and preprocessing time, one can support queries in O(klogn) time; alternatively, using O(n3) space and preprocessing time, queries can be answered in O(logn+k) time [13].

As a special visibility problem, the ray-shooting problem asks for the first point on P hit by a ray originating inside P. As mentioned earlier, ray-shooting queries can be answered in O(logn) time after O(n)-time preprocessing [9, 20].

Visibility and ray-shooting in polygons with holes have also been studied [1, 12, 21, 23, 25, 27], but the presence of holes makes the problems substantially more difficult. We refer the reader to [12] for an overview of results in that setting.

1.1 An overview of our approach

The methods of [3, 19] decompose P into O(n3) cells such that the combinatorial structure of Vis(q) is the same for every point q 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 P [18, 17, 10] (see Section 2 for more details). Their method achieves O(log2n+k) query time using O(n2) space. The O(log2n) factor in query time appears inherent to the balanced decomposition: each subpolygon may be connected to the “outside world”, i.e., the rest of P, by O(logn) diagonals and the decomposition has O(logn) recursive levels.

To obtain O(logn+k) 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 P into subpolygons whose sizes shrink geometrically; however, the gate property fundamentally changes how visibility information propagates across subregions.

Intuitively, suppose a query point q lies in a subpolygon Pd with gate d. If we have already computed the portion of Pd visible to q, denoted by Vis(Pd,q), then the remaining part of the visibility region, Vis(PPd,q), is exactly the portion of PPd visible through the diagonal d. We refer to computing this region as the diagonal-separated subproblem. The entire query algorithm reduces to solving this subproblem and recursing inside Pd (i.e., to compute Vis(Pd,q), we can apply the algorithm recursively).

Our optimal-query-time data structure is built on this decomposition and uses O(1) recursive steps by choosing a parameter r=nϵ. This yields O(n2+ϵ) space and O(logn+k) query time. Our quadratic-space data structure also relies on our new decomposition but groups its levels into O(loglogn) super-levels. This reduces the space to O(n2) at the cost of increasing the query time to O(lognloglogn+k). In contrast, the balanced decomposition of [2] has Θ(logn) levels, resulting in an unavoidable O(log2n) 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 O(n2)-space data structure supporting O(logn+k) 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 O(n)-space structure supporting queries in O(n1/2+ϵ+k) time, yielding our result.

For the boundary case, the diagonal-separated subproblem simplifies substantially: with q constrained to lie on the boundary of P, the remaining computation becomes essentially one-dimensional. We obtain a solution of O(n) space and O(logn+k) 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., P, n, and Vis(q). For any subpolygon PP, we define Vis(P,q)=Vis(q)P, i.e., the portion of Vis(q) contained in P.

For convenience, we assume that each edge of P is an open segment that does not include its endpoints; thus, the vertices of P are disjoint from its edges. We refer to either a vertex or an edge of P as an element of P. For any geometric object R, let R denote its boundary. For two points p and q, pq¯ denotes the line segment connecting them.

It is well known that Vis(q) 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 P that appear on the boundary Vis(q), one can reconstruct Vis(q) in O(|Vis(q)|) time [2, 3]. Hence, to compute Vis(q), it suffices to determine this cyclic list, called the combinatorial representation of Vis(q) [2]. It is also known that this cyclic order of vertices and edges of P on Vis(q) is consistent with their order along P. In the following, depending on the context, we may use Vis(q) to refer to its combinatorial representation.

Balanced decomposition.

We will use the balanced decomposition of P, which has been applied to various problems in simple polygons [2, 18, 17, 10]. A diagonal is a line segment connecting two vertices of P that is fully contained in P but not an edge of P. Chazelle [6] proved that P always admits a diagonal that splits it into two subpolygons, each having between n/3 and 2n/3 vertices. The balanced decomposition of P is obtained by recursively partitioning each subpolygon using such diagonals until all subpolygons are triangles. This decomposition can be represented by a tree 𝒯(P), called the BD-tree. Each node v of 𝒯(P) corresponds to a subpolygon Pv of P: the root corresponds to P itself, and each leaf corresponds to a triangle. The diagonal used to partition Pv into its two child subpolygons is stored at v and denoted by dv. The triangles at all leaves of 𝒯(P) form a triangulation of P. The entire decomposition and BD-tree 𝒯(P) can be computed in O(n) time [17, 7].

Convention on stating query time.

For simplicity, when we state that a data structure supports queries in O(Q(n)) time for computing Vis(q) (or a portion thereof, e.g., Vis(P,q) for a subpolygon PP), we mean that a (balanced) binary search tree storing the combinatorial representation of Vis(q) can be computed in O(Q(n)) time, and the full visibility polygon Vis(q) can then be output in an additional O(|Vis(q)|) time.

For conciseness, we say that a data structure has complexity O(T(n),S(n),Q(n)) if its preprocessing time, space, and query time are O(T(n)), O(S(n)), and O(Q(n)), 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 d be a diagonal that divides P into two subpolygons P and Pr. Without loss of generality, assume that d is vertical and P lies locally to the left of d. The diagonal-separated subproblem is to compute Vis(P,q) for any query point qPr. We describe our solution below.

Since qPr, for any point pVis(P,q), pq¯ must cross d. In other words, the visibility of q within P occurs “through” d. Because P is a simple polygon, Vis(d,q) is a contiguous segment of d [2]. Let s=Vis(d,q). If s=, then Vis(P,q)=. Otherwise, let Cq(s) denote the cone formed by the rays from q through all points ps; we say that Cq(s) is defined by q and s, and refer to q 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 Cq(s) can be computed in O(logn) time via shortest-path queries. To compute Vis(P,q), it thus suffices to determine the portion of P visible to q through the cone Cq(s).

Figure 2: The gray region is Vis(P,q). Cs(q) is bounded by the two blue dotted segments.

We use Viss(q) to denote Vis(P,q). We also define an analogous notion Visd(q), which consists of all points pP such that pq¯ crosses d and pp¯P, where p=dpq¯. Note that whether the segment qp¯ lies inside P is irrelevant. See Figure 3.

Figure 3: The gray region is Visd(q).

Following [2], we first compute a binary search tree that stores the combinatorial representation of Visd(q), i.e., the cyclic order of the elements of P (recall that an element refers to either a vertex or an edge of P) appearing on Visd(q). We then perform a clipping operation on this tree using Cq(s); the resulting tree represents Viss(q).

Observation 1.

[2, 3] The order of the vertices and edges of P along Viss(q) (resp., Visd(q)) is consistent with their order along P.

We sort all elements of P along its boundary and assign each of them an index in this order. Let Ad(q) denote the set of elements of P that appear on Visd(q). By Observation 1, the elements of Ad(q) are sorted in index order in the combinatorial representation of Visd(q).

Figure 4: The gray region is Ce. The two dashed red paths are shortest paths from the two endpoints of e to the two vertices of d. The two bounding lines of Ce are tangent to these two paths.

For each vertex vP, as discussed above, all points of d visible to v within P form a segment sv of d. Let Cv denote the cone defined by sv and v. Observe that v belongs to Ad(q) if and only if qCv. For each edge e of P, as discussed in [18], the points of d weakly visible to e also form a segment se of d, such that e belongs to Ad(q) if and only if q lies in the cone Ce defined by se and a point to the left of d (see Figure 4).

For reference, we summarize the above discussion in the following observation.

Observation 2.

For each vertex v (resp., edge e) of P, v (resp., e) appears in the combinatorial representation of Visd(q) if and only if q lies in the cone Cv (resp., Ce).

All cones Cv and Ce for the vertices and edges of P can be computed in O(n) time using the shortest path trees of the two endpoints of d [18]. Let 𝒞 denote the set of all these cones. We refer to v (resp., e) as the generator of Cv (resp., Ce). To compute Ad(q), by Observation 2, the problem reduces to the following cone stabbing query: given q, compute all cones of 𝒞 that are stabbed by q (we say that a cone is stabbed by q if the cone contains q). To accommodate the clipping operation with Cq(s), 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 Rd denote the halfplane to the right of the supporting line of d. If qRd, then Visd(q)=, so we assume qRd. Let 𝒜d be the arrangement in Rd formed by the supporting lines of the bounding rays of all cones in 𝒞. By Observation 2, points q in the same cell of 𝒜d share the same (combinatorial representation of) Visd(q), and Visd(q) of q in adjacent cells differ by at most one element of P. Since there are O(n) cones, 𝒜d has O(n2) cells.

We use persistent binary search trees [26, 14] to store the combinatorial representations of Visd(q) for all cells of 𝒜d in a total of O(n2) space and O(n2logn) preprocessing time. Additionally, we construct a point location data structure on 𝒜d in O(n2) time and space [26, 22, 15]. Given a query point q, we can locate the cell of 𝒜d containing q in O(logn) time and thereby obtain access to the corresponding binary search tree that stores Visd(q). This yields a data structure of complexity O(n2logn,n2,logn), i.e., O(n2logn) preprocessing time, O(n2) space, and O(logn) query time for computing Vis(P,q) for any qPr.

The boundary case.

In the boundary case, each query point q is on PPr. In this case the cone stabbing queries become 1D interval stabbing queries on PPr. Using persistent trees [26, 14], we obtain a data structure of complexity O(nlogn,n,logn). This result combining with the algorithmic framework given in Section 3.3 yields a data structure of complexity O(nlog2n,nlogn,log2n) for computing Vis(q). 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 Cs(q). The elements remaining in the clipped trees of all canonical subsets collectively form the set As(q), which consists of the elements of P lying on Viss(q). We then sort the elements of As(q) by their index order to obtain Viss(q). 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 q, compute all simplices stabbed by q 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 j=2 levels. We briefly discuss this and the reader is referred to [5, Section 3.1] for details.

Determining whether q is in a cone is equivalent to testing whether q 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 q of q 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 j-th halfplanes of the cones of 𝒞, with j=2. For each cell Δ of the partition that intersects q, we recurse on the canonical subset of the dual points of Δ. For each cell Δ lying entirely below q (or above q, depending on which is the correct side), we recurse on the canonical subset of Δ but as a level-(j1) 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 O(n) space and can be constructed in O(nlogn) time.

Given a query point q, the query algorithm returns O(n1/2+ϵ) canonical subsets whose union corresponds to the set of cones of 𝒞 stabbed by q. For each canonical subset, we perform a clipping operation using the cone Cq(s), taking O(logn) additional time. Hence, we can compute As(q) in O(n1/2+ϵlogn+|As(q)|) time, which simplies to O(n1/2+ϵ+|As(q)|) since the logn factor is absorbed by nϵ.

Once As(q) is obtained, we must sort its elements by their index order. A straightforward comparison sort would require O(|As(q)|log|As(q)|) time, introducing an undesired logarithmic factor in the overall query time. However, since the index of each element of As(q) is an integer in [1,2n], we can perform the sorting in O(nϵ+|As(q)|) time using radix sort in the following lemma.

Lemma 3.

For any ϵ>0, the elements of As(q) can be sorted by their indices in O(nϵ+|As(q)|) time.

Proof.

Let I denote the set of indices of the elements in As(q), and our goal is to sort the integers in I. Since each index in I is an integer in [1,2n], it can be represented using at most logn+1 bits. We partition these logn+1 bits into O(1) groups, each consisting of ϵlogn bits. We refer to each such group as a digit. Hence, each integer in I has O(1) digits. We apply radix sort on the integers of I using these digits. Sorting I by a single digit requires O(2ϵlogn+|I|)=O(nϵ+|I|) time. Since there are only O(1) digits, the entire sorting process takes O(1) passes, resulting in a total running time of O(nϵ+|I|).

After As(q) is sorted, we obtain the combinatorial representation of Viss(q). We then construct a binary search tree to store this representation in an additional O(|Viss(q)|) time. Combining all the above results yields the following lemma.

Lemma 4.

Given a simple polygon P of n vertices and a diagonal d dividing P into two subpolygons P and Pr, a data structure of O(n) space can be constructed in O(nlogn) time such that Vis(P,q) can be computed in O(n1/2+ϵ+|Vis(P,q)|) time for any point qPr.

3.3 A general algorithmic framework

We now describe the algorithmic framework. In the preprocessing, we compute a balanced decomposition of P together with the BD-tree 𝒯(P) as defined in Section 2.

Given a query point qP, let vq be the leaf of 𝒯(P) whose triangle Pvq contains q. The query algorithm proceeds in a bottom-up manner along the path from vq to the root of 𝒯(P). For each node v on this path, let u denote the parent of v and w the sibling of v (i.e., the other child of u). Suppose that Vis(Pv,q) has already been computed (this is true initially when v=vq since Vis(Pv,q)=Pvq). Our goal at node u is to compute Vis(Pu,q), which equals the union of Vis(Pv,q) and Vis(Pw,q).

By definition, Pu is partitioned into Pv and Pw by the diagonal du. Since Vis(Pv,q) is known, we next compute Vis(Pw,q) and then merge Vis(Pv,q) and Vis(Pw,q) along du to obtain Vis(Pu,q). Computing Vis(Pw,q) is precisely an instance of the diagonal-separated subproblem. Therefore, in the preprocessing, for each node u𝒯(P), we construct a diagonal-separated data structure for both Pv and Pw (with respect to du). During a query, these data structures allow us to compute Vis(Pw,q) efficiently.

Once Vis(Pw,q) is computed, we obtain Vis(Pu,q) by merging Vis(Pw,q) and Vis(Pv,q) along s=Vis(du,q). Note that if s=, then Vis(Pw,q)=; otherwise, s must be an edge of Vis(Pv,q). Merging Vis(Pv,q) and Vis(Pw,q) can be done in O(logn) time. For reference purpose, we use Lemma 5 to summarize this merging step (see the full paper for the proof). After computing Vis(Pu,q), the algorithm continues upward until reaching the root of 𝒯(P), at which point Vis(q) is obtained.

Lemma 5.

Suppose a diagonal d divides P into two subpolygons P and Pr. Let q be a point in Pr. Given a binary search tree storing Vis(Pr,q) and a binary search tree storing Vis(P,q), we can obtain a binary search tree storing Vis(q) in O(logn) 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 𝒯(P), we obtain a data structure of complexity O(n2logn,n2,log2n) for computing Vis(q) for any qP. 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 𝒯(P) is O(n) (as they form a partition of P), we obtain a data structure of complexity O(nlog2n,nlogn,n1/2+ϵ). 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 P with n vertices, let r be a parameter satisfying 1rn1ϵ for any constant ϵ>0. A data structure of size O(nr+nlog(n/r)) can be constructed in O((nr+nlog(n/r))logn) time such that Vis(q) can be computed in O((n/r)1/2+ϵ) time for any query point qP. In particular, setting r=1 yields a data structure of O(nlogn) space, O(nlog2n) preprocessing time, and O(n1/2+ϵ) query time.

4 A new polygon decomposition

In this section, we introduce a new decomposition of P together with its associated data structure for answering visibility queries.

Our decomposition decomposes P into geodesic triangles, a concept first introduced in [9], in which a balanced geodesic triangulation of P was proposed and it also decomposes P 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 π(p,q) is a shortest path in P between two points p and q. For three vertices vi, vj, and vk of P ordered clockwise along P, consider the three geodesic paths π(vi,vj), π(vj,vk), and π(vk,vi). 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 vi, vj, or vk lies on the geodesic path connecting the other two.

Figure 5: Illustrating a geodesic triangle (the gray region) formed by three geodesic paths.

4.1 A data structure for geodesic triangles

Consider a geodesic triangle , defined by three vertices pi, pj, and pk as discussed above. Each edge of is either an edge of P or a diagonal. For each diagonal d on , let Pd() denote the subpolygon of P bounded by d that does not contain . We refer to Pd() as the pocket of P separated by d from . For simplicity, if d is an edge of P, we let Pd() denote d itself. When is clear from context, we simply write Pd.

We study two subproblems with respect to . In the first subproblem, the query point q lies in , and the goal is to compute Vis(q). In the second subproblem, the query point q lies in Pd for some diagonal d of , and we wish to compute Vis(PPd,q), i.e., the portion of Vis(q) that lies outside the pocket Pd. 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 O(n2) can be constructed in O(n2logn) time such that, for any query point q, if q, then Vis(q) can be computed in O(logn) time, and if qPd for some diagonal d on the boundary of , then Vis(PPd,q) can be computed in O(logn) time.

Intuitively, the motivation for having a query algorithm that computes Vis(PPd,q) is as follows. If Vis(Pd) is already available, then after obtaining Vis(PPd,q), we can compute Vis(q) by merging the two. To compute Vis(Pd) itself, we would like to apply the same algorithm recursively. For this recursive approach to work, we require an “appropriate” polygon decomposition of P. This motivates the new decomposition introduced in Section 4.2.

4.2 The new decomposition

We now introduce a new decomposition of P, defined with respect to a designated edge of P. Let p1,p2,,pn be the vertices of P ordered clockwise along P. In the following, we describe the decomposition with respect to the edge p1pn¯.

We represent the decomposition by a decomposition tree Ψ. Let v denote the root of Ψ. Each node v of Ψ corresponds to a subpolygon Pv and a gate dv, where dv is a diagonal of P that separates Pv from the “outside world” PPv, and all other edges of Pv are edges of P. Initially, we have Pv=P and dv=p1pn¯ (since v is the root, as a special case we allow dv not to be a diagonal, i.e., we assume dv connects P with the outside).

Each node v also corresponds to a subpolygon Pcore(v)Pv, called the core of Pv, which is the union of a collection of geodesic triangles. The core Pcore(v) and the subpolygons Pu of all children u of v form a partition of Pv (thus PuPv for each child u). Moreover, for every child u of v, we have |Pu||Pv|/2. Hence, the sizes of the subpolygons Pv decrease geometrically along any root-to-leaf path in Ψ, and the height of Ψ is O(logn).

At each node v of Ψ, we explicitly store the edges of Pcore(v). The cores of all nodes are interior-disjoint and together form a partition of P. 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 O(n). Because each core consists of geodesic triangles, our decomposition effectively partitions P into geodesic triangles.

As will be seen later, when our decomposition is used to answer visibility queries, the property that the gate dv separates Pv from PPv plays a crucial role. We refer to this as the gate property. Moreover, for any node v and any ancestor u of v, since PvPuP, the gate property also implies that dv separates Pv from PuPv.

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 O(n2log4n) can be constructed in O(n2log5n) time for the decomposition Ψ such that, for any query point q, if q lies in the core Pcore(u) of a node uΨ, then Vis(Pu,q) can be computed in O(logn) time; and if q lies in Pv for a child v of u, then Vis(PuPv,q) can be computed in O(logn) time.

Proof.

We only sketch the proof here; full details can be found in the full paper.

Consider the root v of Ψ. For each geodesic triangle in the core Pcore(v), we build the data structure of Lemma 7 for in Pv (which equals P). We can show that this construction requires O(n2log4n) space and O(n2log5n) preprocessing time. Afterward, for any query point qP, if qPcore(v), we can compute Vis(Pv,q) in O(logn) time; and if qPv for a child v of v, we can compute Vis(PvPv,q) in O(logn) time.

In general, for each node vΨ, and for each geodesic triangle in Pcore(v), we build the data structure of Lemma 7 for within Pv. This requires O(nv2log4nv) space and O(nv2log5nv) preprocessing time, where nv=|Pv|. Since the sizes of the subpolygons Pv decrease geometrically along every root-to-leaf path, and since the subpolygons Pv of nodes at the same level of Ψ are interior disjoint, the total space over all nodes of Ψ is O(n2log4n), and the total preprocessing time is O(n2log5n). 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 vΨ: (1) dv separates Pv from PuPv, where u is the parent of v; (2) the gate du of u is not in Pv. Then, the gate property holds for v, i.e., dv separates Pv from PPv.

Proof.

We prove the lemma by induction. Initially, if v is a child of the root v, then since dv separates Pv from PuPv, u=v, and Pv=P, it is vacuously true that dv separates Pv from PPv.

We now inductively assume that du separates Pu from PPu. We next argue that dv separates Pv from PPv. Indeed, consider two points p and p with pPv and pPPv. It suffices to show that the geodesic path π(p,p) must intersect dv. If p is in Pu, then since dv separates Pv from PuPv, then π(p,p) must intersect dv. If pPu, then pPPu. In this case, since pPvPu, duPv, and du separates Pu from PPu, if we traverse from p to p along π(p,p), we must first cross du and then dv. The lemma thus follows.

We next describe our decomposition. We will focus on explaining the children v of v. Specifically, we will define the core Pcore(v), the subpolygons Pv, and the gate dv for every child v of v. In particular, we will argue that the following three key properties hold for each v: (1) Pv is separated from PPv by dv; (2) dv is not in Pv; (3) Pv has no more than n/2 edges other than the gate dv. 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 Pv for each child v of v.

Let p=pn/2, the middle point of P (recall that vertices of P are indexed from p1 to pn clockwise around P). We consider the geodesic triangle formed by the three geodesic paths π(p,p1), π(p,pn), and π(p1,pn). Note that π(p1,pn) is the edge dv=p1pn¯. 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 Pcore(v).

Note that dv is one side of and thus p1 and pn are two apexes of . Let b be the third apex (see Figure 6). Note that dv is the union of the other two sides of .

Figure 6: The shaded region bounded by d is a pocket Pd(). ab¯ is the bride d on dv. The bigger shaded region bounded by d is Pd().

Let B1 denote the boundary of P from p1 clockwise to p and B2 the boundary of P from p clockwise to pn. We let both B1 and B2 contain p. Hence, P=B1B2dv. We say that a diagonal is a bridge if one vertex of it is in B1{p} while the other is in B2{p}. By definition, if b=p, then dv has no bridge; otherwise, dv has exactly one bridge, denoted by d, which must have b as a vertex (see Figure 6, where d=ab¯).

For each diagonal d of dv, if d is not a bridge, then it connects two vertices either both on B1 or both on B2. Recall we defined in Section 4.1 that the notation Pd() refer to the pocket of P separated by d from (see Figure 6). Observe that the edges of Pd() other than d are all in B1 or all in B2. Hence, Pd() has no more than n/2 edges other than d. We create a child v for v in Ψ with Pv=Pd() and the gate dv=d. In this way, dv separates Pv from PPv and dv=p1pn¯ is not an edge of Pv. Hence, all three key properties hold for v.

If d is a bridge, i.e., d=d, then bp. In this case, Pd() contains vertices from both B1 and B2 (see Figure 6), and therefore, Pd() may have more than n/2 edges other than d. We therefore cannot simply create a child for v as above and need to resort to other approaches as follows.

Decomposing 𝑷𝒅() into subpockets.

Let a be the vertex of d other than b (see Figure 6). Then, π(p,a) is a subpath of either π(p,p1) or π(p,pn). To simplify the notation, let =Pd() and π=π(a,p).

The geodesic path π decomposes the pocket into subpockets each of which is bounded by a subpath of π and a sequence of edges of B1 or B2. If a subpocket is bounded by a subpath of π and a sequence of edges of B1 (resp., B2), we call it a B1-bounded subpocket (resp., B2-bounded subpocket); see Figure 7. For each subpocket Q, the subpath of π on the boundary of Q is called the base of Q. We say that Q is closed if its base is a single edge; otherwise, it is open (see Figure 7).

For a closed subpocket Q, since its edges other than its base edge are either all from B1 or all from B2, the number of its edges other than its base is at most n/2, and Q is separated from PQ by its base edge. Hence, we create a child v for v in Ψ with Pv=Q and dv as the base edge of Q. Clearly, dv is not in Pv. Hence, all three key properties hold for v.

Figure 7: The gray region Q is an open B1-bounded subpocket while the green region Q is a closed B2-bounded subpocket.

If Q 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 Q is B1-bounded.

Decomposing an open subpocket 𝑸.

Define Q=P. We consider Q a special subpocket. Following our above definition, Q is a closed subpocket since it has only one edge of π. To differentiate, when we say “subpockets of P”, we refer to all subpockets of and also Q; when we say “subpockets of ”, we only refer to the subpockets inside . Unless otherwise stated, a subpocket of P refers to any subpocket of {Q}.

To simplify the discussion, we assume that each edge e of π is a diagonal. Indeed, this is the most general case because if e is an edge of P then we can assume there is an infinitely small subpocket separated by e. With this assumption, e is on the boundaries of two subpockets of P. In particular, if p is a vertex of e, then one subpocket bounded by e is closed while the other is open. In this case, we consider e 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 Q 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 Q is a geodesic path (because it is a subpath of π) and Q is a simple polygon, the base of Q 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 Q must be in B1 while all other vertices are in B2 because Q is B1-bounded (see Figure 7). This implies that among all edges on the base of Q, only the first and last edges are bridges. For other edges of Q not on its base, by definition, each of them connects two vertices of B1, meaning that it is not a bridge.

We say that two subpockets of P are neighboring if they share a common edge of π. By definition, for two neighboring subpockets of , one of them is B1-bounded while the other is B2-bounded. Also, a closed subpocket has exactly one neighboring subpocket while an open one has multiple. For any open subpocket Q, since only the first and last edges of its base are bridges, Q has at most two neighboring open subpockets. The following simple observation implies that to compute Vis(q) for a point qQ, it suffices to consider Q and its neighboring subpockets.

Observation 11.

For any point qQ, if a point pP is visible to q, then p is either in Q or in a neighboring subpocket of Q.

Proof.

Assume to the contrary p is in other subpockets. Then, pq¯ must cross two edges of π. Since π is a geodesic path in P, no line segment in P can cross two edges of π. We thus obtain contradiction.

With the above concepts, we next discuss how to further decompose an open subpocket Q (again assume that Q is B1-bounded).

Let π(Q) denote the base of Q. Let pi be the end vertex of π(Q) that is closer to a along π=π(a,p) and pj the other end vertex (see Figure 7). By definition, i<j. Note that if we traverse π(Q) from pi to pj, we always make right turns. For simplicity of discussion, we consider the order of vertices of π(Q) from pi to pj as the left-to-right order so that we can use “left” and “right” to refer to the directions of π(Q). Note that π(Q) could be spiral. Let B1(Q) denote the portion of B1 in Q. Hence, pi is the first vertex and pj is the last vertex of B1(Q) if we order vertices of B1(Q) along B1 clockwise (and we also consider it the left-to-right order of B1(Q)). Also, the union of B1(Q) and π(Q) forms the boundary Q of Q.

We pick the middle vertex pk of B1(Q) with k=(i+j)/2, and connect pk to pi and pj by geodesic paths, which yields a geodesic triangle, denoted by k. Since the base π(Q) is a geodesic path and pk is not on π, k cannot be empty. One side of k is on π(Q) 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 π(Q); since the base side is a subpath of π(Q), we can talk about the “leftmost” and “rightmost” vertices). We add k to the core Pcore(v) of the root v of Ψ.

Figure 8: Illustrating the case a=pj. The gray region is Q. The left dotted polygonal chain is πkl. The red solid polygonal chain is in B1 and the blue solid polygonal chain is in B2.
Figure 9: Illustrating the case apj. The green region is Qab¯(k). The union of the green region and the gray region is Q. The red solid polygonal chain is in B1 and the blue solid polygonal chain is in B2.

Consider the left side of k, denoted by πkl. Let a be the leftmost vertex of the base side of k. Depending on whether a=pi, there are two cases.

  • If a=pi, then no edge of πkl is a bridge and every edge of πkl connects two vertices of B1; see Figure 8. In this case, for each diagonal d of πkl, all vertices of Qd(k) are in B1(Q), where Qd(k) is the subpolygon of Q divided by d that does not contain k. Hence, Qd(k) has no more than n/2 edges other than d. We create a child v for v in Ψ with Pv=Qd(k) and gate dv=d. Since Pv does not contain dv, all three key properties hold for v. In this case, the processing of the left side πkl is done.

  • If api, then a is in B2 and the edge of πkl incident to a must be a bridge (see Figure 9); let b denote the other vertex of the edge. Note that none of the other edges of πkl is a bridge. For each diagonal d of πkl with dab¯, we create a child v for v in the same way as above. For ab¯, the pocket Qab¯(k) now also contains vertices of B2 (see Figure 9), and thus we cannot create a child for v in the same way as above. Instead, we process Qab¯(k) recursively. The reason we can do this is the following. By definition, the union of π(pi,a), which is the portion of π(Q) between pi and a, and ab¯ is a subpath of π(pi,pk) and thus it is the geodesic path π(pi,b). In fact, ab¯ is tangent to π(Q) at a. Since Qab¯(k) is a simple polygon with π(pi,b) on its boundary, π(pi,b) is also a concave chain and we can consider π(pi,b) as the base of Qab¯(k) (note that π(pi,b) also contains exactly two bridges at the two ends). Hence, Qab¯(k) has the same “structure” as Q and thus we can apply the above processing recursively. Note that the number of vertices of B1 in Qab¯(k) is at most |B1(Q)|/2.

The right side of k can be processed symmetrically.

The above process can be better represented by a tree TQ. Each node ν of TQ corresponds to a subpolygon Q(ν) of Q and also a non-empty geodesic triangle ν, which is added to the core Pcore(v) of v for Ψ. If ν is the root, then we have Q(ν)=Q and ν=k. In the above processing of πkl, if πkl has a bridge ab¯, then the root of TQ has a left subtree by processing Qab¯(k) recursively (if ν is the left child of the root, then Q(ν)=Qab¯(k)). The right subtree is defined similarly. The tree height is O(logn), or more precisely O(log|B1(Q)|) since every time we pick the middle vertex of the portion of B1 in the current subpolygon Q(ν) to further decompose Q(ν). Note that as the base case, if B1(Q) contains a single vertex pk other than pi and pj, then the two non-base sides of k are line segments pkpi¯ and pkpj¯, which are edges of P, and therefore the recursive step stops at Q.

Summary.

The above defines the children v of v in the decomposition tree Ψ. As mentioned before, the entire tree Ψ can be obtained by applying the same decomposition recursively on Pv for every child v of the root v. 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 O(n).

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 pn is in π(p,p1) or p1 is in π(p,pn). We let π be π(p,p1) in the first case and π(p,pn) in the second case. Hence, dv=p1pn¯π holds in either case. We can simply treat the entire P as , and then apply the above decomposition. Since dv is in π, according to our decomposition, it must lie on the base side of a geodesic triangle that is added to the core Pcore(v). Hence, dv can never be in Pv for any child v of v. This ensures the second key property. The other two key properties follow from the same analysis.

As computing a geodesic path in P can be done in linear time [18], a straightforward algorithm can decompose each open subpocket Q in O(|Q|logn) time since the height of TQ is O(logn). As such, decomposing all subpockets of takes O(||logn) time, and thus computing all the children of the root v of the decomposition tree Ψ can be done in O(nlogn) time. As the height of Ψ is O(logn) and the subpolygons Pv of all nodes v in the same level of Ψ are interior disjoint, the total time for computing Ψ can be bounded by O(nlog2n).

5 A data structure of optimal query time

In this section, we present our visibility query data structure of O(n2+ϵ,n2+ϵ,logn) 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 O(n2log4n) space and O(n2log5n) preprocessing time.

For each node vΨ, recall that all edges of the subpolygon Pv are edges of P, except for the gate dv. For simplicity, let |Pv| denote the number of edges of P that belong to Pv.

Let r be a parameter with 1rn. A node v of Ψ is called a border node if |Pvp|n/r and |Pv|<n/r, where vp denotes the parent of v. By definition, each leaf-to-root path in Ψ contains at most one border node. This further implies that the subpolygons Pv corresponding to all border nodes v are edge-disjoint.

The border nodes, together with all their ancestors in Ψ, form a subtree Ψb of Ψ. Note that Ψb includes the root and has all border nodes as its leaves (hence, the border nodes indeed form the “border” of Ψb). We use B(Ψ) to denote the set of all border nodes of Ψ. We further have the following lemma.

Lemma 12.

The number of internal nodes of Ψb is O(r).

Proof.

Let Ψb denote the subtree of Ψb obtained by removing all its leaves. Our goal is to show that Ψb contains O(r) nodes.

By definition, |Pv|n/r holds for every node v of Ψb. Since the edges of Pv for all leaves vΨb are disjoint, Ψb has O(r) leaves. According to our decomposition, |Pv||Pvp|/2 holds for every non-root node vΨ.

For any value m, let Vm denote the set of nodes vΨb satisfying m/2<|Pv|m. For any two nodes u,vVm, it is impossible for one to be an ancestor of the other. Indeed, suppose to the contrary that u is an ancestor of v. Then we would have |Pu||Pv|/2m/2, contradicting the condition m/2<|Pu|. Hence, Pu and Pv are interior disjoint, which implies that |Vm|2n/m.

The total number of nodes in Ψb is therefore bounded by

|Vn|+|Vn/2|+|Vn/4|++|Vn/r|2+4+8++2r=O(r).

The lemma thus follows.

We further perform the following preprocessing. For each internal node vΨb, we construct a data structure 𝒟v with respect to the gate dv such that, for any point qPv, Vis(PPv,q) can be computed in O(logn) time. This corresponds to a diagonal-separated subproblem and requires O(n2) space and O(n2logn) preprocessing time [2], as described in Section 3.1. Since Ψb has O(r) internal nodes by Lemma 12, constructing the data structures for all these nodes takes O(n2r) space and O(n2rlogn) preprocessing time in total.

For each leaf vΨb, we recursively preprocess Pv and the subtree of Ψ rooted at v. This completes the preprocessing phase.

We now analyze the overall space. Let S(n) denote the total space of the preprocessing (excluding the data structure of Theorem 8). We have the following recurrence:

S(n)=vB(Ψ)S(|Pv|)+O(n2r).

Since |Pv|<n/r for every node vB(Ψ), and the subpolygons Pv for all vB(Ψ) are edge-disjoint (implying that vB(Ψ)|Pv|n), by setting r=O(nϵ) for any constant ϵ>0, the recurrence solves to S(n)=O(n2+ϵ).

Similarly, the preprocessing time is also O(n2+ϵ). Including the data structure of Theorem 8, the total preprocessing requires O(n2+ϵ) space and time.

Queries.

Recall that the data structure of Theorem 8 includes a point location structure for the cores Pcore(v) of the nodes vΨ, which together form a decomposition of P.

Given a query point q, we first perform a point location query to determine the node v of Ψ whose core Pcore(v) contains q. Then, by Theorem 8, we compute Vis(Pv,q) in O(logn) time. Depending on whether v is an internal node of Ψb, we distinguish two cases.

  • If v is an internal node of Ψb, then using the data structure 𝒟v, we compute Vis(PPv,q) in O(logn) time. Finally, by Lemma 5, we merge Vis(Pv,q) and Vis(PPv,q) in O(logn) time to obtain Vis(q). Thus, in this case, computing Vis(q) takes O(logn) time in total.

  • If v is not an internal node of Ψb, then by following the path from v to the root of Ψ, we find a border node v. Using the recursively constructed data structure for Pv, we compute Vis(Pv,q) recursively. Let u be the parent of v. By definition, u is an internal node of Ψb. By Theorem 8, we compute Vis(PuPv,q) in O(logn) time, and by Lemma 5, we merge Vis(Pv,q) and Vis(PuPv,q) in O(logn) time to obtain Vis(Pu,q). Finally, using the data structure 𝒟u, we compute Vis(PPu,q) in O(logn) time and merge it with Vis(Pu,q), again in O(logn) time, to obtain Vis(q).

    Let Q(n) denote the query time. Since |Pv|<n/r, the recursive computation of Vis(Pv,q) takes Q(n/r) time. Hence, the recurrence relation is

    Q(n)=Q(n/r)+O(logn),

    which solves to Q(n)=O(logn) for r=nϵ, where ϵ is a constant.

The following theorem summarizes our result.

Theorem 13.

Given a simple polygon P with n vertices, a data structure of size O(n2+ϵ) can be constructed in O(n2+ϵ) time such that the visibility polygon Vis(q) can be computed in O(logn) time for any query point qP.

 Remark.

One may wonder whether the balanced decomposition 𝒯(P) from Section 3.3 could replace our decomposition Ψ to achieve the same result. This, however, appears challenging because 𝒯(P) does not satisfy the gate property. Indeed, each subpolygon in 𝒯(P) may connect to the “outside world” through up to O(logn) diagonals. This limitation is precisely why we introduce a new decomposition for P.

6 A quadratic-space data structure

In this section, we present our data structure of complexity O(n2logn,n2,lognloglogn). We will first give a data structure of O(n2log5n,n2log4n,lognloglogn) using our decomposition Ψ. By integrating it with the framework in Section 3.3, we will reduce the space to O(n2) and reduce the preprocessing time to O(n2logn), while keeping the same query time.

In the preprocessing phrase, we compute the decomposition tree Ψ and the data structure of Theorem 8. This takes O(n2log4n) space and O(n2log5n) preprocessing time.

Super-levels.

We partition Ψ into O(loglogn) 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 i-th super-level Ψi, with 1iO(loglogn), is defined as follows.

We assume that the set Ri of the roots of all component subtrees of Ψi is already known and that the following algorithm invariants hold for Ri: (1) |Pv|2n/22i for every node vRi; (2) the subpolygons Pv for all vRi are edge-disjoint; and (3) for each node vRi with i>0, its parent lies in the (i1)-th super-level. Initially, when i=0, the set R0 consists of a single node that is the root of Ψ, and thus all invariants hold for R0.

We now define Ψi. Consider a node vRi. Let Ψ(v) denote the subtree of Ψ rooted at v. We borrow several concepts from Section 5. A non-root node u of Ψ(v) is called a border node of Ψ(v) if |Pup||Pv|/22i and |Pu|<|Pv|/22i, where up is the parent of u. The border nodes, together with all their ancestors in Ψ(v), form a subtree Ψb(v) of Ψ(v). Let Ψi(v) denote the subtree of Ψb(v) obtained by removing all its leaves, and let Bv denote the set of border nodes of Ψ(v). We then define

Ψi=vRiΨi(v)andRi+1=vRiBv.

We have the following observation.

Observation 14.

All algorithm invariants hold for Ri+1.

Proof.

Consider a node uBv for some vRi. By definition, |Pu||Pv|/22i. Since |Pv|2n/22i, we obtain |Pu|2n/22i+1. This proves the first invariant.

For the second invariant, by definition, Pu of all nodes uBv are edge disjoint (this is because the path from any leaf to the root of Ψ(v) has exactly one border node). Since Pv for all nodes vRi are edge disjoint, we obtain that Pu for all nodes uRi+1 are edge disjoint. This proves the second invariant.

By definition, the parent of each node of Ri+1 is in the i-th super-level Ψi. Therefore, the third invariant also holds.

Finally, note that if |Pv|=O(22i) for any vRi, we simply set Ψi(v)=Ψ(v), which marks the last super-level. Since |Pv|2n/22i, this occurs for i=O(loglogn), implying that the total number of super-levels is O(loglogn).

Preprocessing.

With the super-levels defined above, we perform the following preprocessing.

Consider the i-th super-level Ψi. For each node vRi and each node uΨi(v), note that v is an ancestor of u in Ψ. By the gate property, Pu is separated from PvPu by the gate du of u. We construct a data structure 𝒟u(v) for Pu with respect to du in Pv, such that, for any query point qPu, Vis(PvPu,q) can be computed in O(logn) time. This is a diagonal-separated subproblem and such a data structure can be constructed in O(|Pv|2) space and O(|Pv|2logn) preprocessing time [2], as described in Section 3.1.

We now analyze the total space required for the data structures in Ψi. By the same argument as in Lemma 12, we have |Ψi(v)|=O(22i) since Ψi(v) consists of the internal nodes of Ψb(v). Hence, the total space for all data structures 𝒟u(v), over all nodes uΨi(v) and all vRi, is O(vRi|Pv|222i). Because the subpolygons Pv for all vRi are edge-disjoint, we have vRi|Pv|=O(n). Moreover, since |Pv|2n/22i, it follows that vRi|Pv|2=O(n2/22i). Therefore, the total space of all data structures in the i-th super-level is O(n2), and the total preprocessing time is O(n2logn).

Hence, building the data structures for all O(loglogn) super-levels takes O(n2loglogn) space and O(n2lognloglogn) preprocessing time. Including the preprocessing for Theorem 8, the total space becomes O(n2log4n) and the total preprocessing time is O(n2log5n).

Queries.

Given a query point q, by a point location query, we find the node u of Ψ whose core Pcore(u) contains q. We then compute Vis(Pu,q) in O(logn) time using Theorem 8.

Assume that u belongs to the i-th super-level for some i, i.e., uΨi. Let v be the node in Ri such that uΨi(v). Using the data structure 𝒟u(v), we compute Vis(PvPu,q) in O(logn) time. Since Pu is separated from PvPu by the gate du, we can obtain Vis(Pv,q) by merging Vis(Pu,q) and Vis(PvPu,q) in O(logn) time using Lemma 5.

If i=0, then Pv=P, and thus Vis(q)=Vis(Pv,q) is already computed. Otherwise, let u be the parent of v. By the algorithm invariants, u lies in the (i1)-th super-level. By Theorem 8, we can compute Vis(PuPv,q) in O(logn) time. Since Pv is separated from PuPv by the gate dv, we can merge Vis(Pv,q) and Vis(PuPv,q) in O(logn) time to obtain Vis(Pu,q). As u lies in the (i1)-th super-level, we repeat the same procedure until reaching the 0-th super-level, after which Vis(q) is obtained.

Since there are O(loglogn) super-levels and each super-level requires O(logn) time, the total query time is O(lognloglogn). For reference, we summarize the result below.

Lemma 15.

We can construct a data structure of size O(n2log4n) in O(n2log5n) time for P such that Vis(q) can be computed in O(lognloglogn) time for any query point qP.

We further reduce the preprocessing complexities in the following theorem.

Theorem 16.

Given a simple polygon P with n vertices, a data structure of size O(n2) can be constructed in O(n2logn) time such that the visibility polygon Vis(q) can be computed in O(lognloglogn) time for any query point qP.

Proof.

We follow the framework of Section 3.3 to construct the balanced decomposition 𝒯(P) and solve the diagonal-separated subproblems using the quadratic-space method of [2], as reviewed in Section 3.1. This requires O(n2) space and O(n2logn) preprocessing time.

Let 𝒯t(P) denote the subtree of 𝒯(P) consisting of its top t levels, where t is the smallest integer such that the subpolygon Pv at every node v of the t-th level has size at most n/log5n. By the definition of 𝒯(P), we have t=O(loglogn).

For each leaf v𝒯t(P), we construct a data structure 𝒟v as in Lemma 15 for Pv. Each such data structure requires O(|Pv|2log4n) space and O(|Pv|2log5n) preprocessing time. Hence, the total preprocessing time for all data structures 𝒟v of the leaves v𝒯t(P) is O(vL|Pv|2log5n), where L denotes the set of leaves of 𝒯t(P). Since the subpolygons Pv for all leaves vL form a partition of P, we have vL|Pv|=O(n). Furthermore, because |Pv|n/log5n for all vL, it follows that vL|Pv|2=O(n2/log5n). Thus, the total preprocessing time of all 𝒟v is O(n2), and the total space is also O(n2).

This completes the preprocessing, which requires O(n2) space and O(n2logn) time in total.

For a query point qP, we first locate the leaf node vL such that Pv contains q, which takes O(logn) time using a point location query. Then, by Lemma 15, we compute Vis(Pv,q) in O(lognloglogn) time using 𝒟v. Next, as described in Section 3.3, we use the diagonal-separated data structure to compute Vis(Pu,q) in O(logn) time for the parent u of v. In general, by following the path from v to the root in 𝒯(P), Vis(q) can be computed in an additional O(lognloglogn) time since the path has O(loglogn) nodes. Therefore, the total query time for computing Vis(q) is O(lognloglogn).

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.