Line Segment Visibility in Simple Polygons: Exact, Robust, Scalable Computation and Applications
Abstract
The weak visibility polygon of a line segment inside a simple polygon , denoted by , is the region of the polygon that is visible from at least one point on . Given its fundamental nature in computational geometry, several algorithms have been proposed to compute weak visibility polygons efficiently, each with different trade-offs in terms of preprocessing time, query time, and space complexity. Although there are many applications that require computing these polygons such as computer graphics, robot motion planning, and network communication systems, there is a lack of any implementations of these algorithms in the literature – not to mention one that is exact, robust, and scalable. Furthermore, weak segment visibility polygons are used as basic building blocks in several other algorithms, such as in minimum-link path computation.
In this work, we present an implementation of an optimal linear-time algorithm for computing the weak visibility polygon of a segment inside a triangulated simple polygon. Our implementation provides exact, robust geometric primitives and optimizations to handle large inputs with more than vertices. We demonstrate two concrete applications: (1) construction of window partitions, a standard data structure in visibility algorithms, and (2) support for optimal minimum-link path queries between two points in a simple polygon, the latter serving as a direct use case of the former. Experimental results on a variety of polygon families confirm that the end-to-end running time scales linearly with the size of the polygon and is dominated by the cost of computing the triangulation, validating the practicality and scalability of the approach. The implementation is released as open source in the format of a CGAL package to support reproducibility and further research.
Keywords and phrases:
Visibility, line segments, link distance, window partition, computation, implementation, robustness, scalability, exactness, CGALFunding:
Prahlad Narasimhan Kasthurirangan: Work was carried out during a research stay at TU Braunschweig. Partially supported by the US Office of Naval Research under grant no. N00014-26-1-2088.Copyright and License:
Kollhoff, Chek-Manh Loi, and Michael Perk; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Computational geometry ; General and reference Experimentation ; Mathematics of computing Arbitrary-precision arithmeticAcknowledgements:
We thank the authors of [4] for sharing parts of their implementation with us.Funding:
Supported by the German Research Foundation (Deutsche Forschungsgemeinschaft, DFG) as part of project Computational Geometry: Solving Hard Optimization Problems (CG:SHOP) – 444569951.Editors:
Hee-Kap Ahn, Michael Hoffmann, and Amir NayyeriSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
Developing efficient methods for geometric problems is at the core of computational geometry. The usual quality measure for such algorithms is their asymptotic worst-case complexity, making non-trivial, linear runtime an ultimate achievement, such as Chazelle’s triangulation algorithm [11]. While this is undoubtedly one of the intellectual pinnacles of the field, and widely used as a subroutine for achieving fast asymptotic worst-case complexities for many other algorithms, its sophistication also highlights a serious issue: We are not aware of any practical implementation, leaving a serious question posed by none other than Chazelle himself, “Can computational geometry meet the algorithmic needs of practitioners?” [12].
Achieving this goal requires significant additional effort, often involving tough choices and scientific expertise. From the practical side, asymptotic worst-case complexity does not suffice; instead, we require actual scalability: what size instances can indeed be solved in reasonable time? This matters not only for hard problems, but also for algorithms for relatively “easy” tasks that are used as repetitive subroutines when dealing with more complex problems.
Another serious challenge is to achieve robustness, i.e., ensuring that an implementation does not fail catastrophically in the vicinity of geometric degeneracies? As demonstrated by Kettner, Mehlhorn, Pion, Schirra and Yap [33], even simple algorithms such as Graham’s scan [23] can produce completely erroneous results when simply run with floating point arithmetic. An important tool to aid in achieving robustness is the use of exact computations, combined with correct handling of all degenerate special cases such as collinear points and overlaps, ensuring that numerical issues cannot lead to any errors. Achieving this with managable performance impact has been one of the goals in community efforts such as CGAL [55], which won the SoCG Test of Time Award in 2023; among many relevant publications, see Boissonat [5] for a practical paper on triangulations. Finally, an implementation can only be used if it is available, i.e., its code is published in a usable state and under a suitable license.
In this paper, we demonstrate practical progress along these lines. We describe (and provide) a practical solution for a fundamental problem of Computational Geometry: Compute the weak visibility polygon of a segment within a simple polygon . This task occurs in a wide variety of problems, such as in robot navigation or optimal surveillance, e.g., in the classical Watchman Problem; see the surveys by Mitchell [45, 44]. In theory, the weak visibility polygon of a segment can be computed in linear time, combining Chazelle’s triangulation algorithm with an algorithm by Guibas, Hershberger, Leven, Sharir and Tarjan [24]. However, to this date, there is no scalable, robust and exact implementation that solves this problem. Indeed, we are unaware of any open source implementation. Further relevance is highlighted by the relation to problems such as the Art Gallery Problem, which is not only -hard, but even known to be -complete [1], illustrating the fragility of solutions and the need for robust solutions. Our implementation has all these properties.
-
It is scalable: We can solve instances with points within seconds.
-
It is robust and exact: We use exact arithmetic for all computations.
-
It is also available: it comes as a CGAL package that can be used out of the box.
In this way, we literally follow Chazelle’s Recommendation #1 in his 1996 task force report for the first practice track of SoCG, which is also central for SoCG’s new practice track: “production and dissemination of geometric code” [12]. In addition, we showcase two major use cases to demonstrate the practical applicability of our code for large-scale instances: we show how to compute a window partition of a polygon , as well as computing the minimum link path between two points in , for polygons with up to vertices.
1.1 Preliminaries
In the following, denotes a simple polygon and its number of vertices. Two points and are visible to each other if the line segment . The visibility polygon of a point , denoted by , is the set of all points in visible to . Given a segment inside of , the weak visibility polygon is the set of all points in that are visible from some point on , i.e., ; see Figure 1.
For two points , the link distance between them is the minimum number of edges in any polygonal path within between and (see Figure 1, Left). Consider a point and its visibility polygon . The vertices of are either vertices of or the shadows of reflex vertices of seen by . The edges of between reflex vertices and their shadows are called windows. A window is a chord of and divides into two parts; define to be part of which does not contain . The window partition is the partition of returned by Algorithm 1 described by Suri [50] given input . We drop the subscript from when it is clear from context which polygon we are referring to.
Let denote the region generated by a window . The rooted dual tree of has as vertices the windows defining and edges between two vertices if their regions share a common boundary. The root of is . We refer to as the window tree of . See Figure 1, Right. Let denote the minimum distance of two nodes in and consider a point . The link distance is [50].
Constructing a triangulation of a polygon takes linear time [11]. Thus, computing for a segment in takes linear time – first triangulate , then use the algorithm from [24]. As we are unaware of any implementation of [11], we use a constrained Delaunay triangulation of provided by CGAL [5]. This has a worst-case complexity of [8] but works extremely well in practice, avoids degenerate triangles and thus simplifies our workflow. Our implementation runs in linear time given as in [24]. To achieve this runtime, we implemented a specialized data structure called a finger tree [30, 29] (see Section 2.1). To the best of our knowledge, all previous implementations of finger trees are in functional programming languages like Haskell or Scala [29, 22]; we used C++ for their iterative versions. We implemented an improvement to [24] suggested in [50]; this allows us to compute in time linear in the number of triangles in it intersects rather than . Apart from allowing us to reliably compute even in extremely large input polygons, this is crucial to compute window trees in . All our implementations use exact number types and handle degeneracies. In Section 2, we review the algorithms introduced in [24, 50] and discuss relevant implementation details. We recommend readers familiar with these results to skim through our implementation notes in Section 2 before skipping to Section 3.
1.2 Related work
Computing visibility polygons is central to computational geometry. We focus on weak visibility polygons of segments inside simple polygons; for a more general overview of visibility problems, see [56, 46, 48, 21, 15]. Given a triangulation of a polygon, Guibas, Hershberger, Leven, Sharir and Tarjan [24] presented an algorithm that computes the visibility polygon. A number of algorithms have been proposed for data structures that can efficiently compute these for a query segment , each with its own trade-offs in terms of preprocessing time, query time, and space complexity. We summarize the most relevant ones in Table 1.
| Data Structure | Preprocessing Time | Size | Query Time |
|---|---|---|---|
| Bose, Lubiw and Munro [6] | |||
| Bygi and Ghodsi [9] | |||
| Aronov et al. [3] | |||
| Chen and Wang [13] | |||
| Chen and Wang [13] | |||
| Guibas et al. [24] | |||
| With finger tree | |||
| With CGAL’s Multiset |
Our results are given in bold. We remark that implementing the more recent results with improved output sensitive query time [3, 6, 9, 13] with exact predicates seems extremely challenging. It is also unclear if these will lead to improvements in runtime in practice (see Section 4 for experiments).
Computing segment visibility is a crucial subroutine in several important geometric data structures; perhaps the most well-known one being window partitions and window trees [50]. Other than computing minimum link paths, window partition is also used in convex decomposition algorithms [7, 38] as well as in pursuit evasion problems [52].
Minimum link paths have numerous applications across domains: in motion planning, where turns are expensive and their number should be minimized [47]; in communication systems design under line-of-sight constraints, where a min-link path minimizes the number of necessary repeaters; in placement of telescoping manipulators with flexible telescopic links [34]; in curve simplification by approximating curves with minimum link paths [25, 31, 43]; and in VLSI layouts, where wires typically run along orthogonal axes, motivating the study of link path problems in rectilinear settings [54, 14]. For a comprehensive overview, we refer the reader to [39, Chapter 12] and [40]. There also exist several works on implementing minimum link paths: [53] is restricted to rectilinear paths and is the only work with a publicly available implementation we could find, [20, 57] also consider rectilinear paths, and [17, 58] are restricted to rectilinear environments. Baum, Bläsius, Gemsa, Rutter, and Wegner use minimum link paths in [4] to simplify the boundary of a polygon in a corridor; this is the only other experimental paper on (non-rectilinear) minimum link paths we are aware of. While the authors provided parts of their non-public implementation to us and the paper provides valuable insights into optimizing minimum link path computations for a specific source-target pair, their implementation is tailored to their specific use case and does not offer a method to compute optimal paths between two arbitrary points in a simple polygon.
2 Weak visibility of a segment
In this section, we give an overview of the algorithm by Guibas, Hershberger, Leven, Sharir and Tarjan [24] for computing the visibility polygon of a segment inside a simple polygon . For a more detailed explanation we refer the reader to the original paper. Consider a triangulated simple polygon and line segment in . The algorithm has two steps: first, we compute the shortest path tree from both and (see Section 2.1 for a definition). Simple data structures can compute this in time, reduced to using a finger tree. In the second step, we compute in linear time by iterating over all edges of the polygon and testing if any part of them is visible from . We only require (amortized) constant time to determine this for each edge of (and to return the part of this edge that is seen) when we have the shortest path trees of and . We discuss details in Section 2.2.
2.1 Shortest path tree
Let be a simple polygon with vertices and let be a given source vertex of . For two points , let denote the Euclidean shortest path between and inside . Lee and Preparata [37] showed that for all vertices of , is a polygonal path whose corners are vertices of and that over all vertices forms a tree rooted at . We use to denote this shortest-path tree rooted at – the vertices of are vertices of and is an edge of the tree if it is an edge of either or .
Let be a triangulation of and the dual graph of . Let be a diagonal or and edge of and let be the deepest common ancestor of and in , see Figure 2 Left. Then the path and are two outward convex chains [37], i.e., the convex hull of each subpath lies outside of the region bounded by , , and . Following [37], we call the funnel of with cusp .
We compute in linear time by maintaining funnels of diagonals in as we process its vertices. We maintain the current funnel as a sorted list where is the cusp of , and with and . We call Algorithm 2 [24] with and an adjacent vertex as the initial funnel ; for an interior source point , we start by locating the triangle containing and create three funnels, one for each edge, with cusp .
We explain Lines 4 and 11 of Algorithm 2 in more detail. As and are outward convex, the slopes of the segments defining them are monotonic. Thus, we can do a binary search on these slopes to find the point of tangency for to in Line 4; see Figure 2, Left. We do not store shortest paths explicitly as suggested by Line 11, we simply store back pointers from to ; is computed by following these pointers until we reach .
Although using binary search as above is straightforward with a binary search tree, it requires time, as and (and thus our list representing ) might contain elements. For an overall linear runtime, we need to find in (amortized) constant time. This is achieved by storing the list as a so-called finger tree [26]. Our finger trees are modified 2-3 search trees which include pointers (called fingers) to the last and first element of . They allow for access to , as well as the splitting of at in time, where is the distance from to the nearest finger. See Guibas, McReight, Plass and Roberts [26] for details on properties of finger trees. Gibiansky [22] also provides valuable insights.
Implementation notes.
To the best of our knowledge, all implementations of finger trees are in functional programming languages; we implemented an iterative version in C++. As suggested in [24], we can use simpler data structures such as linked lists to represent funnels, resulting in a runtime of instead. To compare with our finger tree implementation, we use CGAL’s built-in Multiset class, as it supports search and split natively. In Section 4, we evaluate the performance of our finger tree implementation against CGAL’s Multiset class. Collinear points pose a challenge for balanced trees, as orientation checks alone cannot establish a strict ordering. By carefully distinguishing cases, we ensure that the funnel remains free of collinearities at all times.
2.2 Segment visibility polygon
Given a polygon and a segment inside of , recall that the weak visibility polygon contains all points in that are visible from a point on , i.e., . The following structural lemma is crucial.
Lemma 1 ([24]).
If a point interior to an edge is visible from a segment then (up to swapping and ) the two paths and are outward convex.
Consider such an edge . The structure formed by , , and is called an hourglass, see Figure 2, Right. When running the shortest path tree algorithm with as the source, the funnel has as its cusp and as an adjacent vertex. Similarly, when running the algorithm with as the source, the funnel has as its cusp and as an adjacent vertex. These two tangents define the visible section of .
During the computation of the , we check, for each vertex , in constant time if is outward convex or not. To extract the visibility polygon, we iterate over the vertices of the polygon and check whether an edge is (partially) visible as explained above. Then we connect continuous visible portions of the boundary, skipping over invisible edges, by connecting visible vertices with their shadow vertices (defined by the tangents). While the algorithm defined in [24] is not output sensitive (taking time regardless of the size of ), we explain in Section 2.3 modifications to this algorithm to have this characteristic.
Implementation notes.
Although point visibility is available in CGAL [28], our implementation can also compute the visibility polygon of a point by essentially treating it as degenerate segment, simplifying window extraction. Figure 3 shows the visibility polygon of a query point . All labeled points are collinear, so the point is visible from . We call these low-dimensional features caused by degeneracies needles and the polygons that have them non-regularized. Often needles are undesired; however, for the implementation of the window partition tree in Section 2.4, we require such visibility polygons. Thus, the visibility polygons we generate are non-regularized; we provide a simple linear-time post-processing function that regularizes visibility polygons for use cases where such polygons are preferred.
2.3 Output sensitivity
A naive implementation of Algorithm 1 using [24] would, for each window, compute a complete shortest path tree of , resulting in a worst case runtime of . Suri [50] suggested modifications to [24] to make the computation of segment visibility output sensitive. The main idea is to synchronize the shortest path tree computation of both endpoints of a segment and abort the computation of the visibility polygon if an edge is no longer visible from .
Let be a simple polygon and be a triangulation of the interior of . For a given segment , we start by computing the shortest path tree rooted in and along the triangles intersected by . When processing the next point in a triangle , we only continue with a diagonal if either and , or and are both outward convex. Symmetrically, we only continue with diagonal if either and , or and are both outward convex. The resulting runtime to compute a visibility polygon , is , where is the number of triangles intersected by . To ensure that the implementation achieves this runtime, we carefully adjust the traversal of the polygon boundary to only consider vertices that are part of the considered triangles.
Note that can be arbitrarily large compared to the size of the visibility polygon , e.g., for a triangular visibility polygon that intersects many triangles of . However, exploiting the fact that each triangle is intersected by at most three partitions [50], we obtain a linear-time algorithm to compute the window partition of a point in . Note that to start the shortest-path tree computation, we have to locate a triangle intersecting . We do this using CGAL’s built-in locate function, which in the worst case has a linear runtime.
2.4 Window partition
To compute the window partition , we combine Algorithm 1 with our output sensitive visibility polygon computation. The algorithm initially computes a single triangulation of , which we use to compute the non-regularized visibility polygon of , giving us the initial set of windows. Then, for each window , we can compute the visibility polygon on the remaining polygon . We reuse by checking if the next vertex is in . This window partition forms the basis for our implementation of the minimum link path algorithms in Section 3.
3 Minimum link path
For a simple polygon and two interior points and , the link distance between and is the minimum number of line segments (links) required to form a polygonal path from to that is completely contained in . The link metric has received considerable attention in computational geometry [49, 50, 42, 2, 41, 35, 27], typically focusing on answering distance queries and not constructing actual minimum link paths. Using window partition trees and other observations, Arkin, Mitchell and Suri [2] proposed an algorithm that can answer link distance queries in time with preprocessing time and space. Although the authors mention that the path can be constructed by backtracking through the windows, no details are provided. We implemented two linear time algorithms [50] for answering minimum link path queries based on window partitions: an exact algorithm and an (additive) approximation algorithm that is at most four links longer than the optimal solution.
3.1 Exact algorithm
To construct exact minimum link paths from a source point to any target point in a simple polygon , we use the window partition rooted at . First, we locate the region that contains and then traverse the unique path from to in . Our construction of informs us of a minimum link path from to in that has a vertex on each of the windows in that order. Constructing takes time and space [50] and locating the target node takes . Point location could be reduced to time with preprocessing, but the preprocessing takes super-linear time [15, Chapter 6]. In Section 3.3, we explain how we reconstruct the minimum link path in in linear time.
3.2 Approximation algorithm
To compute an additive () approximative minimum link path from to in a simple polygon , we can use the window partition of an arbitrary point . For two vertices and of , let denote the distance in between them.
Lemma 2 ([50]).
Let be two nodes of , and let be two points of . Then .
The idea is to first identify the two regions and that contain and in respectively. Then, we identify the lowest common ancestor of and in . This allows us to construct two paths: one from to and one from to . Finally, we have to connect the two paths with an additional link on .
Note that, even if or , i.e., the path is directed in , we may still require an additional link using the above algorithm: let and be a directed path in . As in Section 3.1, we construct a path from to with one vertex on each window for . Unlike the exact algorithm, we cannot guarantee that is visible from , we can only guarantee the existence of a point on that is visible from . Therefore, we may need to add an additional link from to and then to .
We precompute window partitions rooted at a set of seed vertices and answer queries by probing a small subset of them. At query time, a small set of candidate seed vertices is chosen, e.g., the nearest to the endpoints. Additionally, we post-process the candidates by removing any introduced loops. The algorithm returns a path with a minimum number of links among all candidates and runs in time proportional to the number of candidates and the cost of locating nodes and reconstructing paths, i.e., in the worst case for candidates. Note that Lemma 2 also provides a lower bound on the link distance between and that can be used to evaluate the quality of the approximated path.
3.3 Path reconstruction
Now we reconstruct the path from to for the exact algorithm detailed in the prior sections. Specifically, we look to construct , where belongs to the window . This is done backwards from . For the step from to , any point on works because sees all points on . For going from a window to , this can easily be done in by extending to a line and determining its intersection with . However, especially if is not fixed when constructing the window partition, e.g., because we are answering multiple queries with the same source , we need to find a point on the last window that sees . There is a straightforward algorithm that can do this in linear time: compute and intersect this with to obtain the maximal connected subsegment of that sees . In practice, this approach is not preferable due to the lack of efficient implementations of visibility algorithms for non-regularized polygons that often appear in the generated window partitions, see Figure 3. The linear-time algorithm available in CGAL [28] is not directly applicable, as it requires the polygon to be simple. Additionally, the triangular expansion approach implemented in CGAL, which is often preferred in practical applications, requires a triangulation of each window, which cannot be directly derived from our triangulation of , as windows are not necessarily edges of the triangulation; even if we had such a triangulation, the interface of CGAL’s visibility package does not allow specifying a triangulation as input. Even without these issues, triangulating each region separately would result in a (practical) superlinear worst-case runtime.
To avoid these problems, we compute the maximal connected subsegment of that is visible from in linear (in the complexity of ) time as follows. Consider the ray between and the left endpoint of ; this possibly intersects . Consecutive hitting points define chains of edges on one side of the ray that occlude parts of . March through the vertices in these chains and choose the vertex defining the rightmost ray from through it. We find the supporting ray for the right endpoint symmetrically. If these supporting rays cross, is not visible from (an impossibility). Otherwise, they define the maximal subsegment on visible from ; see Figure 4 for an illustration. Because each other step of path reconstruction takes time , this allows path reconstruction for source in time once is computed and the window containing is identified.
For the approximation algorithm, we apply the above procedure for both the windows containing and ; apart from this and an added segment on the window defining their deepest common ancestor, the situation is analogous.
4 Experimental evaluation
In this section, we present the experimental evaluation of our implementations, see Figure 5 for some example outputs. All experiments were run on otherwise idle workstations equipped with AMD Ryzen 7 5800X CPUs and 128 GiB of DDR4-3200 memory, using Ubuntu Linux 24.04.3 LTS as operating system. The core routines were implemented in C++17, compiled against CGAL 6.0.1 and Boost 1.83.0 using g++ 13.3.0. Our instances and code are publicly available111https://doi.org/10.5281/zenodo.19194126. To guard against programming errors, our code contains large amounts of optional checks and assertions. We also ran a suite of tests with these checks enabled, using instrumentation with tools such as the undefined behavior and address sanitizers of our compiler, which should catch essentially all memory errors. We validated that all paths and visibility polygons found in our experiment stay within the given polygon, and any approximate path has at least the same number of links as the corresponding exact link path.
4.1 Weak line segment visibility
For evaluating our implementation, we consider the following research questions.
- RQ1
-
How does our implementation scale to large inputs, and how is the total runtime distributed onto the individual subroutines?
- RQ2
-
Is there a measurable difference between using finger trees and CGAL’s multiset? Which of the two approaches is faster?
- RQ3
-
How does the performance of our implementation depend on the size of the output?
To address these questions, we randomly generate segments for simple polygons from the Salzburg Database of Geometric Inputs222We used all valid simple polygons from https://zenodo.org/records/3784789 not labeled as contrived. [19], the largest of which has vertices. These polygons are of various types and include polygons with many collinear points or other degeneracies. To generate segments, we sample a source point uniformly at random within the given polygon, compute the visibility polygon of that point, and then either sample a target point in the visibility polygon or pick a random vertex of it. The former approach corresponds to sampling segments inside polygons uniformly at random, whereas the latter focuses on placing one of the endpoints on the boundary of the polygon, exercising edge cases. Using each polygon and each approach twice results in a total of instances. For each such instance, and each of the two shortest path tree data structures, we compute the exact visibility polygon five times, measuring the runtime (both total and of various subroutines). Figure 6 depicts the resulting runtimes.
We can see that the overall runtime is dominated by computing a triangulation of the input polygon, which we do via CGAL’s constrained Delaunay triangulation (CDT). Even CGAL’s mark_in_domain routine, which simply flags the CDT’s triangles that constitute the polygon, is typically more expensive than the actual visibility computation. The fact that the runtime for the visibility computation seems to be almost unaffected by the size of the input polygon can be explained by the fact that it – except for a few small operations such as finding the segment endpoints in the triangulation – mostly depends on the size of the output polygon; see Figure 7, Left. On our inputs, the implementation using finger trees is slightly faster than the one using CGAL’s Multiset, see Figure 7 Right. In a preliminary microbenchmark based on building funnels by left insertion, our finger trees became significantly faster already at around funnel vertices; this makes a difference even for the typically small funnels we encounter in our algorithm. We therefore used our finger trees in our other experiments.
4.2 Minimum link paths
Recall that computing a window partition is a basic routine that is useful in different contexts. Furthermore, we only need one window partition from a source point to compute shortest link-distance paths to any target , and only a constant number to approximate shortest link-distance paths for any source-target pair inside our polygon. We therefore study the performance of our window partition on its own, as well as in the context of minimum link paths, addressing the following research questions.
- RQ4
-
How does our window partition implementation scale to large polygons?
- RQ5
-
How does it compare to the other parts of our exact minimum link path implementation?
- RQ6
-
How does the approximate minimum link path algorithm perform w.r.t. runtime and solution quality?
To answer these questions, we randomly selected a sample of simple polygons with at most vertices from [19]. For each such polygon , we generate source points uniformly at random and computed a window partition for each source. Furthermore, for each source point , we generate a random target point outside of the visibility polygon of and computed an exact minimum link --path, as well as an approximate minimum link path using randomly chosen source points for the window partitions in our approximation. The resulting runtimes are depicted in Figure 8.
For each path computed using the approximation algorithm, Figure 9 shows the absolute, additive error depending on the number of window partitions ; the quality of the approximation notably improves with higher . One should, however, note that increasing makes both preprocessing and path reconstruction more expensive, both scaling linearly in .
Overall, we find that both our window partition and minimum link path implementation scale well to large polygons; in fact, in our experiments, time spent inputting, verifying and outputting polygons was typically orders of magnitude higher than pure computation time. If we want to query minimum link paths from a single source , each subsequent query helps amortizing the cost of computing a window partition; similarly, for doing many queries for different sources and targets in the same polygon, the approximate algorithm can be used to amortize the cost of computing a constant number of window partitions. Depending on the relative importance of runtime versus solution quality, the approximation may be preferable.
5 Conclusions
We presented a scalable, robust and exact implementation for computing the weak visibility polygon of a line segment in a simple polygon. We also demonstrated two concrete applications: computing the window partitioning, and computing the link distance between two points inside a simple polygon. For further improvement on the algorithm engineering side, we could parallelize the shortest path tree and window partition implementations.
An immediate generalization is to non-simple polygons. Suri and O’Rourke [51] studied algorithms for computing visibility polygons with holes. Following the approach described in [10], we can extend our implementation to handle polygons with holes by first splitting the polygon into simple subpolygons and then computing the union of these visibility polygons. The same can be considered for link distance in polygons with holes [42, 40].
Another set of applications arises from using our implementation as a critical tool for dealing with more complex optimization problems that require frequent visibility queries as the critical subroutine. An important example is the Watchman Route Problem (WRP), in which the goal is to find a cheapest tour in a (simple or non-simple) polygon for a watchman along which every point in can be seen; here “cheapest” may refer to a minimization of total length or correspond to the number of involved edges. (There are numerous other variants, such as using multiple watchmen.) While a minimum-length watchman tour inside a simple polygon can be computed in polynomial time inside a simple polygon, with the best known time bounds [18] being for the “anchored” WRP, in which the tour is required to pass through a specified anchor point, and for the “floating” WRP, in which no anchor point is specified; this is only efficient in theory, and we are not aware of any practical implementations. Moreover, the problem is -hard for non-simple polygons (with an immediate reduction from the TSP), so practical computation requires more involved exact algorithms that combine the computation of shortest tours with set cover, i.e., many segment visibility computations along the way. This resembles practical approaches for computing optimal solutions for instances of the excruciatingly difficult Art Gallery Problem; as previous work has shown, this may actually hinge on the theoretically “easy” visibility computations instead of the “hard” set cover. For example, of the computation time reported by Kröller, Baumgartner, Fekete and Schmidt [36], 80% was spent on (point) visibility computations: “It is obvious that data structure updates and geometric support procedures are – by far – computationally most expensive, whereas solving the LPs has virtually no runtime impact.” See [16] for a deeper dive into how provably optimal solutions for polygons with up to thousands of vertices can be computed. We are optimistic that our newly developed implementation for segment visibility will be a milestone towards similar progress for Watchman Problems, as well as many of the ensuing variants.
References
- [1] Mikkel Abrahamsen, Anna Adamaszek, and Tillmann Miltzow. The art gallery problem is -complete. Journal of the ACM, 69(1):1–70, 2021. doi:10.1145/3486220.
- [2] Esther M. Arkin, Joseph S. B. Mitchell, and Subhash Suri. Optimal link path queries in a simple polygon. In Symposium on Discrete Algorithms (SODA), pages 269–279, 1992. URL: http://dl.acm.org/citation.cfm?id=139404.139462.
- [3] 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.
- [4] Moritz Baum, Thomas Bläsius, Andreas Gemsa, Ignaz Rutter, and Franziska Wegner. Scalable exact visualization of isocontours in road networks via minimum-link paths. Journal of Computational Geometry, 9(1):27–73, 2018. doi:10.20382/JOCG.V9I1A2.
- [5] Jean-Daniel Boissonnat, Olivier Devillers, Monique Teillaud, and Mariette Yvinec. Triangulations in CGAL. In Symposium on Compuational Geometry (SoCG), pages 11–18, 2000. doi:10.1145/336154.336165.
- [6] Prosenjit Bose, Anna Lubiw, and J. Ian Munro. Efficient visibility queries in simple polygons. Computational Geometry, 23(3):313–335, 2002. doi:10.1016/S0925-7721(01)00070-0.
- [7] Reilly Browne, Prahlad Narasimham Kasthurirangan, Joseph S. B. Mitchell, and Valentin Polishchuk. Constant-factor approximation algorithms for convex cover and hidden set in a simple polygon. In 2023 IEEE 64th Annual Symposium on Foundations of Computer Science (FOCS), pages 1357–1365, 2023. doi:10.1109/FOCS57990.2023.00083.
- [8] Francisc Bungiu, Michael Hemmer, John Hershberger, Kan Huang, and Alexander Kröller. Efficient computation of visibility polygons. CoRR, abs/1403.3905, 2014. arXiv:1403.3905.
- [9] Mojtaba Nouri Bygi and Mohammad Ghodsi. Weak visibility queries in simple polygons. In Canadian Conference on Computational Geometry (CCCG), 2011. URL: http://www.cccg.ca/proceedings/2011/papers/paper95.pdf.
- [10] Mojtaba Nouri Bygi and Mohammad Ghodsi. Weak visibility queries of line segments in simple polygons and polygonal domains. CoRR, abs/1310.7197, 2013. arXiv:1310.7197.
- [11] Bernard Chazelle. Triangulating a simple polygon in linear time. Discrete and Computational Geometry, 6:485–524, 1991. doi:10.1007/BF02574703.
- [12] Bernard Chazelle. The computational geometry impact task force report: An executive summary. In Workshop on Applied Computational Geometry (WACG), pages 59–65, 1996. doi:10.1007/BFB0014485.
- [13] Danny Z. Chen and Haitao Wang. Weak visibility queries of line segments in simple polygons. Computational Geometry, 48(6):443–452, 2015. doi:10.1016/j.comgeo.2015.02.001.
- [14] Mark de Berg. On rectilinear link distance. Computational Geometry, 1:13–34, 1991. doi:10.1016/0925-7721(91)90010-C.
- [15] Mark De Berg, Otfried Cheong, Marc Van Kreveld, and Mark Overmars. Computational Geometry: Algorithms and Applications. Springer, 2008. doi:10.1007/978-3-540-77974-2.
- [16] Pedro J de Rezende, Cid C de Souza, Stephan Friedrichs, Michael Hemmer, Alexander Kröller, and Davi C Tozoni. Engineering art galleries. In Algorithm Engineering: Selected Results and Surveys, pages 379–417. Springer, 2016. doi:10.1007/978-3-319-49487-6_12.
- [17] Nakju Lett Doh, Chanki Kim, and Wan Kyun Chung. A practical path planner for the robotic vacuum cleaner in rectilinear environments. IEEE Transactions on Consumer Electronics, 53(2):519–527, 2007. doi:10.1109/TCE.2007.381724.
- [18] Moshe Dror, Alon Efrat, Anna Lubiw, and Joseph SB Mitchell. Touring a sequence of polygons. In Symposium on the Theory of Computing (STOC), pages 473–482, 2003.
- [19] Günther Eder, Martin Held, Steinþór Jasonarson, Philipp Mayer, and Peter Palfrader. Salzburg database of polygonal data: Polygons and their generators. Data in Brief, 31:105984, 2020. doi:10.1016/j.dib.2020.105984.
- [20] Robert Fitch, Zack Butler, and Daniela Rus. 3d rectilinear motion planning with minimum bend paths. In Proceedings 2001 IEEE/RSJ International Conference on Intelligent Robots and Systems. Expanding the Societal Role of Robotics in the the Next Millennium (Cat. No. 01CH37180), volume 3, pages 1491–1498. IEEE, 2001. doi:10.1109/IROS.2001.977191.
- [21] Submir Kumar Ghosh. Visibility Algorithms in the Plane. Cambridge University Press, 2007.
- [22] Andrew Gibiansky. Finger trees, 2014. URL: https://andrew.gibiansky.com/blog/haskell/finger-trees/.
- [23] Ronald L. Graham. An efficient algorithm for determining the convex hull of a finite planar set. Information Processing Letters, 1:132–133, 1972. doi:10.1016/0020-0190(72)90045-2.
- [24] Leonidas J. Guibas, John Hershberger, Daniel Leven, Micha Sharir, and Robert Endre Tarjan. Linear-time algorithms for visibility and shortest path problems inside triangulated simple polygons. Algorithmica, 2:209–233, 1987. doi:10.1007/BF01840360.
- [25] Leonidas J. Guibas, John Hershberger, Joseph S. B. Mitchell, and Jack Snoeyink. Approximating polygons and subdivisions with minimum link paths. International Journal of Computational Geometry and Applications, 3(4):383–415, 1993. doi:10.1142/S0218195993000257.
- [26] Leonidas J. Guibas, Edward M. McCreight, Michael F. Plass, and Janet R. Roberts. A new representation for linear lists. In Symposium on the Theory of Computing (STOC), pages 49–60, 1977. doi:10.1145/800105.803395.
- [27] Mart Hagedoorn and Valentin Polishchuk. Link diameter, radius and 2-point link distance queries in polygonal domains. In Workshop on Algorithms and Data Structures (WADS), pages 34:1–34:15, 2025. ISSN: 1868-8969. doi:10.4230/LIPIcs.WADS.2025.34.
- [28] Michael Hemmer, Kan Huang, Francisc Bungiu, and Ning Xu. 2D visibility computation. In CGAL User and Reference Manual. CGAL Editorial Board, 6.1 edition, 2025. URL: https://doc.cgal.org/6.1/Manual/packages.html#PkgVisibility2.
- [29] Ralf Hinze and Ross Paterson. Finger trees: a simple general-purpose data structure. Journal of Functional Programming, 16(2):197–217, 2006. doi:10.1017/S0956796805005769.
- [30] Scott Huddleston and Kurt Mehlhorn. A new data structure for representing sorted lists. Acta informatica, 17(2):157–184, 1982. doi:10.1007/BF00288968.
- [31] Hiroshi Imai and Masao Iri. Polygonal approximations of a curve—formulations and algorithms. In Machine Intelligence and Pattern Recognition, volume 6, pages 71–86. Elsevier, 1988.
- [32] Phillip-Raphaël Keldenich, Fabian Kollhoff, Michael Perk, Chek-Manh Loi, and Prahlad Narasimhan Kasthurirangan. Line segment visibility in simple polygons, March 2026. doi:10.5281/zenodo.19194126.
- [33] Lutz Kettner, Kurt Mehlhorn, Sylvain Pion, Stefan Schirra, and Chee Yap. Classroom examples of robustness problems in geometric computations. Computational Geometry, 40(1):61–78, 2008. doi:10.1016/J.COMGEO.2007.06.003.
- [34] K. Kolarov and B. Roth. On the number of links and placement of telescoping manipulators in an environment with obstacles. In International Conference on Advanced Robotics (ICAR), pages 988–993 vol.2, 1991. doi:10.1109/ICAR.1991.240543.
- [35] Irina Kostitsyna, Maarten Löffler, Valentin Polishchuk, and Frank Staals. On the complexity of minimum-link path problems. Journal of Computational Geometry, 8(2):80–108, March 2017. doi:10.20382/jocg.v8i2a5.
- [36] Alexander Kröller, Tobias Baumgartner, Sándor P Fekete, and Christiane Schmidt. Exact solutions and bounds for general art gallery problems. Journal of Experimental Algorithmics, 17:2–1, 2012. doi:10.1145/2133803.2184449.
- [37] D. T. Lee and Franco P. Preparata. Euclidean shortest paths in the presence of rectilinear barriers. Networks, 14(3):393–410, 1984. doi:10.1002/NET.3230140304.
- [38] Jyh-Ming Lien and Nancy M. Amato. Approximate convex decomposition of polygons. Computational Geometry, 35(1):100–123, 2006. doi:10.1016/j.comgeo.2005.10.005.
- [39] Anil Maheshwari, Jörg-Rüdiger Sack, and Hristo N. Djidjev. Link distance problems. In Jörg-Rüdiger Sack and Jorge Urrutia, editors, Handbook of Computational Geometry, pages 519–558. North Holland / Elsevier, 2000. doi:10.1016/B978-044482537-7/50013-9.
- [40] Joseph S. B. Mitchell, Valentin Polishchuk, and Mikko Sysikaski. Minimum-link paths revisited. Computational Geometry, 47(6):651–667, 2014. Special issue on EuroCG’11. doi:10.1016/J.COMGEO.2013.12.005.
- [41] Joseph S. B. Mitchell, Valentin Polishchuk, and Mikko Sysikaski. Minimum-link paths revisited. Computational Geometry, 47(6):651–667, August 2014. doi:10.1016/j.comgeo.2013.12.005.
- [42] Joseph S. B. Mitchell, Günter Rote, and Gerhard J. Woeginger. Minimum-link paths among obstacles in the plane. In Symposium on Computational Geometry (SoCG), pages 63–72. ACM, 1990. doi:10.1145/98524.98537.
- [43] Joseph S. B. Mitchell and Subhash Suri. Separation and approximation of polyhedral objects. Computational Geometry, 5:95–114, 1995. doi:10.1016/0925-7721(95)00006-U.
- [44] Joseph SB Mitchell. Shortest paths and networks. In Handbook of Discrete and Computational Geometry, pages 445–466. CRC Publishing, 1997.
- [45] Joseph SB Mitchell et al. Geometric shortest paths and network optimization. In Handbook of Computational Geometry, volume 334, pages 633–702. North Holland, 2000. doi:10.1016/B978-044482537-7/50016-4.
- [46] Joseph O’Rourke. Art gallery theorems and algorithms. Oxford University Press, Inc., USA, September 1987.
- [47] John H. Reif and James A. Storer. Minimizing turns for discrete movement in the interior of a polygon. IEEE Journal on Robotics and Automation, 3(3):182–193, 1987. doi:10.1109/JRA.1987.1087092.
- [48] Jörg-Rüdiger Sack and Jorge Urrutia. Handbook of computational geometry. Elsevier, 1999.
- [49] Subhash Suri. Minimum link paths in polygons and related problems. PhD thesis, The Johns Hopkins University, 1987.
- [50] Subhash Suri. On some link distance problems in a simple polygon. IEEE Transactions on Robotics and Automation, 6(1):108–113, 1990. doi:10.1109/70.88124.
- [51] Subhash Suri and Joseph O’Rourke. Worst-case optimal algorithms for constructing visibility polygons with holes. In Alok Aggarwal, editor, Proceedings of the Second Annual ACM SIGACT/SIGGRAPH Symposium on Computational Geometry, Yorktown Heights, NY, USA, June 2-4, 1986, pages 14–23. ACM, 1986. doi:10.1145/10515.10517.
- [52] Ichiro Suzuki and Masafumi Yamashita. Searching for a mobile intruder in a polygonal region. SIAM Journal on Computing, 21(5):863–888, 1992. doi:10.1137/0221051.
- [53] Mikko Sysikaski. Rectilinear minimum link paths in two and higher dimensions. Master’s thesis, University of Helsinki, 2019. Available at https://helda.helsinki.fi/bitstreams/9c8e7b5f-f4ac-42ca-bbc6-bb39a4b24782/download.
- [54] Roberto Tamassia. On embedding a graph in the grid with the minimum number of bends. SIAM Journal on Computing, 16(3):421–444, 1987. doi:10.1137/0216030.
- [55] The CGAL Project. CGAL User and Reference Manual. CGAL Editorial Board, 6.1 edition, 2025. URL: https://doc.cgal.org/6.1/Manual/packages.html.
- [56] Csaba D Toth, Joseph O’Rourke, and Jacob E Goodman. Handbook of discrete and computational geometry. CRC press, 2017.
- [57] David Phillip Wagner. Path planning algorithms under the link-distance metric. Phd thesis, Dartmouth College, 2006. Available at https://digitalcommons.dartmouth.edu/cgi/viewcontent.cgi?article=1015&context=dissertations.
- [58] Hu Xu, Lei Shu, and May Huang. Planning paths with fewer turns on grid maps. In Proceedings of the International Symposium on Combinatorial Search, volume 4, pages 193–200, 2013. doi:10.1609/SOCS.V4I1.18298.
