Abstract 1 Introduction 2 Preliminaries 3 Overview of the data structure 4 Dynamic shortest path data structure 5 Static cone query nearest neighbor data structure References

Nearest Neighbor Searching in a Dynamic Simple Polygon

Sarita de Berg ORCID Department of Information and Computing Sciences, Utrecht University, The Netherlands Frank Staals ORCID Department of Information and Computing Sciences, Utrecht University, The Netherlands
Abstract

In the nearest neighbor problem, we are given a set S of point sites that we want to store such that we can find the nearest neighbor of a (new) query point efficiently. In the dynamic version of the problem, the goal is to design a data structure that supports both efficient queries and updates, i.e. insertions and deletions in S. This problem has been widely studied in various settings, ranging from points in the plane to more general distance measures and even points within simple polygons. When the sites do not live in the plane but in some domain, another dynamic problem arises: what happens if not the sites, but the domain itself is subject to updates?

Updating sites often results in local changes to the solution or data structure, while updating the domain may incur many global changes. For example, in the closest pair problem, inserting a point only requires us to check if this point is in the new closest pair, while updating the domain might change the distances between most pairs of points in our set. Presumably, this is the reason that this form of dynamization has received much less attention. Only some basic problems, such as shortest paths and ray shooting, have been studied in this setting.

Here, we tackle the nearest neighbor problem in a dynamic simple polygon. We allow insertions into both the set of sites and the polygon. An insertion in the polygon is the addition of a line segment starting at the boundary of the polygon. We present a near-linear size –in both the number of sites and the complexity of the polygon– data structure with sublinear update and query time. This is the first nearest neighbor data structure that allows for updates to the domain.

Keywords and phrases:
dynamic data structure, simple polygon, geodesic distance, nearest neighbor
Copyright and License:
[Uncaptioned image] © Sarita de Berg and Frank Staals; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Computational geometry
Related Version:
Full Version: https://arxiv.org/abs/2503.03435 [12]
Editors:
Oswin Aichholzer and Haitao Wang

1 Introduction

The nearest neighbor problem is a fundamental problem in computer science: given a set of n point sites S in some domain P, the goal is to store S so that given a query point qP we can efficiently find the point in S closest to q [5, 19]. In case P is the two-dimensional Euclidean plane, such queries can be answered in O(logn) time by computing the Voronoi diagram of S, and storing it for efficient point location queries. In many applications, the domain however may contain obstacles (e.g. buildings, cars, rivers, lakes etc.) that are impassible. Hence, we may want to model P as a simple polygon, or even a polygonal domain (i.e. a polygon with holes), and measure the distance between two points by the length of their shortest obstacle avoiding path. In this setting, it is also possible to build the Voronoi diagram. Aronov [3] showed that the so called geodesic Voronoi diagram in a simple polygon with m vertices has complexity O(n+m), and gave an O((n+m)log(n+m)logm) time algorithm to construct it. This then allows for O(log(n+m)) time nearest neighbor queries. Finding an optimal algorithm to construct the geodesic Voronoi diagram remained elusive for quite a while. Only a few years ago, after a series of improvements [21, 24, 26], Oh showed an optimal O(m+nlogn) time algorithm [22]. When P is a polygon with holes, the Voronoi diagram has the same complexity, and can be computed in O((n+m)log(n+m)) time [16].

Nearest neighbor searching is a decomposable search problem, meaning that to find the nearest neighbor in the set AB, we can compute the nearest neighbor in set A, separately compute the nearest neighbor in set B, and return the closest of these two candidates [4]. Therefore, supporting efficient insertions of new point sites in 2 (while still answering queries in polylogarithmic time) is relatively simple using, for example, the logarithmic method [25]. However, supporting both insertions and deletions in polylogarithmic time, turned out to be quite challenging. Chan [5] presented the first such results, achieving O(log2n) query time while supporting insertions in O(log3n) and deletions in O(log6n) amortized expected time. Kaplan et al. [19] and later Chan [7] further improved the update times to O(log2n) for insertions, and O(log4n) for deletions. Kaplan et al. also generalized these results to other (constant complexity) distance functions [19]. Agarwal, Arge, and Staals [1] showed that these techniques can be extended to efficiently answer nearest neighbor queries in a simple polygon P. De Berg and Staals even presented a data structure that can report efficiently report the k-nearest neighbors, for some query parameter k[n], in this setting [11].

The above results thus support applications in which the set of input points may change over time. However, in such applications, the obstacles are also likely to change. Unfortunately, none of the approaches above support updates to the domain P, e.g. by inserting or deleting an obstacle. Even more generally, there is relatively little work in which the input domain P may change while maintaining some non-trivial structure on P or S. Results of this type are mostly restricted to general purpose range or intersection searching [2, 17] or point location [14]. The most prominent work that we are aware of that specifically maintains some data structure on top of a dynamic polygonal domain is the work by Goodrich and Tamassia [13]. They support ray shooting and shortest path queries in a dynamic connected planar subdivision P^ in O(log2n) time. Ishaque and Tóth show how to maintain the (geodesic) convex hull of S in P^ while supporting the insertion of barriers (non-crossing segments such that all faces are simply connected) and site deletions in O(polylog(n+m)) time [18]. Oh and Ahn generalize this result to supporting both insertions and deletions (of barriers and sites) [23]. They achieve update times of O~((n+m)2/3), where the O~() notation hides logarithmic factors in n and m. A recent result of Choudhury and Inkulu [10] shows how to maintain the visibility graph inside a dynamic simple polygon P using O~(Δ) time per update, where Δ is the number of changes.

