Linking disjoint segments into a simple polygon is hard
Abstract
Deciding whether a family of disjoint line segments in the plane can be linked into a simple polygon (or a simple polygonal chain) by adding segments between their endpoints is NP-hard.
1 Introduction
Given a family of closed line segments in the plane, Simple Circuit (respectively, Simple Path) is the problem of deciding whether these segments can be linked into a simple polygon (respectively, a simple polygonal chain) by adding segments between their endpoints.
Rappaport [4] proved that Simple Circuit is NP-hard if the segments in are allowed to intersect at their common endpoints, and asked whether the problem remains NP-hard when the segments are disjoint. Later, Bose, Houle, and Toussaint [3] asked whether the related problem Simple Path is NP-hard when the segments in are disjoint. More recently, Tóth [6] asked about the complexity of Simple Path again, with a special interest in the case when the segments in are both disjoint and axis-parallel.
In this note, we prove the following theorem:
Theorem 1.
Simple Circuit and Simple Path are both NP-hard even if the segments in are disjoint and have only four distinct orientations.
We prove the theorem in two steps. First, we modify the construction in Rappaport’s proof of NP-hardness of Simple Circuit on not necessarily disjoint segments [4] to show that the problem remains NP-hard on disjoint segments. Next, we modify the construction further to prove that Simple Path is also NP-hard on disjoint segments. In the following, we briefly review Rappaport’s proof, which is based on a polynomial reduction from the NP-hard problem Hamiltonian Path in planar cubic graphs.
For any family of closed segments in the plane, denote by the set of endpoints of the segments in . For any two endpoints and in , we call the open segment a visibility edge if it does not intersect any closed segment in .
Given a planar cubic graph with vertices, the reduction [4] first obtains a rectilinear planar layout of the planar graph using an algorithm of Rosenstiehl and Tarjan [5], then constructs a family of segments following the rectilinear planar layout, such that admits a Hamiltonian path if and only if can be linked into a simple polygon by adding visibility edges between points in . The segments in are axis-parallel and interior-disjoint, but may intersect at common endpoints. Each endpoint in is incident to at most one horizontal segment and at most one vertical segment in . Since the rectilinear planar layout is of width at most and of height at most [5], all coordinates of endpoints in are integers of magnitude ; indeed a closer look at the construction [4, Figure 8] shows that . The reduction is hence strongly polynomial. Consequently, Simple Circuit is strongly NP-hard, on not necessarily disjoint segments.
2 Modification for Simple Circuit
To show that Simple Circuit remains strongly NP-hard on disjoint segments, we will transform the family of interior-disjoint axis-parallel segments, which Rappaport constructed, into a family of disjoint segments with four distinct orientations, in polynomial time, such that can be linked into a simple polygon if and only if can be linked into a simple polygon. This transformation can be viewed as a reduction from Simple Circuit on one type of input to the same problem on another type of input.

To obtain from , we first scale the integer coordinates of all segment endpoints by a factor of , then locally modify each intersection between a horizontal segment and a vertical segment into a gadget. The gadgets come in four variants, one for each possible orientation of an intersection; see Figure 1. For a global picture of these modifications on a rectilinear simple polygon with intersections of all four different orientations, refer to Figure 2.



By symmetry, it suffices to describe in detail only one variant of the gadget. Refer to Figure 3. For the intersection between a horizontal segment and a vertical segment , where is the left endpoint of and the lower endpoint of , the corresponding gadget is constructed as follows. First, separate the two segments and into two disjoint segments and , by splitting their common endpoint , then moving one to and the other to . Next, add five disjoint segments , , , , and . Finally, extend the segment to a slightly longer segment by moving its lower endpoint down for a distance of , from to .
In the presence of , we say that two points and can see each other if the open segment is disjoint from all closed segments in , and we say that two segments and in can see each other if at least one of the four pairs of endpoints, one of and one of , can see each other. The gadgets we constructed have the following property of mutual invisibility:
Lemma 1.
The four segments , , , and in each gadget cannot see any segments in other gadgets. Moreover, in each gadget, can only see and , can only see and , cannot see and can see only at , and can see only at .

