Computing the Geodesic Diameter and Center of a Simple Polygon in Linear Time
In this paper, we show that the geodesic diameter and center of a simple polygon can be computed in linear time. For the purpose, we focus on revealing basic geometric properties of the geodesic balls, that is, the metric balls with respect to the geodesic distance. More specifically, in this paper we show that any family of geodesic balls in any simple polygon has Helly number two, and the geodesic center consists of midpoints of shortest paths between diametral pairs. These properties are crucial for our linear-time algorithms, and do not hold for the Euclidean case.
Let be a simple polygon with vertices in the plane. The diameter and radius of with respect to a certain metric are very natural and important measures of . The diameter with respect to is defined to be the maximum distance over all pairs of points in , that is, , while the radius is defined to be the min-max value . Here, the polygon is considered as a closed and bounded space and thus the diameter and radius of with respect to are well defined. A pair of points in realizing the diameter is called a diametral pair. Similarly, any point such that is equal to the radius is called a center. In this paper we study how fast can we compute these measures (and whenever possible, to also obtain the set of points that realize them).
One of the most natural metrics on a simple polygon is induced by the length of the Euclidean shortest paths that stay within , namely, the (Euclidean) geodesic distance. The problem of computing the diameter and radius of a simple polygon with respect to the geodesic distance has been intensively studied in computational geometry since the early 1980s. The diameter problem was first studied by Chazelle , who gave an -time algorithm. The running time was afterwards improved to by Suri . Finally, Hershberger and Suri  presented a linear-time algorithm based on a fast matrix search technique. Recently, Bae et al.  considered the diameter problem for polygons with holes.
The first algorithm for finding the Euclidean geodesic radius was given by Asano and Toussaint . In their study, they showed that any simple polygon has a unique center, and provided an -time algorithm for computing it. The running time was afterwards reduced to by Pollack, Sharir, and Rote . Since then, it has been a longstanding open problem whether the center can be computed in linear time (as also mentioned later by Mitchell ).
Another popular metric with a different flavor is the link distance, which measures the smallest possible number of links (or turns) of piecewise linear paths. The currently best algorithms that compute the link diameter or radius run in time [20, 13, 8]. The rectilinear link distance measures the minimum number of links when feasible paths in are constrained to be rectilinear. Nilsson and Schuierer [15, 16] showed how to solve the problem under the rectilinear link distance in linear time.
In order to tackle the open problem of computing the Euclidean geodesic center, we investigate another natural metric: the metric. To the best of our knowledge, only a special case where the input polygon is rectilinear has been considered in the literature. This result is given by Schuierer , where he showed how to compute the geodesic diameter and radius of a simple rectilinear polygon in linear time.
This paper aims to provide a clear and complete exposition on the diameter and radius of general simple polygons with respect to the geodesic distance. We first focus on revealing basic geometric properties of the geodesic balls (that is, the metric balls with respect to the geodesic distance). Among other results, we show that any family of geodesic balls has Helly number two (see Theorem 11). This is a crucial property that does not hold for the Euclidean geodesic distance, and thus we identify that the main difficulty of the open problem lies there.
We then show that the method of Hershberger and Suri  for computing the Euclidean diameter extends to metrics, and that the running time is preserved. However, the algorithms for computing the Euclidean radius do not easily extend to rectilinear metrics. Indeed, even though the approach of Pollack et al.  can be adapted for the metric, the running time is . On the other hand, the algorithm of Schuierer  for rectilinear simple polygons heavily exploits properties derived from rectilinearity. Thus, its extension to general simple polygons is not straightforward either.
In this paper we use a different approach: using our Helly-type theorem for geodesic balls, we show that the set of points realizing geodesic centers coincides with the intersection of a finite number of geodesic balls. Afterwards we show how to compute their intersection in linear time. Table 1 summarizes the currently best results on computing the diameter and radius of a simple polygon with respect to the most common metrics, including our new results.
|simple||[Thm. 18]||[Thm. 24]|
For any subset , we denote by and the boundary and the interior of , respectively. For , denote by the line segment with endpoints and . For any path in , let be the length of under the metric, or simply the length. Note that equals the distance between and .
The following is a basic observation on the length of paths in . A path is called monotone if any vertical or horizontal line intersects it in at most one connected component.
For any monotone path between , it holds that .
Let be a simple polygon with vertices. We regard as a compact set in , so its boundary is contained in . An shortest path between and is a path joining and that lies in and minimizes its length. The geodesic distance is the length of an shortest path between and . We are interested in two quantities: the geodesic diameter and radius of , defined to be and . Any pair of points such that is called a diametral pair. A point is said to be an geodesic center if and only if . We denote by the set containing all geodesic centers of .
Analogously, a path lying in minimizing its Euclidean length is called the Euclidean shortest path. It is well known that there is always a unique Euclidean shortest path between any two points in a simple polygon . We let be the unique Euclidean shortest path from to . The following states a crucial relation between Euclidean and shortest paths in a simple polygon.
Fact 2 (Hershberger and Snoeyink ).
For any two points , the Euclidean shortest path is also an shortest path between and .
Notice that this does not imply coincidence between the Euclidean and the geodesic diameters or centers, as the lengths of paths are measured differently (see an example in Figure 1).
Nonetheless, Fact 2 enables us to exploit structures for Euclidean shortest paths such as the shortest path map.
A shortest path map for a source point is a subdivision of into regions according to the combinatorial structure of shortest paths from . For Euclidean shortest paths, Guibas et al.  showed that the shortest path map can be computed in time. Once we have , the Euclidean geodesic distance from to any query point can be computed in time, and the actual path in additional time proportional to the complexity of . Fact 2 implies that the map also plays a role as a shortest path map for the geodesic distance so that a query can be processed in the same time bound to evaluate the geodesic distance or to obtain the shortest path .
Throughout the paper, unless otherwise stated, refers to a simple polygon, a shortest path and the geodesic distance always refer to an shortest path and the geodesic distance , and the geodesic diameter/center is always assumed to be with respect to the geodesic distance .
3 The Geodesic Balls
Geodesic balls (or geodesic disks) are metric balls under the geodesic distance . More precisely, the (closed) geodesic ball centered at point with radius , denoted by , is the set of points such that . Note that if , it holds that . In this section, we reveal several geometric properties of the geodesic balls , which build a basis for our further discussion.
3.1 -convex sets
A subset is -convex if for any , the Euclidean shortest path is a subset of . The -convex sets are also known as the geodesically convex sets in the literature . Pollack et al.  achieved their -time algorithm computing the Euclidean geodesic center based on the -convexity of Euclidean geodesic balls. A set is path-connected if and only if, for any , there exists a path connecting them such that . With this definition we can introduce an equivalent condition of -convexity.
For any subset of , the following are equivalent.
is path-connected and for any line segment , is connected.
(i) (ii). Assume that is -convex. By definition, any two points are joined by the Euclidean shortest path which lies in , that is, should be path-connected. Now, suppose that there exists a line segment such that consists of two or more connected components. Then, there are two points such that the segment is not completely contained in . Since , we have . This contradicts the -convexity of .
(ii) (i). Assume that is path-connected and any line segment intersects in a connected subset. For a contradiction, suppose that there exist such that . Recall that is a sequence of line segments whose endpoints are either vertices of , , or . In particular, there exists a vertex of that is in but not in . Let be the first such vertex, and let be the vertex of just before (note that is either or a corner of ). By construction, and are adjacent through a segment of and is farther from than . By our choice of , we must have (see Figure 2 for an illustration).
Let be the first point on hit by the ray starting at in the direction opposite to . Since is a diagonal of (that is, and ), is partitioned by into two simple polygons. Let be the sub-polygon containing ; we claim that must be in the other one (which we call ). Observe that properly crosses at . Indeed, if , the path must properly cross again the segment . However, in such a case we can find a shorter path that avoids the segment altogether, a contradiction. Thus, we conclude that and .
Since is path-connected, there exists a path between and such that . Since is a simple polygon, the path must cross , and thus . Now, consider the segment . As observed above, we have , , and . In particular, is not connected, a contradiction. ∎
We are interested in the boundary of a -convex set. Let be a -convex set. Consider any convex subset . Since for any , the intersection is also a convex set due to the -convexity of . Based on this observation, we show the following lemma.
Let be a closed -convex set. Then, any connected component of is a convex curve.
Consider an arbitrary triangulation of the simple polygon . We call each edge in a diagonal if it is not an edge of . For each triangle , is a convex set since is -convex and is convex. Therefore, is convex, implying that every (maximal) continuous portion of is a convex curve (note that may have more than one continuous portion). Now, consider any connected component of . The diagonals of subdivides into some pieces, each of which is a convex curve, as discussed above. Since the vertices of each triangle in are those of , does not pass through any vertex of any triangle by definition. This implies that is a simple curve, being either open or closed.
In order to show that is a convex curve, it suffices to check each intersection point between and a triangle diagonal . If such a point does not exist, then does not intersect any diagonal, and we are done. Otherwise, the diagonal is incident to two triangles and of . Let be the continuous portion of that connects and let be the continuous portion of that connects . According to our discussion above, both and are nonempty convex curves. Let be a sufficiently small disk centered at such that is part of the boundary of . By the -convexity of , must also be a convex set, and therefore, , as a part of , is a convex curve. This also shows that is convex. Since there are only a finite number of such intersection points , repeating this argument for each such proves that is a convex curve. ∎
Note that if a connected component of is not a closed curve, then is an open curve excluding its endpoints, which lie on . This implies that the curve divides into two connected components such that lies on one side of , regardless of whether is open or closed.
3.2 Geometric properties of geodesic balls
In the following, we establish several geometric properties of geodesic balls that follow from the -convexity of . Note that, to the best of our knowledge, most of these properties of have not been discussed before in the literature.
We start with a simple observation. By Fact 2, is an shortest path from to . Since makes turns only at vertices of , the ball is equal to the union of some balls centered at the vertices of . More precisely, , where denotes the set of vertices of . This immediately implies the following observation.
For any and , the geodesic ball is a simple polygon in and each side of either lies on or has slope or .
Given a point and a horizontal or vertical line segment , the function over is convex.
Without loss of generality, we assume that is horizontal. The case where is vertical can be handled in a symmetric way. Consider the union of all Euclidean shortest paths from to over , which forms a funnel with apex and base plus . The funnel consists of two concave chains and through vertices of and the endpoints of so that connects the apex and the left endpoint of and connects and the right endpoint of . See Figure 3. Note that the apex is also a vertex of unless .
Each of the two concave chains and is either monotone or not. Recall that a path is called monotone if and only if any vertical or horizontal line intersects it at most once. Observe that at least one of them must be monotone, since the apex must be visible to a point of . Without loss of generality, we assume that is monotone. Let and be the left and right endpoints of , respectively. For any point , let denote its -coordinate. We define a particular vertex of defined as follows: (1) if both chains are monotone and (see Figure 3 (i)); (2) if both chains are monotone and (see Figure 3 (ii)); (3) if both chains are monotone and (symmetric to Figure 3 (ii)); (4) is the rightmost vertex of if is not monotone (see Figure 3 (iii)).
Note that, by construction of , it always holds that . Let be the point of that has the same -coordinate as . We first prove that is visible to . In case (1) both chains and are monotone and is horizontal. Thus, the segment connecting and cannot be obstructed. In cases (2) and (3) we have (and thus the statement is obviously true). For case (4) the vertex cuts into two monotone concave chains. Since is horizontal and is visible to at least one point of , must be visible to .
We claim that for any there exists a shortest path to that passes through . Consider the path formed by concatenating the (horizontal) segment , the (vertical) segment and the shortest path from to . Recall that we considered four different types of funnels. In most of these cases, the resulting path is monotone (and thus it is a shortest path by Fact 1). The only situation in which the resulting path is not monotone is if the funnel is in case (4), and is to the left of . However, in this situation we know that always passes through .
That is, for any there exists a shortest path to that passes through (and thus to as well, since all shortest paths from points of pass through ). In particular, we have which is a convex function over as claimed.
We are ready to prove the -convexity of any geodesic ball.
For any point and any real , the geodesic ball is -convex.
The case where is trivial, so assume . Suppose that is not -convex. Since is a simple polygon (Observation 5), any line segment in intersects in finitely many connected components. Thus, by Lemma 3, there exists a line segment such that crosses exactly twice. Let be the two intersection points such that lies in .
We then observe that and belong to a common connected component of . Suppose for a contradiction that and belong to different components and , respectively. See Figure 4(a). Since is path-connected and closed, there exists a path between and such that . Consider the simple closed curve , and is contained in . Since and , separates the two endpoints of , that is, an endpoint of (which is on ) lies in the region bounded by . However, this is impossible since is simple, a contradiction. Hence, both and lie in a common connected component of .
By Observation 5, is a polygonal curve consisting of line segments with slope or . Since and is not contained in , has a reflex corner incident to two line segments whose slopes are and , respectively. See Figure 4(b) for an illustration. Then, we can find a horizontal or vertical line segment sufficiently close to such that and consists of two connected components. Take any point . Since but , we have a strict inequality and , a contradiction to Lemma 6. ∎
For and , each connected component of is a convex polygonal curve consisting of line segments of slope or .
For any point and any , the geodesic ball intersects any line segment in in a connected subset.
A real-valued function is called quasiconvex if its sublevel set for any is convex. Corollary 9 implies the following.
Given a point and a line segment , the function over is quasiconvex.
For any , is connected by Corollary 9, and is therefore convex. It suffices to observe that coincides with the sublevel set of over at ; that is, . ∎
Indeed, the geodesic distance function over is not only quasiconvex but convex; this can be shown by a more careful geometric analysis. Nonetheless, the quasiconvexity will be sufficient for our overall purpose.
3.3 Helly-type theorem for geodesic balls
Here, we discuss the intersection of a family of geodesic balls, and show that the geodesic balls have Helly number two. More precisely, we claim the following theorem.
Let be a family of closed geodesic balls. If the intersection of every two members of is nonempty, then .
Theorem 12 (Breen ).
Let be a family of simple polygons in the plane. If every three (not necessarily distinct) members of have a simply connected union and every two members of have a nonempty intersection, then .
Thus, it suffices to show that the union of two or three balls is simply connected, provided that any two of them have a nonempty intersection. This can be done based on the above discussion on the geodesic balls with Lemma 4 and Corollary 8.
Let be any three closed geodesic balls such that every two of them have a nonempty intersection. Then, the union is simply connected.
Since every pair of balls have nonempty intersection, the union is connected. Assume to the contrary that the union has a hole . This hole is a simple polygon whose boundary consists of portions of and for . We consider each of the connected components of and that appear on .
We claim that, for any , only a single connected component of can appear on . Assume otherwise that there are two components, say and , that satisfy . By definition of connected component, partitions into two components. Since appears on , lies in one side of and in the other side . Analogously, lies in one side of and in the other side of . Pick any two points and . Since is a simple polygon (and thus connected), there exists a path between and that stays inside (and in particular avoids ). On the other hand, since is an geodesic ball, there exists a path between and that stays inside . Now consider the loop constructed by merging the two paths and . By construction, an endpoint of must be contained in the region bounded by , which is a contradiction since the endpoints of by definition must belong to .
By a similar reasoning we claim that cannot contain any portion of (or equivalently ). Indeed, assume for the sake of contradiction that there exists a point . Consider a sufficiently small neighborhood around : partitions this neighborhood into two components, one of which must be contained in . Recall that by hypothesis we have , and in particular the other component of the neighborhood must be contained in . However, both regions are subsets of and as such they must both lie in the same side, a contradiction.
Thus, the boundary of is formed by portions of at most one connected component of each ball. Recall that, by Corollary 8, each connected component is a convex polygonal curve consisting of line segments of slope or . In particular, also consists of line segments of slope and thus must contain at least four line segments. Pick any point and shoot four rays of slope until they hit a point of . Since each connected component is convex, we conclude that each ray must hit a different component. In particular, must be formed by at least four connected components, a contradiction.
Therefore, Theorem 11 follows directly from Theorem 12 and Lemma 13. We note that Theorem 11 does not hold for the Euclidean case. It is easy to construct three disks (Euclidean balls) such that every two of them intersect but the intersection of the three is empty. This implies that the Helly number of Euclidean geodesic balls is strictly larger than two.
4 The Geodesic Diameter
In this section, we show that the geodesic diameter of , , and a diametral pair can be computed in linear time by extending the approach of Suri  and Hershberger and Suri  to the case. For any point , let be the maximum geodesic distance from to any other point in , that is, . A point such that is called a farthest neighbor of . Obviously, and . The following lemma is a key observation for our purpose.
For any , all farthest neighbors of lie on the boundary of , and at least one of them is a vertex of .
We first show that any farthest neighbor of must lie on the boundary of . Assume to the contrary that a point is a farthest neighbor of . Consider the Euclidean shortest path from to . By Fact 2, . Let be the point on hit by the extension of the last segment of . Observe that the Euclidean shortest path from to is obtained by concatenating and the segment . Since , we have a strict inequality , a contradiction to the assumption that is a farthest neighbor of . Therefore, there is no such farthest neighbor lying in the interior of . This proves the first statement of the lemma.
Let be a farthest neighbor of . Then, lies on as shown above. Let be the edge of on which lies. Corollary 10 implies that the geodesic distance over is quasiconvex and thus it is maximized when is an endpoint of , that is, a vertex of . Thus, the lemma is shown. ∎
There exist two vertices and of such that , that is, is a diametral pair.
Thus, the problem of computing is solved by finding the farthest vertex-pair. Let be the vertices of ordered counterclockwise along . Let and be vertices of such that is a farthest neighbor of and is a farthest neighbor of . The existence of and is guaranteed by Lemma 14. We assume that ; otherwise, we take the mirror image of for the following discussion. The three vertices divide into three chains: , , and . Let be the chains complementary to , respectively, that is, , , and . We then observe the following, which we prove with Lemma 14.
For any and , there is a vertex that is a farthest neighbor of .
We note that an almost identical statement (Lemma 8 in ) was given by Suri for the Euclidean geodesic distance. In the following we give the details for completeness. Also note that it suffices to give the proof for only, since the other cases are analogous.
Let : by Lemma 14 there exists a vertex of that is a farthest neighbor of . If , we are done, hence from now on we focus in the case. Walk along the boundary of in counterclockwise fashion and consider the order in which we meet points , , , and : the order is either or . In the former case, the paths and must cross (since and lie on different sides of the path ). In particular, by the triangular inequality we have . Recall that is a farthest neighbor of , hence , and in particular . Thus, we conclude that is also a farthest neighbor of as claimed. The case in which the order is is analogous (but in this case we find that is a farthest neighbor of ).
Lemma 16 implies that computing a farthest vertex from every vertex of can be done by handling three pairs of two disjoint chains that partition the vertices of . We recall that a very similar strategy was used by Suri was also used for computing the Euclidean geodesic diameter [21, 11]. This motivates the restricted farthest neighbor problem: Given two disjoint chains of vertices of , and that together partition the vertices of , where the vertices are ordered counterclockwise and , find a farthest vertex on from each . With respect to the Euclidean geodesic distance, Suri  presented an -time algorithm for the problem, and later Hershberger and Suri  improved it to time based on the matrix searching technique by Aggarwal et al. . In the following, we show with Fact 2 that the method of Hershberger and Suri  can be applied to solve the problem with respect to the geodesic distance .
Let and be two disjoint chains of vertices of that together partition the vertices of . One can compute in time a farthest vertex over for every with respect to the geodesic distance .
Define to be a matrix such that for and . We claim that implies for any and . that is, is totally monotone . Thus, the problem is to find the row-wise maxima in the totally monotone matrix .
Indeed, the above claim follows from the fact that the counterclockwise order of the four vertices must be , , , and . In particular, the paths and must cross, and thus the triangular inequality implies . This implies that we cannot have both and or we would have a contradiction. Note that this proof only uses the triangular inequality (for geodesic paths), hence it holds for other metrics as well. Indeed, this fact was previously shown by Hershberger and Suri  for the Euclidean case.
Aggarwal et al.  proved that the row-wise maxima of a totally monotone matrix can be computed in comparisons and evaluations of matrix entries. The matrix is implicitly defined and each entry will be evaluated only when needed. Hershberger and Suri  showed that evaluations of can be done in total time. The main structures used in their algorithm are the two shortest path trees and rooted at the vertices and , respectively, and the funnel structures. The shortest path tree rooted at a point is a plane tree on the vertices of plus the root such that the path in from to any vertex of is actually the Euclidean shortest path . It is known that the shortest path tree can be computed in linear time .
Fact 2 implies that these structures can also be used for the geodesic distance and the corresponding operations on them can be performed in the same time bound without modifying the structures, but by replacing the Euclidean geodesic distance by the geodesic distance . For example, we can use exactly the same data structures as in  for computing tangents on funnels. Therefore, the algorithm of Hershberger and Suri applies to the case, and solves the restricted farthest neighbor problem in linear time. ∎
We are now ready to conclude this section with a linear-time algorithm. We first find and such that is a farthest neighbor of and is a farthest neighbor of . This can be done in time by computing the shortest path maps and then with the algorithm of Guibas et al.  and Fact 2. We then have the three chains and their complements . Next, we apply Lemma 17 to solve the three instances for of the restricted farthest neighbor problem, resulting in a farthest neighbor of each vertex of by Lemma 16. Corollary 15 guarantees that the maximum over the pairs of vertices is a diametral pair of . All the effort in the above algorithm is bounded by time. We finally conclude with the main result of this section.
The geodesic diameter of a simple polygon with vertices can be computed in time, along with a pair of vertices that is diametral.
5 The Geodesic Center
In this section, we study the geodesic radius and center of a simple polygon , and present a simple algorithm that computes in linear time.
Consider the geodesic balls centered at all points with radius , and imagine their intersection as grows continuously. By definition, the first nonempty intersection happens when . Equivalently, by Theorem 11, is the smallest radius such that for any .
For any simple polygon , it holds that .
Before giving the proof, we note that Schuierer  claimed Lemma 19 but no proof was given. In this paper, we provide a proof based on the Helly-type theorem for geodesic balls (Theorem 11). It is worth mentioning that Theorem 12 was also used to prove a similar relation between the diameter and center with respect to the rectilinear link distance .
By the triangle inequality we have . Thus, it suffices to show the reverse direction. For any , let be the family of geodesic balls with radius . Also, let be their intersection. As discussed above, for and for . Theorem 11, together with the the above discussion, tells us that any two members of have a nonempty intersection only when . This implies that for any there are two points such that .
Clearly for any diametral pair . Since the intersection of these two balls can only be a segment, we obtain the following description of .
The geodesic center forms a line segment of slope , unless it degenerates to a point.
Before explicitly computing , we need a technical lemma.
Let be any two points with . Then, for any , it holds that .
Obviously, we have . In the following, we show the opposite inclusion, . The statement is obviously true when . Thus, from now on we assume that the intersection is nonempty. Pick any point . Then, we have and . Consider the function over all points on the segment . The function is quasiconvex by Corollary 10, and thus for any , . This implies that for any , so we conclude that . ∎
5.1 Computing the center in linear time
Now, we describe our algorithm for computing in linear time. We start by computing the diameter and a diametral pair of vertices in time by Theorem 18. Then, we know that by Lemma 19. Compute the intersection of the two geodesic balls and , which is a line segment of slope or (including the degenerate case in which it is a single point). Extend this line segment to a diagonal , where . Clearly, we have , but for simplicity in the exposition we will search for the possible centres of within .
This preprocessing can be done in linear time: first, we must compute the balls and by computing the shortest path maps and and traversing the cells of the maps. The intersection can be found by a local search at the midpoint of since it is guaranteed that is a line segment by Corollary 8.
Since and , we conclude that . The last task is thus to identify from . Here, we present a simple method based on further geometric observations. Recall that for any and any line segment , the geodesic distance function over is quasiconvex as stated in Corollary 10. A more careful analysis based on Fact 1 gives us the following.
Given a point and a line segment with slope or , let be the geodesic distance from to over . Then, there are two points with such that we have