Refer to caption
Figure 1: After inserting the green segments, the orange site is the nearest neighbor of q.

Challenges.

A possible explanation for the lack of work in this dynamic domain setting is that the problems seem extremely challenging: even just adding a single line segment to the boundary of the polygon may significantly change the distances between the sites in the polygon. This severely limits what information (i.e. which distances) the data structure can store. An insertion may also structurally change the triangulation of the polygon (which is the foundation upon which, e.g., the data structure of Agarwal, Arge, and Staals [1] is built).

Our results.

We overcome these challenges, and present the first dynamic data structure for the geodesic nearest neighbor problem that allows updates to both the sites S and the simple polygon P containing S. Our data structure achieves sublinear query and update time and allows the following updates on P and S (Fig. 1): 1. inserting a segment (barrier) between points u and v, where u on the boundary P of P and vP an arbitrary point, provided that the interior of this segment does not intersect P, and 2. inserting a site sP into S.

This type of barrier insertion is similar to the insertion operation considered by Ishaque and Tóth [18] and Oh and Ahn [23]. Note that in case v also lies on the boundary of P, this actually splits the polygon into two subpolygons, which can no longer interact. Hence, we can essentially treat these subpolygons independently. In the remainder of the paper, we thus focus on the more interesting case in which v lies strictly in the interior of P. This also slightly simplifies our presentation, since P then remains an actual simple polygon.

Our data structure uses O(n(loglogn+logm)+m) space, supports the above updates in amortized O~(n3/4+m3/4) time, and answers queries in expected O~(n3/4+n1/4m1/2) time. While these query and update times are still far off from the polylogarithmic query and update times for a static domain, they are comparable to, for example, the result of Oh and Ahn for maintaining the geodesic hull in a dynamic polygon [23].

We believe it should be possible to extend our data structure to support deleting sites as well. In particular, by further incorporating the results of Agarwal, Arge, and Staals [1]. However, for ease of exposition we defer site deletions for now. Supporting deleting vertices of the polygon seems more interesting, however also much more complicated. Further ideas are likely required to support deletions of vertices as well.

Organization.

Our data structure essentially consists of two independent parts, both of which critically build upon balanced geodesic triangulations [9]. So, we first review some of their useful properties in Section 2. We then give an overview of the data structure in Section 3. Section 4 describes the first part of our data structure, which can be regarded as an extension of the dynamic two-point shortest path data structure of Goodrich and Tamassia [13]. Our main technical contribution is in Section 5, which describes the second main part: a (static) data structure that can answer nearest neighbor queries in a subpolygon Q of P that can be specified at query time. This result may be of independent interest. Omitted proofs as well as the generalization of some of the results of Agarwal, Arge, and Staals [1] that we need for our data structure, can be found in the full version [12].

2 Preliminaries

Let P be a simple polygon with m vertices, let P be the boundary of P, and let S be a set of n point sites inside P. We denote the shortest path that is fully contained within P between two point p,qP by πP(p,q), or simply π(p,q) if the polygon is clear from the context. Similar to earlier papers about geodesic Voronoi diagrams, we will use the general position assumptions that no point is (ever) equidistant to four sites in S, and no vertex of P is equidistant to three sites.

A geodesic triangulation of P is a triangulation-like decomposition of P into geodesic triangles. A geodesic triangle with corners u,v,wP is formed by the three shortest paths π(u,v), π(v,w), π(w,u). In general, such a geodesic triangle consists of a simple polygon bounded by three concave chains, and three polygonal chains emanating from the vertices where the the concave chains join. The interior of the simple polygon region is called the deltoid region, and the polygonal chains are called the tails of the geodesic triangle. Note that the deltoid region may be empty, for example if w lies on π(u,v).

Similar to a triangulation, a geodesic triangulation decomposes P into O(m) geodesic triangles with corners that are vertices of P whose boundaries do not cross. This triangulation induces a dual tree 𝒯, where two nodes are connected if their respective geodesic triangles share two corners. We root this tree at a node whose geodesic triangle shares a side with an edge of P. A geodesic triangulation is called balanced if the height of this tree is O(logm). A balanced geodesic triangulation can be constructed in O(m) time [9].

A dynamic shortest path data structure.

Here we shortly discuss the data structure of Goodrich and Tamassia for dynamic planar subdivisions [13]. This data structure supports both shortest-path and ray-shooting queries in O(log2m) time. Updates to the subdivision, such as inserting or deleting a vertex or edge, also take O(log2m) time. The main component is a balanced geodesic triangulation with dual tree 𝒯. A secondary dynamic point location data structure [14] is build for this geodesic triangulation. A tertiary data structure stores, for each deltoid Δ, the three concave chains bounding Δ in balanced tree structures. To support shortest path queries, they store for each node in 𝒯 the tail of its geodesic triangle that is not shared by its parent in a balanced tree structure. The size of the data structure is O(m). Using rotations, insertions and deletions can be performed in O(log2m) time.

3 Overview of the data structure

Our dynamic nearest neighbor data structure for a dynamic simple polygon consists of two independent data structures: a Dynamic Shortest Path data structure, which remains up-to-date, and a Cone Query data structure, which is static and is rebuild after a number of updates. We denote by P the current polygon with m vertices and by S the current set of n sites in P. Furthermore, we denote by P~ and m~ the polygon and number of vertices and by S~ and n~ the set of sites and its size at the last rebuild of the Cone Query data structure. Let k be the number of updates (insertions) since the last rebuild, i.e. k=m+nm~n~.