Proof.
Clearly none of the eight endpoints of in any gadget can see any endpoint outside the gadget. After extending to by moving its lower endpoint from to , the endpoint may see outside the gadget only through the gap between and . Refer to Figure 4.
We next show that still cannot see any integer endpoints from other gadgets. Note that , , and . Thus
Consider the ray that starts from and goes through . Rotate this ray clockwise about for a positive angle till it goes through another integer point in . The area of the triangle is at least since all three endpoints have integer coordinates. Recall that the endpoints of all segments in are in the range , and is scaled by a factor of by the transformation from to . Thus we have for . Also note that . Thus
(1) |
Therefore we have . Since the three points , , and are collinear, this inequality implies that the line through and splits the angle . Thus the cone with the angle does not contain in its interior any integer endpoints in . Thus cannot see any integer endpoints from other gadgets.
Moreover, no two endpoints from two different gadgets can see each other, because the narrow ranges of slopes of viewing lines through , as illustrated by the dotted lines in Figure 1, are disjoint for intersections of different orientations.
The remaining claims of the lemma are easy to verify. ∎
The following lemma shows that our local transformation preserves linkability:
Lemma 2.
can be linked into a simple polygon if and only if can be linked into a simple polygon.
Proof.
We first prove the direct implication. Suppose that can be linked into a simple polygon. For each visibility edge of this polygon between two endpoints in , we add a visibility edge between the corresponding endpoints in . For each endpoint incident to two segments and in , we link the segments in the corresponding gadget in following the alternating path as illustrated in Figure 3 right. Then is also linked into a simple polygon.
We next prove the reverse implication. Suppose that can be linked into a simple polygon. Recall Lemma 1. In any gadget, can only see and , and can only see and . Thus must be linked to both and , which are linked to and , respectively. This chain can extend further only to and , respectively, since cannot see . Thus the seven segments in each gadget must be linked consecutively in the simple polygon along the sequence . Then, following the other visibility edges of the simple polygon through , which are outside and between the gadgets, can be linked into a simple polygon too. ∎
Recall that the coordinates of endpoints in are integers of magnitude . After the transformation, all endpoints in except have integer coordinates too. We can scale all coordinates by another factor of , so that all endpoints in including have integer coordinates of magnitude , and the reduction remains strongly polynomial. Thus Simple Circuit is strongly NP-hard, even if the input segments are disjoint and have only four distinct orientations.
3 Modification for Simple Path
To prove that Simple Path is also NP-hard, we use almost the same transformation from to as before, except two changes:
-
1.
Increase the initial scaling factor from to , and correspondingly decrease the distance between and from to when constructing the gadgets.
- 2.
The purpose of the first change is to make room for additional segments in the extended gadget. Updating the scaling factor and the distance together ensures that (1) still holds, and hence Lemma 1 remains valid. Clearly, the reduction remains strongly polynomial.


We have the following lemma analogous to Lemma 2:
Lemma 3.
can be linked into a simple polygon if and only if can be linked into a simple polygonal chain.
Proof.
We first prove the direct implication. Suppose that can be linked into a simple polygon. We link the segments in as before, except that in the extended gadget we link the segments as illustrated in Figure 5 right. Then is linked into a simple polygonal chain starting and ending in the extended gadget.
We next prove the reverse implication. Suppose that can be linked into a simple polygonal chain. In the extended gadget, can only see and , can only see and , and moreover for , can only see , , and . Since and together can be linked to at most four other segments in the polygonal chain, and since the polygonal chain has only two vertices of degree one, it follows that among the six segments , , each of and must be linked to two distinct segments, and the polygonal chain must start and end at the other two segments. Thus the segments , and the two segments , are all linked locally to each other in the extended gadget, and they are then linked to and , respectively, at and . As before, in each gadget other than this extended gadget, the seven segments must be linked consecutively along the sequence . Then, following the other visibility edges of the simple polygonal chain through , which are outside and between the gadgets, can be linked into a simple polygon. ∎
Thus Simple Path is also NP-hard. This completes the proof of Theorem 1.
Postscript
In SoCG 2019, Akitaya et al. [1, 2] presented a proof of the NP-hardness of Simple Circuit using a gadget very similar to ours. We thank Adrian Dumitrescu for bringing it to our attention.
Compare [1, Figure 13] and [2, Figure 19] with our Figure 3. Note in particular that their and correspond to our and , their and correspond to our and , and their properties (i) and (ii) correspond to our Lemma 1. The main idea behind the internal connections of their gadget is the same as ours. However, to ensure property (ii), they use a more complicated method to custom-make each gadget individually [2, Figure 20]. Our construction handles all gadgets uniformly by the small distance , the narrow viewing angle in Figure 4, and the disjoint ranges of slopes for the dotted lines in Figure 1.
To the best of our knowledge, our result on the NP-hardness of Simple Path is new.
References
- [1] H. A. Akitaya, M. Korman, M. Rudoy, D. L. Souvaine, C. D. Tóth. Circumscribing polygons and polygonizations for disjoint line segments. Proceedings of the 35th International Symposium on Computational Geometry, 9:1–9:17, 2019.
- [2] H. A. Akitaya, M. Korman, M. Rudoy, D. L. Souvaine, C. D. Tóth. Circumscribing polygons and polygonizations for disjoint line segments. arXiv:1903.07019, 2019.
- [3] P. Bose, M. E. Houle, and G. T. Toussaint. Every set of disjoint line segments admits a binary tree. Discrete and Computational Geometry, 26:387–410, 2001.
- [4] D. Rappaport. Computing simple circuits from a set of line segments is NP-complete. SIAM Journal on Computing, 18:1128–1139, 1989.
- [5] P. Rosenstiehl and R. E. Tarjan. Rectilinear planar layouts and bipolar orientations of planar graphs. Discrete and Computational Geometry, 1:343-353, 1986.
- [6] C. D. Tóth. Alternating paths along axis-parallel segments. Graphs and Combinatorics, 22:527–543, 2006.