The main purpose of the two data structures is the following. When given a query point q, we first use the Dynamic Shortest Path data structure to compute the distance from q to each of the newly inserted sites, i.e. in SS~. This gives us the nearest neighbor of q among these sites. To find the nearest neighbor of q among S~, we first use the Dynamic Shortest Path data structure to find O(k) regions in P, where each region R is paired with an apex point vR on R. Each regions has the property that the shortest path πP(p,q) from a point pR to q is given by πP~(p,vR)πP(vR,q). This means that the nearest neighbor of q in P of the sites S~R is the same as the nearest neighbor of vR in P~ of the same sites S~R.

This is where the Cone Query query data structure comes into play. This data structure allows us the answer such a nearest neighbor query for some region R with apex vR in P~. After querying the Cone Query data structure for each of the O(k) regions generated by the Dynamic Shortest Path data structure, we return the nearest neighbor of q among S~, which is the closest of these O(k) sites. Next, we define the queries for the Cone Query data structure more precisely. We refer to these queries as bounded nearest neighbor queries.

Refer to caption
Figure 2: Two bounded nearest neighbor queries: a geodesic triangle (R1) and a geodesic cone (R2).
Definition 1 (Figure 2).

A bounded nearest neighbor query (R,vR) in P~ consists of a region R and an point vRR and asks for the nearest neighbor of vR in S~R, where R is of one of the following two types:

  • a geodesic triangle: a region bounded by three shortest paths in P~, or

  • a geodesic cone: a region bounded by two shortest paths in P~ and part of P~.

The Dynamic Shortest Path data structure that finds these geodesic triangle and geodesic cone regions is based on the data structure of Goodrich and Tamassia [13] for ray shooting and shortest path queries in a dynamic planar subdivision. We augment this data structure to distinguish between “old” and “new” vertices, i.e. the vertices in P~ and in PP~. In Section 4, we discuss this data structure in more detail, and obtain the following result.

Theorem 2.

A Dynamic Shortest Path data structure maintains a dynamic simple polygon with O(log2m) update time using O(m) space such that for a query point q a set of O(k) bounded nearest neighbor queries that together find the nearest neighbor of q in P among S~ in P can be computed in O(klog2m) time.

The Cone Query data structure is the main data structure we present. We give a short overview of the data structure here, illustrated in Figure 3, and discuss the details and proofs in Section 5. The data structure is based on a balanced geodesic triangulation 𝒯, augmented with three auxiliary data structures. We call the geodesic triangulation the first level data structure, and the three auxiliary data structures the second level data structures. The second level data structures are the following. First, for each node in 𝒯, we store a partition tree [6] on the sites that lie in the corresponding deltoid. Furthermore, we store several third level data structures for each node of the partition tree. This allows us to find the nearest neighbor of vR for (a subset of) the sites contained in the deltoid. Second, for each node in 𝒯, we store the sites that lie on the boundary of the geodesic triangle in a binary search tree. This allows us the find the nearest neighbor of vR for a subset of the sites that lie on the boundary of the geodesic triangle. Third, for each edge in 𝒯, which corresponds to a shortest path between two points on P~, we store a nearest neighbor data structure that allows us to compute the nearest neighbor of vR among the sites in one of the subpolygons defined by this shortest path, provided that vR lies in the other subpolygon. We show that we can answer a bounded nearest neighbor query by querying O(logm~) of these level two data structures. This results in the following theorem.

Refer to caption
Figure 3: Overview of the Cone Query data structure. For each node in the geodesic triangulation (level 1) we store a partition tree and for each edge we store some restricted Voronoi diagram (level 2). For each node in the partition tree we store three Voronoi based data structures (level 3). Nodes of the geodesic triangulation whos deltoid is empty are omitted.
Theorem 3.

For a static polygon P~ with m~ vertices and a set S~ of n~ sites in P~, the Cone Query data structure can be constructed in O(m~loglogn~+n~logn~loglogn~+n~logn~log2m~)) time and O(n~loglogn~+n~logm~+m~) space, such that a bounded nearest neighbor query can be answered in O(n~log3/2m~+logn~log2m~) expected time.

To obtain our final result, we rebuild the Cone Query data structure once k becomes larger than n~1/4+m~1/4. This results in update and query times that are O~(n3/4+m3/4). Note that by rebuilding the Cone Query data structure earlier (or later), we can increase (or decrease) the update time and decrease (or increase) the query time, respectively.

Theorem 4.

We can build an insertion-only data structure for a dynamic simple polygon P with m vertices and a dynamic set S of n sites in P using O(n(loglogn+logm)+m) space with O(n3/4logn(loglogn+log2m)+m3/4loglogn) amortized update time that can answer nearest neighbor queries in O(n3/4log3/2m+m1/4(n1/2log3/2m+lognlog2m)) expected time.

4 Dynamic shortest path data structure

The Dynamic Shortest Path data structure is an extension of the dynamic data structure of Goodrich and Tamassia [13], discussed in Section 2. We first explain how we adapt it to support efficient access to our newly inserted vertices. Then, we show how to use the Dynamic Shortest Path data structure to generate O(k) bounded nearest neighbor queries that can together answer a nearest neighbor query, thus proving Theorem 2.

Extending the dynamic shortest path data structure.

We extend the dynamic shortest path data structure of Goodrich and Tamassia [13] so that we have efficient access to the vertices and edges that were inserted since the last rebuild. We call these marked vertices and edges. In the data structure of  [13], each polygonal chain is stored in a chain tree: a balanced binary tree where leaves correspond to the edges in the chain and internal nodes to the vertices of the chain. Each internal node also corresponds to a subchain and stores its length. We additionally store a boolean in each node that that is true whenever its subchain contains a marked edge, and false otherwise. Next to this dynamic data structure, we keep a list of all marked vertices. For this list, we consider the endpoint of an inserted edge to be marked, even if the vertex already existed in P~.

Lemma 5.

The Dynamic Shortest Path data structure maintains a dynamic simple polygon with O(log2m) update time using O(m) space.

Lemma 6.

Given two points p,qP, the Dynamic Shortest Path data structure can find the first (or last) marked vertex on π(p,q) in O(log2m) time.

Computing the bounded nearest neighbor queries.

Next, we explain how to use the Dynamic Shortest Path data structure to find for a query point qP a set of bounded nearest neighbor queries such that the nearest neighbor of q is the result of one of these queries. For each bounded nearest neighbor query we return the apex vR, the two other endpoints s,t of the shortest paths bounding R, and a boolean indicating whether R is a geodesic triangle or geodesic cone. In case R is a geodesic cone, we order s,t such that the part of P in R is given by the clockwise traversal from s to t along P. We will choose our region R in such way that the paths bounding R are shortest paths in both P and P~. In other words, there are no marked vertices (that are reflex vertices) on these shortest paths.

Lemma 7.

We can compute a set of O(k) bounded nearest neighbor queries in P~ that allows us to find the nearest neighbor of a point qP among the sites in S~ in O(klog2m) time.

Proof.

We first describe the partition of P that will result in the O(k) bounded nearest neighbor queries, and then discuss how to compute them. We partition P into O(k) maximal regions such that for every point in a region R, the path to q uses the same marked vertices, see Figure 4. This can be viewed as a shortest path map for q, where we only consider marked vertices. Each region in this map will be a bounded nearest neighbor query together with its apex, i.e. the first marked vertex on the path from any point in the region to q.

Refer to caption
Figure 4: The bounded nearest neighbor query regions that are obtained for the query point q. The green segments are the segments inserted after the last rebuild.

To find these regions, we keep track of all points on P that define the boundary between two such regions in a balanced binary tree T based on the order along P. Observe that all marked vertices define such a boundary point. We thus insert all O(k) marked vertices into T. Then, for each marked vertex v, we:

  1. 1.

    Compute the shortest path π(v,q).

  2. 2.

    Perform a ray shooting query in the direction of the last segment of π(v,q) to find the point x where the extension of this segment hits P.

  3. 3.

    Insert x into T.

The Dynamic Shortest Path data structure supports shortest path queries in O(log2m) time. We can also obtain the last segment on the shortest path using the chain trees representing the path. The ray shooting query that follows again takes O(log2m) time. Finally, inserting x into T takes just O(logk) time. As there are O(k)=O(m) marked vertices, this takes O(klog2m) time in total.

What remains is to find the bounded nearest neighbor queries using T. Each pair s,t of consecutive points in T defines such a query. If s and t are endpoints of the same marked edge, then their query region R is a geodesic triangle, otherwise R is a geodesic cone. The apex vR of the bounded nearest neighbor is the last marked vertex on π(q,s)π(q,t), or q if there is no such vertex. We distinguish the following cases:

  • If s (or t) is a marked, then vR is the first (other) marked vertex on π(s,q) (or π(t,q)).

  • If both s and t are not marked, and thus included in T in the ray shooting step, then vR is the second marked vertex on π(s,q), i.e. the first vertex after the vertex used in the ray shooting step.

Note that in both cases vR is also on π(t,q), as otherwise the ray shooting step on vR would add some point x between s and t on P to T. Lemma 6 implies that we can find vR in O(log2m) time (to find the second marked vertex we can search the corresponding chain tree from the first marked vertex in O(logm) time).

5 Static cone query nearest neighbor data structure

In this section, we present the static Cone Query data structure. Throughout this section, let P be a static simple polygon with m vertices and S a static set of n sites in P. We want our data structure to answer bounded nearest neighbor queries for a region R and a query point q on R, which in our case will be the apex point vR, as in Definition 1. We assume that the region R is given as endpoints of the (at most three) shortest paths bounding it, and in case R is a geodesic cone, an indication which part of P is in R.

The base of our data structure is a geodesic triangulation 𝒯. We construct several data structures for the nodes and edges of 𝒯. We assign each site sS to the highest node in 𝒯 whose geodesic triangle contains s. Note that there is only one node whose geodesic triangle contains s if s lies in some deltoid region, but there may be more if s is on the boundary of a geodesic triangle. For a geodesic triangle δ𝒯, we denote the set of sites assigned to δ by Sδ. For the deltoid Δ of δ, we define SΔ:=SδΔ.

As a preprocessing step, we triangulate P [8] and construct the shortest path data structure of Guibas and Hershberger [15]. We also construct a point location data structure [20] on the geodesic triangulation. Each face in this subdivision is associated with its node in 𝒯, and each edge is associated with the highest node in 𝒯 that has this edge on its boundary. The geodesic triangulation can also be used to answer ray shooting queries in O(logm) time [9].

Next, we define two fundamental queries for a node in 𝒯.

Definition 8.

Let δ be a node in 𝒯. Let (R,q) be a bounded nearest neighbor query, then we define the following subqueries.

  • Type (a): return the nearest neighbor of q in SδR.

  • Type (b): let 𝒯x be the subtree of 𝒯 rooted at a child x of δ and Px the corresponding subpolygon, i.e. Px:=y𝒯xy. For qPx, return the nearest neighbor of q in SPx.

For each node δ𝒯, we store two data structures that together can answer type (a) queries. One that finds the nearest neighbor of q among the sites on the boundary of the geodesic triangle, and one that finds the nearest neighbor of q among the sites in the deltoid region. For each edge (δ,x)𝒯 we store a data structure that can answer type (b) queries.

Next, we show that we can answer bounded nearest neighbor queries using O(logm) type (a) and (b) queries. We first state two lemmas that prove useful in finding these queries.

Lemma 9.

Let p,r be two points on P, and let sP. In O(logm) time we can test if s lies right of the shortest path π(p,r).

Lemma 10.

Let p,r be two points on P, and let s,tP. We can determine in O(log2m) time the first and last point of π(s,t)π(p,r), or conclude the paths are disjoint.

Lemma 11.

A bounded nearest neighbor query can be answered using O(logm) type (a) and (b) queries. We can determine these O(logm) queries in O(log2m) time.

Proof.

We first prove the first part of the lemma, and then show how to find these type (a) and (b) queries efficiently. Figure 5 illustrates which nodes and edges we query. Let (R,q) be a bounded nearest neighbor query. The region R is either bounded by three shortest paths, or by two shortest path and part of P. We first consider one of these shortest path that bounds R. Let π(s,t) be this shortest path, and let v(s) and v(t) be geodesic triangles in 𝒯 that contain s and t respectively. Let σ be the subset of nodes of 𝒯 on the paths from v(s) and v(t) to the root of 𝒯. Furthermore, let Pσ be the union of the geodesic triangles in σ, i.e. Pσ=δσδ. We claim that π(s,t) is contained Pσ. Indeed, consider a deltoid region Δ that is entered by π(s,t) of a geodesic triangle δσ. Let π(a,b) be the shortest path that is the boundary of δ through which π(s,t) enters Δ. Note that by definition a and b are on P. So, because π(s,t) starts and ends in Pσ, it should at some point reenter Pσ by crossing π(a,b) again. This contradicts π(s,t) being a shortest path.

Refer to caption
Figure 5: A geodesic triangulation and its dual tree. Nodes with empty deltoid regions are gray. We perform a type (a) query for all green nodes, and a type (b) query for all green edges.

Let σ be the the union of the σ sets for the shortest paths bounding R, excluding any geodesic triangles that intersect none of the shortest paths bounding R. Observe that for any point pP the subgraph of nodes in 𝒯 whose geodesic triangle contains p is connected. As each pair of shortest paths bounding R has a common endpoint, the subgraph of σ is also connected. For each δσ, we perform a type (a) query. Because 𝒯 has height O(logm), we perform O(logm) of these queries. Together, these queries find the nearest neighbor of q in R for all geodesic triangles whose intersection with one of the shortest paths bounding R is non-empty. Clearly, any node whose deltoid region is intersected by such a shortest path is in σ. Any site that is on the boundary of a geodesic triangle intersected by such a shortest path is stored in the highest node in 𝒯 that contains the site. As this subset of nodes is connected, some node in σ must contain this site.

What remains is to query the geodesic triangles that are fully contained in R. If R is a geodesic triangle, no node in 𝒯 can be contained in the interior of R, as there are no vertices of P in its interior, and the corners of the geodesic triangle are vertices of P. If R is a geodesic cone, there might be O(m) nodes in 𝒯 contained inside R that do not intersect the two bounding paths. Because R is connected, there is an edge (δ,x) in 𝒯, with δ the parent of x, whose removal splits 𝒯 into two subtrees, one of which contains exactly the geodesic triangles that are fully contained in R. If this subtree is 𝒯x (recall that 𝒯x is the subtree rooted at x), then we perform a type (b) query on (δ,x). If the subtree is 𝒯𝒯x, then for each node on the path from δ to the root, we perform a type (a) query and a type (b) query for the incident edge not on this path.

Finally, we prove the second part of the lemma. We first compute the set σ. Consider one of the shortest paths π(s,t) that bounds R. We first perform a point location query for both s and t. This gives us two nodes v(s),v(t) in 𝒯 that contain s and t. We then find the lowest common ancestor w of v(s) and v(t) in O(logm) time. All nodes on the paths from v(s) and v(t) to w are in σ. Note that the previous argument that π(s,t) cannot cross a geodesic triangle boundary and return even implies that π(s,t) is contained in the subpolygon correspoding to these nodes. However, there may be more nodes on the path from w to the root of 𝒯 whose boundary intersects π(s,t). Let π(p,r) be the shortest path that is the boundary between w and its parent geodesic triangle. Lemma 10 implies that we can find the first point a and the last point b of π(s,t)π(p,r), or conclude the paths are disjoint, in O(log2m) time. Any geodesic triangle in 𝒯 above w that intersects π(s,t) intersects either a or b (or both). It follows we can find the highest node of 𝒯 that intersects π(s,t) by a point location query on a and b, and choosing the highest node of the returned nodes. All nodes on the path in 𝒯 from w and to this node are in σ. By following the same procedure for all shortest path bounding R, we can compute σ in O(log2m) time.

If R is a geodesic triangle, we are finished. If R is instead a geodesic cone, we need to find the edge whose removal splits off the fully contained geodesic triangles as described earlier. Note that this edge must be incident to σ. Let s and t be the endpoints other than q of the shortest paths that bound R. We first find the subsequence of polygon vertices contained in R by a point location query for s and t. By storing the boundary of P in a balanced tree, we can then find the subsequence of vertices between the edges containing s and t in O(logm) time. For each node in σ, we check whether the incident edge that is not in σ is contained in R by checking whether its endpoints are contained in the subsequence in O(logm) time. We thus find the desired edge of 𝒯 in O(log2m) time. The required type (a) and (b) queries can then be found by traversing the tree as described before in O(logm) time.

5.1 Second level data structures

For each node δ𝒯, we store two data structures that together can answer type (a) queries, and for each edge (δ,x) we store a data structure that can answer type (b) queries.

Data structures for type (a) queries.

Fix a node δ𝒯 and let Δ be its deltoid. For each shortest path bounding δ, we store the sites of Sδ that are on the path in a binary search tree based on the order along the path. Together, these trees contain the sites in SδSΔ.

On the sites in SΔ we construct Chan’s partition tree [6]. Each leaf node stores a constant number of sites, and each site is stored in exactly one leaf. For each node μ in the partition tree, let S(μ) denote the sites stored in the leaves below μ and let (μ) denote the triangular cell of μ that contains S(μ). We store the following data structures for μ, see Figure 6:

  1. 1.

    The geodesic Voronoi diagram of the sites S(μ) with respect to the polygon (μ)Δ.

  2. 2.

    For each segment bounding (μ): the forest representing the Voronoi diagram of S(μ) restricted to the subpolygon bounded by P and the chord that contains the segment that does not contain S(μ).

  3. 3.

    For each shortest path π bounding δ: the forest representing the Voronoi diagram of S(μ) restricted to the subpolygon bounded by P and π that does not contain S(μ).

Refer to caption
Figure 6: The three data structures stored for the orange cell (μ) for answering type (a) queries. The first is used for a query point inside (μ)Δ, the second for a query point outside (μ), and the third for a query point that is in (μ) but outside of Δ.

The first data structure is simply the standard geodesic Voronoi diagram [22]. For the second and third data structure, we adapt a data structure that Agarwal, Arge, and Staals [1] use in their dynamic nearest neighbor data structure. They essentially prove that when a polygon is partitioned into two subpolygons P,Pr by a line segment, the forest representing the Voronoi diagram of the sites in P restricted to Pr can be stored and queried efficiently. In the full version [12], we generalize this result to the case where the polygon is partitioned using an arbitrary shortest path instead of a line segment, and obtain the following result.

Theorem 12.

Let P be a polygon with m vertices appropriately preprocessed for two-point shortest path and ray-shooting queries. Let P,Pr be a partition of P into two subpolygons by a shortest path between two points on P. Given a set of n sites S in P, there is an O(n) size data structure storing the combinatorial representation of the Voronoi diagram of S in Pr so that given a query point qPr, we can find the site in S closest to q in O(lognlogm) time. Building the data structure takes O(nlog2m+nlogn) time.

Data structure for type (b) queries.

Let δ be a node in 𝒯 and x be a child of δ. To be able to answer type (b) queries we store Voronoi diagram of the sites in SPx restricted to PPx, for Px as in Definition 8, in the forest data structure of Theorem 12, as the boundary between the two geodesic triangles is a shortest path.

5.2 Analysis

Next, we prove that the Cone Query data structure achieves the bounds in Theorem 3. We use the following lemma about multilevel data structures using Chan’s partition tree.

Lemma 13 (Corollary 6.2 of [6]).

Given n points in 2, for any fixed γ<1/2, we can form O(n) canonical subsets of total size O(nloglogn) in O(nlogn) time, such that the subset of all points inside any query triangle can be reported as a union of disjoint canonical subsets Ci with i|Ci|γO(n) in time O(n) w.h.p.(n).

Query time.

Let (R,q) be a bounded nearest neighbor query. Lemma 11 states that we can answer the query using O(logm) type (a) and (b) queries and that we can compute these queries in O(log2m) time. What remain is to analyze the time of a type (a) and (b) query.

First, consider a type (a) query. Recall that this asks for the nearest neighbor of q in SδR for a geodesic triangle δ𝒯 with deltoid Δ. To answer this query we have to query the three binary trees storing the sites in SδSΔ and the partition tree on SΔ. For a shortest path of δ, the sites on this path that are contained in R form a contiguous subsequence. We can thus obtain this subset of sites in a binary tree in O(logn) time. Because the distance from q to a shortest path is a convex function, we can then binary search in this subtree to find the site closest to q in O(lognlogm) time.

To find the closest site of q in SΔ, we query the partition tree. However, we cannot apply Lemma 13 directly, as this requires the query region to be a triangle instead of a geodesic triangle or cone. Oh and Ahn [23] essentially prove that seven triangles can cover a geodesic triangle without including any sites of SΔ outside of the geodesic triangle in their interior. Here, we need a slightly more general statement that also includes geodesic cones.

Lemma 14.

We can construct in O(log2m) time a constant number of interior disjoint triangles whose union contains ΔR but does not contain any sites in SΔR.

For each of the O(1) triangles given by Lemma 14 we query the partition tree. Lemma 13 states that the partition tree gives us a set of disjoint canonical subsets Ci. For each canonical subset, which corresponds to some node μ in the partition tree, we perform a nearest neighbor query using one of the data structures stored in the node. Which data structure we query depends on the location of q in relation to Δ and (μ), see Figure 6.

  • If q is inside both the deltoid Δ and the cell (μ), i.e. qΔ(μ), we query the geodesic Voronoi diagram of Δ(μ).

  • If q is outside the cell (μ), i.e. q(μ), we query the forest constructed for the segment of (μ) whose extension separates q from (μ).

  • If q is inside the cell (μ) but outside the deltoid Δ, i.e. q(μ) and qΔ, we query the forest constructed for side of δ that separates q from Δ.

Consider a canonical subset Ci for which the complexity of Δ restricted to the cell of Ci is mi. The first type of query, which is in the (regular) geodesic Voronoi diagram, takes O(log(|Ci|+mi)) time [22]. The second and third type of query take O(log|Ci|logm) time by Theorem 12. The query time thus becomes

i(log|Ci|logm+log(|Ci|+mi)) =logmilog|Ci|+ilog(|Ci|+mi)
logmilog|Ci|+i(log|Ci|+logmi)
=(logm+1)ilog|Ci|+ilogm.

Here we used that for |Ci|,mi2 it holds that log(|Ci|+mi)log(|Ci|mi). Choosing any γ(0,1/2) in Lemma 13 implies that ilog|Ci|=O(|SΔ|). The number of terms in the sum ilogm is bounded by O(|SΔ|) as well. A type (a) query can thus be answered in O(|SΔ|logm) time.

Finally, we note that the O(logm) type (a) queries we perform are on distinct deltoids. Thus, if we sum over all deltoids Δi that we query, we have i|SΔi|=O(n). To bound the sum of square roots over these set sizes, we use the HM-GM-AM-QM inequalities, which states that for positive reals x1,,xa, we have x1++xaa(x12++xa2). It then follows that the total query time of all type (a) queries is i=0O(logm)|SΔi|logm=O(nlog3/2m).

A type (b) query requires only a single query of the data structure of Theorem 12, and thus takes O(lognlogm) time. The total query time of the type (b) queries is O(lognlog2m).

Construction time.

As preprocessing, we build the shortest path data structure of Guibas and Hershberger in O(m) time [8, 15]. We then build the level one data structure: a balanced geodesic triangulation together with a point location data structure, in O(m) time [9].

There are three level two data structures: one for each edge of 𝒯 (for the type (b) queries), and two for each node of 𝒯 (for the type (a) queries). Let δ be a node in 𝒯 and Δ the corresponding deltoid.

First, consider the data structure on each edge of 𝒯. This is the forest data structure of Theorem 12. For a child x of δ this data structure can be build in O(|SPx|log2m+|SPx|log|SPx|) time, with Px as in Definition 8. Note that each site in S can occur in at most O(logm) polygons Px, once for each level of 𝒯. It follows that constructing the data structure for each edge of 𝒯 takes O(nlog3m+nlognlogm) time in total.

Second, consider the two data structures on the nodes of 𝒯. For each shortest path bounding δ, we store the sites on the path in a binary search tree. These trees can be constructed in O(nδ(lognδ+logm)) time. Furthermore, we store the sites in the deltoid Δ in a partition tree. The partition tree (excluding auxiliary data structures) can be build in O(nΔlognΔ) time (Lemma 13).

For each node μ of the partition tree, we store three third level Voronoi data structures for the sites S(μ). Let m(μ) be the number of vertices of (μ)Δ. The first level three data structure is a (regular) geodesic Voronoi diagram restricted to μ, including a point location data structure, and can be constructed in O(m(μ)+|S(μ)|log|S(μ)|) time [22]. The second and third data structures are the forest data structure of Theorem 12 on each segment bounding the cell of μ and each shortest path bounding δ. These can be constructed in O(|S(μ)|log2m+|S(μ)|log|S(μ)|) time (Theorem 12). The total construction time for a node μ of the partition tree is then O(m(μ)+|S(μ)|log|S(μ)|+|S(μ)|log2m). To bound the total construction time for all nodes of the partition tree, observe that the cells in each of the O(loglognΔ) levels of the partition tree are disjoint. So, μ|m(μ)|=O(mΔloglognΔ). Furthermore, μ|S(μ)|=O(nΔloglognΔ). The total construction time over all nodes is then O(mΔloglognΔ+nΔloglognΔ(lognΔ+log2m)).

Together, the level two and three data structures on a node δ𝒯 are constructed in O(mδloglognδ+nδloglognδ(lognδ+log2m)) time. This implies that the total construction time for all nodes in 𝒯 is O(mloglogn+n(lognloglogn+log2mloglogn)).

The total construction time of all first, second, and third level data structures then becomes O(mloglogn+nlognloglogn+nlog3m+nlognlog2m+nlognlogm)=O(mloglogn+nlognloglogn+nlognlog2m).

Space usage.

The space of the shortest path data structure on P is O(m). For a node δ𝒯 and Δ the corresponding deltoid, the trees for δ have size O(nδ). As for the partition tree, Lemma 13 states that the total size of the canonical subsets is O(nΔloglognΔ). The three data structures that are built for each node of the partition tree use just linear space in the number of sites, thus the total size of the partition tree including its auxiliary data structures remains O(nΔloglognΔ). The total space over all nodes in 𝒯 is thus O(nloglogn). What remains is to analyze the space of the data structures for type (b) queries. Theorem 12 states that this forest data structure for a child x of δ uses O(|SPx|) space. As before, each site in S can occur in at most O(logm) polygons Px, once for each level of 𝒯. Thus the total space of these data structures is O(nlogm).

References

  • [1] Pankaj K. Agarwal, Lars Arge, and Frank Staals. Improved dynamic geodesic nearest neighbor searching in a simple polygon. In 34th International Symposium on Computational Geometry, SoCG, volume 99 of LIPIcs, pages 4:1–4:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2018. doi:10.4230/LIPICS.SOCG.2018.4.
  • [2] Pankaj K. Agarwal and Micha Sharir. Applications of a new space-partitioning technique. Discret. Comput. Geom., 9:11–38, 1993. doi:10.1007/BF02189304.
  • [3] Boris Aronov. On the Geodesic Voronoi Diagram of Point Sites in a Simple Polygon. Algorithmica, 4(1):109–140, 1989. doi:10.1007/BF01553882.
  • [4] Jon Louis Bentley and James B Saxe. Decomposable searching problems I. Static-to-dynamic transformation. Journal of Algorithms, 1(4):301–358, 1980. doi:10.1016/0196-6774(80)90015-2.
  • [5] Timothy M. Chan. A dynamic data structure for 3-d convex hulls and 2-d nearest neighbor queries. J. ACM, 57(3):16:1–16:15, 2010. doi:10.1145/1706591.1706596.
  • [6] Timothy M. Chan. Optimal partition trees. Discret. Comput. Geom., 47(4):661–690, 2012. doi:10.1007/S00454-012-9410-Z.
  • [7] Timothy M. Chan. Dynamic geometric data structures via shallow cuttings. Discret. Comput. Geom., 64(4):1235–1252, 2020. doi:10.1007/S00454-020-00229-5.
  • [8] Bernard Chazelle. Triangulating a simple polygon in linear time. Discret. Comput. Geom., 6:485–524, 1991. doi:10.1007/BF02574703.
  • [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(1):54–68, 1994. doi:10.1007/BF01377183.
  • [10] Tameem Choudhury and R. Inkulu. Maintaining the visibility graph of a dynamic simple polygon. In 5th International Conference on Algorithms and Discrete Applied Mathematics, CALDAM, volume 11394 of Lecture Notes in Computer Science, pages 42–52. Springer, 2019. doi:10.1007/978-3-030-11509-8_4.
  • [11] Sarita de Berg and Frank Staals. Dynamic data structures for k-nearest neighbor queries. Comput. Geom., 111:101976, 2023. doi:10.1016/J.COMGEO.2022.101976.
  • [12] Sarita de Berg and Frank Staals. Nearest neighbor searching in a dynamic simple polygon, 2025. doi:10.48550/arXiv.2503.03435.
  • [13] Michael T. Goodrich and Roberto Tamassia. Dynamic ray shooting and shortest paths in planar subdivisions via balanced geodesic triangulations. J. Algorithms, 23(1):51–73, 1997. doi:10.1006/JAGM.1995.0797.
  • [14] Michael T. Goodrich and Roberto Tamassia. Dynamic trees and dynamic point location. SIAM J. Comput., 28(2):612–636, 1998. doi:10.1137/S0097539793254376.
  • [15] Leonidas J. Guibas and John Hershberger. Optimal shortest path queries in a simple polygon. J. Comput. Syst. Sci., 39(2):126–152, 1989. doi:10.1016/0022-0000(89)90041-X.
  • [16] John Hershberger and Subhash Suri. An Optimal Algorithm for Euclidean Shortest Paths in the Plane. SIAM Journal on Computing, 28(6):2215–2256, 1999. doi:10.1137/S0097539795289604.
  • [17] Mashhood Ishaque, Bettina Speckmann, and Csaba D. Tóth. Shooting permanent rays among disjoint polygons in the plane. SIAM J. Comput., 41(4):1005–1027, 2012. doi:10.1137/100804310.
  • [18] Mashhood Ishaque and Csaba D. Tóth. Relative convex hulls in semi-dynamic arrangements. Algorithmica, 68(2):448–482, 2014. doi:10.1007/S00453-012-9679-6.
  • [19] Haim Kaplan, Wolfgang Mulzer, Liam Roditty, Paul Seiferth, and Micha Sharir. Dynamic planar voronoi diagrams for general distance functions and their algorithmic applications. Discret. Comput. Geom., 64(3):838–904, 2020. doi:10.1007/S00454-020-00243-7.
  • [20] David G. Kirkpatrick. Optimal search in planar subdivisions. SIAM J. Comput., 12(1):28–35, 1983. doi:10.1137/0212002.
  • [21] Chih-Hung Liu. A nearly optimal algorithm for the geodesic voronoi diagram of points in a simple polygon. Algorithmica, 82(4):915–937, 2020. doi:10.1007/S00453-019-00624-2.
  • [22] Eunjin Oh. Optimal algorithm for geodesic nearest-point voronoi diagrams in simple polygons. In Proceedings of the 13th Annual ACM-SIAM Symposium on Discrete Algorithms, SODA, pages 391–409. SIAM, 2019. doi:10.1137/1.9781611975482.25.
  • [23] Eunjin Oh and Hee-Kap Ahn. Dynamic geodesic convex hulls in dynamic simple polygons. In 33rd International Symposium on Computational Geometry, SoCG, volume 77 of LIPIcs, pages 51:1–51:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2017. doi:10.4230/LIPIcs.SoCG.2017.51.
  • [24] Eunjin Oh and Hee-Kap Ahn. Voronoi diagrams for a moderate-sized point-set in a simple polygon. Discret. Comput. Geom., 63(2):418–454, 2020. doi:10.1007/S00454-019-00063-4.
  • [25] Mark H. Overmars. The Design of Dynamic Data Structures, volume 156 of Lecture Notes in Computer Science. Springer, 1983. doi:10.1007/BFB0014927.
  • [26] Evanthia Papadopoulou and Der-Tsai Lee. A New Approach for the Geodesic Voronoi Diagram of Points in a Simple Polygon and Other Restricted Polygonal Domains. Algorithmica, 20(4):319–352, 1998. doi:10.1007/PL00009199.