Browse Subject Areas
?

Click through the PLOS taxonomy to find articles in your field.

# Generation of simple polygons from ordered points using an iterative insertion algorithm

• Hongyun Zhang ,

Contributed equally to this work with: Hongyun Zhang, Quanhua Zhao, Yu Li

Roles Methodology

Affiliation Institute for Remote Sensing Science and Application, School of Geomatics, Liaoning Technical University, Fuxin, Liaoning, China

• Quanhua Zhao ,

Contributed equally to this work with: Hongyun Zhang, Quanhua Zhao, Yu Li

Roles Methodology

zqhlby@163.com

Affiliation Institute for Remote Sensing Science and Application, School of Geomatics, Liaoning Technical University, Fuxin, Liaoning, China

• Yu Li

Contributed equally to this work with: Hongyun Zhang, Quanhua Zhao, Yu Li

Roles Methodology

Affiliation Institute for Remote Sensing Science and Application, School of Geomatics, Liaoning Technical University, Fuxin, Liaoning, China

## Abstract

To construct a simple polygon from a set of plane points, we propose an iterative inserting ordered points (IIOP) algorithm. Using a given a set of ordered non-collinear points, a simple polygon can be formed and its shape is dependent on the sorting method used. To form such simple polygons with a given set of plane points, the points must first be ordered in one direction (typically, the x-axis is used). The first three points in the set are used to form an initial polygon. Based on the formed polygon, new polygons can be iteratively formed by inserting the first point of from among the remaining set of points, depending on line visibility from that point. This process is carried out until all the points are inserted into the polygon. In this study, we generated 20, 50, and 80 plane points and used the proposed method to construct polygons. Experimental results show that these three polygons are all simple polygons. Through theoretical and experimental verification, we can concluded that when given a set of non-collinear points, a simple polygon can be formed.

## Introduction

Constructing a simple polygon from a set of plane points is an important process in computational geometry [1] as simple polygons are widely used in computer graphics, image processing, entity construction, and other fields [24]. However, the fundamental problem of constructing simple polygons from a set of discrete points is still under investigation.

Currently, several methods are being used to construct a simple polygons from a set of discrete points, such as the polar coordinate sorting [5], dichotomy sorting [6], convex-hull construction [7], and visual region [8] methods. In the dichotomy sorting method [5], two outer points are determined from the maximum and minimum values of x-axis (or y-axis) projection. The line connecting the two points can divide the set of points into two subsets. The points in these two subsets are sorted according to the value of x-axis (or y-axis) projection and sequentially connected to form a polygon. In the polar coordinate sorting method [6], a point is randomly selected from a given set as the origin of the polar coordinate system. Afterward, the angles of all the vectors formed by the origin and other points are calculated, and all the points are ordered according to the included angles. The sorted points are then sequentially connected to form a polygon. In the convex-hull construction method [7], a convex hull is first constructed from a given set of points. Here, iteration is started with the convex hull as the initial polygon. In each iteration, a point is randomly selected from the remaining set of points and inserted into the original polygon to form a new polygon. Finally, in the triangle-based construction method [8], an initial triangle is constructed from three randomly selected points and is considered as the initial polygon. The iterative process entails the gradual insertion of the remaining points in the polygon. Although the methods listed above have yielded good experimental results in the process of polygon construction some problems remain. For instance, during polygon construction, invalid points may be encountered. Additionally, it is impossible to prove that a simple polygon can be formed using a given set of discrete points. To solve these problems, in this study, we developed an iterative inserting ordered points (IIOP) algorithm and verified its feasibility of this algorithm theoretically and experimentally. We demonstrate that a simple polygon can be formed using a set of discrete points in which all the points are considered as polygon nodes.

The rest of this article is organized as follows. After defining some functions used in the polygon construction algorithm in the next section, we describe the process of polygon construction and theoretically demonstrate its feasibility. Later, we shall discuss several experimental results and finally present our main conclusions.

## Preliminary definitions

### Simple polygon

Consider a set of n points. These points can act as the nodes of a polygon G, if G satisfies the following conditions.

1. A node connects only two lines.
2. Arbitrary non-adjacent lines do not intersect with each other.
3. There is no loop in the closed geometry.

Under such conditions, G can be defined as a simple polygon [9].

Fig 1 show a polygon G with a set of 7 nodes: this node set can be denoted as v = {v1, v2, v3, v4, v5, v6, v7}. In Fig 1(A)–1(D), each polygon has a different geometry and the polygons in Fig 1(A)–1(C) are not simple. In Fig 1(A), point v4 connects four lines (v1v4, v3v4, v4v6, and v4v7) and hence does not satisfy Condition 1. In Fig 1(B), lines v1v6 and v4v5 intersect, thus nullifying Condition 2. Meanwhile, Fig 1(C) does not satisfy Condition 3. However, because the polygon in Fig 1(D) satisfies all the conditions listed above, it can be classified as a simple polygon.

### Visibility of a polygon line from a point

Given a polygon and a point outside of the polygon, if a node of the polygon is visible from the point, then a line formed between the node and point does not cross any other polygon line. If and only if a polygon line is visible for the point, the two endpoints of this line are visible for the point [1012].

Fig 2 shows a polygon Gv1v2v3) and a point vi outside it. When the point vi and node v2 are connected we can see that the new line viv2 does not intersect with any other line of the polygon G and similar is the case with line viv3. Thus, we can infer that line v2v3 is visible from point vi. When point vi is connected with node v1, the new line viv1 intersects with line v2v3. Therefore, lines v1v2 and v1v3 are invisible from point vi.

### Line-to-line occlusion at a given point

Assume that there are two lines (v1v2 and v3v4) and one point (vi). The two lines do not intersect (or only intersect at the endpoints). With respect to point vi, line v1v2 occludes line v3v4 if and only if the following conditions are satisfied.

1. There is a ray t starting at point vi and it intersects with both lines v1v2 and v3v4, at different points.
2. If the intersections of ray t with lines v1v2 and v3v4 are si and sj (i ≠ j), respectively, then d(vi, si) < d(vi, sj) [1314].

Fig 3(A) shows two disjoint lines v1v2 and v3v4. A ray t starts at point vi and intersects with lines v1v2 and v3v4 at points si and sj, respectively, and thus, it satisfies Condition 1. Additionally, we can see that d(vi, si)<d(vi, sj), which satisfies Condition 2; hence, it can be inferred that line v1v2 occludes v3v4 at point vi. Fig 3(B) shows two lines with intersecting endpoints: here, points v2 and v4 represent the same point. Moreover, ray t intersects lines v1v2 and v3v4 at points si and sj (i ≠ j), respectively, and d(vi, si) < d(vi, sj). Therefore, line v1v2 occludes v3v4 at point vi. Fig 3(C) shows two disjoint lines v1v2 and v3v4. There is no ray starting at point vi that can intersect lines v1v2 and v3v4 simultaneously. Hence, it does not satisfy Condition 1 and there is no occlusion. Fig 3(D) shows two lines with intersecting endpoints. Although there is a ray starting at point vi that can simultaneously intersect lines v1v2 and v3v4, intersection occurs at the same point. Therefore, Condition 1 is not satisfied and there is no occlusion.

### Generation of a simple polygon

Consider a set of ordered points v = {vi (xi, yi); i = 1, …, n}, in which no two points are coincident and no three points are collinear. In this point set, i is the index of points, vi is used to indicate the point i, n is the number of points in the set (usually n > 3), and (xi, yi)⊰R2 represent the coordinates of point i. For vi and vi+1 (i = 1, . . . ., n—1), if the x coordinates are the same xi+1 = xi, then xi+1 = xi; ohterwise xi+1 > xi.

Usually, we regard x-axis as the horizontal axis, y-axis as the vertical axis perpendicular to the x-axis, and the intersection of the two axes as origin o (Fig 4). There are five ordered points in this figure And their set can be represented as v = {v1, v2, v3, v4, v5}. After sorting, x1x2x3x4x5. Moreover, when x1 = x2, y2 > y1. Because the x-coordinates of all the points are different, their y-coordinates were not considered when ordering.

### Polygon-generation process

(1) Initialization. From a given set of ordered points v = {vi, i = 1, …, n}, we select the first nc(0) points (usually 3) to construct a polygon vc(0) (note that vc represents both the polygon and the set of points that compose it). The set of points corresponding to this polygon can be denoted as vc(0) = {vck(0), k = 1, …, nc(0)}, where nc(0) is the point number of the constructed polygon. The residual points in set v are included in the remaining set vs(0) = {v/vc(0)} = {vsl(0), l = 1, …, n–nc(0)}; set vs is still a set of ordered points and the sorting method is consistent with that of set v.

Fig 5 shows an example of polygon initialization. There are 5 ordered points in the set, i.e., v = {v1, v2, v3, v4, v5} = {vi, i = 1, …, n}, where n = 5. Select the first nc(0) points to construct a polygon vc(0). Set vc(0) = {v1/vc1(0), v2/vc2(0), v3/vc3(0)} = {vck(0), k = 1, …, nc(0)}, where nc(0) = 3 and the symbol / denotes the same point. In the remaining set, vs(0) = {v / vc(0)} = {v4/vs1(0), v5/vs2(0)}.

(2) Let τ be the iteration indicator. Considering point vs1(τ) in the remaining set vs(τ) as an insertion point, we can conclude that the point before point vs1(τ) is vnc(τ) in the set v. We find two lines which connect point vnc τ) from the polygon vc(τ) and judging the visibility of these two lines from point vs1(τ). Then insert point into the line which is visible from it. If both lines are visible from point vs1(τ), one line is selected randomly. The set of points of the new polygon can be rewritten as vc(τ + 1) = {vck(τ + 1), k = 1, 2, …, nc(τ + 1)}, nc (τ + 1) = nc(τ) + 1, and the iteration indicator is τ = τ + 1.

Polygon vc(0) is considered as the initial polygon, and the iteration process is started. As shown in Fig 5(B), by judging the visibility of the two lines at vnc(τ) = v3/vc3(0) and vs1(τ) = v4/vs1(0), both v1v3 and v2v3 are visible from point vs1(τ). Therefor, one line is selected randomly and the point vs1(τ) is inserted into it; if we select line v1v3, the resulting polygon is as shown in Fig 6(A). Consider the set of points vc(1) = {v1/vc1(1), v2/vc2(1), v3/vc3(1), v4/vc4(1)} = {vck(1), k = 1, …, nc(1)}, where nc(1) = 4 and the remaining set vs(1) = {v/vc(1)} = {v5/vs2(1)}. If line v2v3 is selected, the resulting polygon is as shown in Fig 6(B). Here, vc(1) = {v1/vc1(1), v2/vc2(1), v4/vc3(1), v3/vc4(1)} and vs(1) = {v/vc(1)} = {v5/vs2(1)}. Evidently, the insertion method affects the order of the set vc and polygon geometry. However, it has no impact on the order of the sets v and vs.

Lemma 1 The point before point vs1 is vnc. In the case of two lines r1 and r2 on which vnc is located, at least one line is visible from vs1.

Proof: Assume that the two lines r1 and r2 are not visible from vs1. If line r1 is not visible from vs1, line r2 occludes r1. A ray t starting from point vs1 intersects lines r1 and r2 at points sm and sn, respectively. According to the definition of occlusion, d(sm, vs1) > d(sn, vs1). If line r2 is not visible from vs1, then r1 occludes r2. When ray t starts at point vs1, it intersects lines r1 and r2 at points sm and sn, respectively. According to the definition of occlusion, d(sn, vs1) > d(sm, vs1). Contrary to the assumptions, there is no situation in which both lines r1 and r2 are not visible from the point vs1. Therefore, it can be demonstrated that at least one line, i.e., either r1 or r2 or both, is visible from point vs1.

Fig 7 illustrates Lemma 1. As shown in Fig 7(A), the point before point vs1 is vnc. A line passing through vnc that is perpendicular to the x-axis divides the plane into L and R regions. According to the order of the points, point vs1 is in the R region. The ray t starting at point vs1 intersects lines r1 and r2 at points sm and sn, respectively. If d(sm, vs1) > d(sn, vs1), r1 is not visible from vs1; similarly, if d(sn, vs1) > d(sm, vs1), r2 is not visible from vs1. If there is no ray t that can simultaneously intersect lines r1 and r2 (except line vs1vnc, as shown in Fig 3(D)), both lines are visible from vs1.

Lemma 1 indicates that either r1 or r2 or both lines are visible from point vs1. As shown in Fig 7(B), region R can be divided into three parts by extending lines r1 and r2, i.e., R = {R1, R2, R3}. When point vs1 is in R1, line r1 is visible and line r2 is not visible. When point vs1 is in R3, line r2 is visible and line r1 is not visible from it. When point vs1 is in R2, both r1 and r2 are visible from it.

(3) The final polygon is generated at an iteration indicator τ = n– 3. At this time, the number of points in the remaining set is 0. The set of points corresponding to the polygon is vc(n– 3) = {vck(n– 3), k = 1, …, n} = v.

The polygon-generation process is illustrated in Fig 8(A)–8(F). There are seven ordered points that can be denoted as v = {v1, v2, v3, v4, v5, v6, v7}. The first three points are connected to form an initial polygon vc(0) = {vc1(0), vc2(0), vc3(0)} and the remaining set of points can be denoted by vs(0) = {vs1(0), vs2(0), vs3(0), vs4(0)}. Consider the first point vs1(0) in vs(0); the point preceding vs1(0) is point vc3(0). Therefore, we need to judge the visibility of lines vc3(0)vc2(0) and vc3(0)vc1(0) from vs1(0). The line vc3(0)vc2(0) is visible from point vs1(0) and hence, we insert point vs1(0) into the line to form the new polygon vc(1) = {vc1(1), vc2(1), vc3(1), vc4(1)} and the remaining set of points can be written as vs(1) = {vs1(1), vs2(1), vs3(1)}, as shown in Fig 8(C). After the iterative insertion process is completed, the final polygon shown in Fig 8(F) is obtained.

### Polygon-generation algorithm

Given a set of ordered points v, the steps required to generate a polygon can be represented using the following pseudo-codes.

Initialization: Initial polygon vc and vs is the set of remaining points

For τ = 0 to n– 3

1. The number of nodes in polygon vc(τ) is denoted as nc(τ).
2. Find two sides of point vnc(τ) from polygon vc(τ) and denote them as r1 and r2.
3. Select the first node vs1(τ) from vs(τ).
4. Judge the visibility of r1 and r2 from vs1(τ).
5. Insert vs1(τ) into r1 or r2, whichever line is visible from it.
6. Generate polygon G = vc(τ +1).

End

1. Generate polygon G = vc

## Experiments and results

This study proposes a simple polygon-construction method, which proves that in a given set of points, all points can be regarded as polygon nodes and can form a simple polygon. In the current experimental section, the number of simple polygons generated is counted and the criterion of whether all given points can be used as polygon nodes to form simple polygons is used to evaluate the proposed algorithm.

### Relationship between the number of polygons and the number of points

From Lemma 1 it can be seen that a simple polygon can be formed from a set of points. Additionally, the number of polygons generated is not unique according to the constructing method. From a set of ordered points v = {vi (xi, yi); i = 1, …, n}. Evidently, the first three points v1, v2, and v3 can be used to construct one polygon. Based on our proposed method, point v4 is inserted into the polygon generated by the first three points, i.e., point v4 is inserted on either line v1v3 or line v2v3. Therefore, when both lines are visible from point v4, two polygons can be formed which implies that a maximum of two polygons can be formed. In the two polygons formed from the four points described above, when point v5 is inserted, each polygon yields two new polygons. Therefore, a maximum of four polygons can be formed from five points. By analogy, according to the given method, a maximum of 2n – 3 polygons can be constructed from a set of n non-collinear points.

As shown in Fig 9(A), from a set of five ordered points v = {v1, v2, v3, v4, v5}, the first three points v1, v2, and v3 are selected to construct a triangle Δv1v2v3. subsequently, point v4 is inserted into the triangle formed by the first three points. Because the points follow a particular order, point v4 can exist only in the R region, which is divided into three parts denoted as R = {R1, R2, R3}. When point v4 is present in R1 or R3, only one of the two lines containing point v3 is visible from it. Therefore, only one polygon can be constructed. When point v4 is in R2, both lines containing v3 are visible from it, and hence, it can form two polygons. According to the proposed polygon-construction method, a maximum of two polygons can be constructed using four points (Fig 9(B)). Similarly, when point v5 is inserted four polygons can be constructed (Fig 9(C)).

### Relationship between polygon shape and point order

In this section, we shall discuss the relationship between the number of points and the number of polygons that can be constructed with the same coordinate order. The influence of different coordinate axis directions on polygon shape when the relative position of a group of points is unchanged is also considered.

As shown in Fig 10, given a set of points v = {vi, i = 1, …, 8}, the positional relationship between the points remains unchanged. Fig 10(A)–10(C) depict the polygons formed when the x-axis direction is horizontal, rotated by 45º to the left, and rotated by 90º to the left, respectively. Note that when the x-axis is in different directions, the order between the points as well as the shape of the polygon are different. Therefore, it can be concluded that the shape of the polygon depends on the arrangement of points, which in turn is dependent on the direction of the coordinate axis. However, according to the theoretical proof, given a set of non-collinear points, a simple polygon can be formed regardless of the direction of the coordinates.

### Polygon generation experiment

To verify the feasibility of the proposed method, 20, 50, and 80 points were randomly generated and a simple polygon was then generated from each of these sets using the proposed algorithm. Fig 11 shows the plane distribution of 20, 50, and 80 random points. The experimental results are shown in Fig 12. As described in the section on the relationship between number of polygons and number of points, the number of simple polygons generated by the proposed algorithm is not unique. Fig 12 shows two different geometric polygons formed by each group of points. Fig 12(A1)–12(A2), 12(B1)–12(B2) and 12(C1)–12(C2) represent polygons consisting of 20, 50, and 80 points, respectively, and it can be noticed that all the constructed polygons are simple polygons.

Some regions of the polygon with 80 random points cannot be seen clearly. We considered the polygon generated in Fig 12(C1) as an example and enlarged a part of its area (Fig 13). Figs 13(B)–13(D) represent enlarged images of areas in the blue, green, and black boxes in Fig 13 (A), respectively. We can see that the polygon with 80 random points is still a simple polygon. Moreover, the points in the graph are randomly generated, which verifies the feasibility of the proposed method for constructing simple polygons.

### Comparative experiments

Because both the polar coordinate sorting [5] and dichotomy sorting [6] methods can construct simple polygons using all the given random points as polygon nodes, we compared our proposed method with these two methods for generating simple polygons from three groups of different number of random points (see Fig 11). Fig 14 shows the result obtained using the polar coordinate sorting method, where the black dot represents pole position. According to this algorithm, for a set of random points at a given position, this method can only generate a simple polygon with a fixed geometry. Fig 15 shows the result obtained using the dichotomy sorting method. It can be seen that the number of polygons generated is unique when the direction of a given dichotomy is fixed. However, the proposed method can still construct polygons with different geometric shapes when the coordinate axis direction is given, which implies that the approach proposed in this study is more flexible.

Table 1 shows the time required by the three methods to generate polygons for different random points; it can be inferred that the polar coordinate sorting method is the fastest, while the proposed method is the slowest. However, this slow rate can be attributed to its ability to generate polygons of different geometric shapes for which more time is required.

The number of simple polygons constructed by the polar coordinate sorting and dichotomy sorting methods is unique, while the number of simple polygons constructed by the convex-hull construction method [7] is non-unique. However, the latter cannot generate a simple polygon using all the given random points as polygon nodes.

Consider a set of seven ordered points v = {v1, v2, v3, v4, v5, v6, v7}, as shown in Fig 16(A). The polygon-construction process using the proposed method is shown in Fig 16(B)–16(E) and Fig 16(F) shows the final polygon, which is a simple polygon.

Fig 17 shows the results of polygon generation using the convex-hull construction method. First, the convex hull of a given node set is generated (Fig 17(A)); later, a point is randomly selected from the remaining points and inserted into the line visible from it to form a new polygon. The final polygon is shown in Fig 17(D). However, none of the polygon edges are visible from point v4. Therefore, in this situation, point v4 is called an invalid point. Finally, we can infer that polygon construction based on the convex-hull method includes a strong element of randomness owing to which it is impossible to construct a simple polygon with all the points in a given set. Unlike the method proposed in this study, using which a simple polygon can be constructed from a given set of non-collinear points, in the convex-hull construction method, invalid points may occur.

## Conclusion

In this study, we designed an IIOP algorithm to generate a simple polygon from a set of ordered points. Through theoretical and experimental verification of this algorithm, the following three conclusions could be drawn. (1) Given a set of non-collinear points, a simple polygon can be formed. (2) The shape of a simple polygon depends on the sorting method used. (3) The number of polygons is related to the number of random points. When the sorting method is fixed, at least 1 or a maximum of 2n – 3 simple polygons can be formed, where n is the number of non-collinear points in a set.

## Acknowledgments

We would like to thank Editage (www.editage.cn) for English language editing.

## References

1. 1. Vaclav Skala. Point-in-Convex Polygon and Point-in-Convex Polyhedron Algorithms with O(1) Complexity using Space Subdivision. ICNAAM 2015. AIP Publishing LLC, 2015; 22–28.
2. 2. Martin N, Roman P, Ignaz R. Partitioning graph drawings and triangulated simple polygons into greedily routable regions. Algorithms and Computation (ISAAC'15). Springer Berlin Heidelberg, 2015. https://doi.org/10.1007/978-3-662-48971-054
3. 3. Bose P, Kostitsyna I, Langerman S. Self-approaching paths in simple polygons. Computational Geometry, 2019.
4. 4. Oh E, De Carufel JL, Ahn HK. The geodesic 2-center problem in a simple polygon. Computational Geometry. 2018; 74: 21–37.
5. 5. Laszlo MJ. Computational geometry and computer graphics in C++. 1st ed. Upper Saddle River, NJ: Prentice Hall, 1996; 109–112. https://doi.org/10.1109/5.163408
6. 6. Weixin W, Yongping H. The algorithm of constructing polygons by sorting the scattered points. Journal of Shenyang Ligong University. 1997; 16(4): 11–14. (in Chinese)
7. 7. Muravitskiy V, Tereshchenko V. Generating a simple polygonalizations. In 2011 15th International Conference on Information Visualisation, IEEE. 2011; 668–671. https://doi.org/10.1109/IV.2011.88
8. 8. Dailey D, Whitfield D. Constructing random polygons. In Proceedings of the 9th ACM SIGITE Conference on Information Technology Education. 2008; 119–124. https://doi.org/10.1145/1414558.1414592
9. 9. Li F, Klette R. Euclidean shortest paths in a simple polygon. Algorithms, Architectures and Information Systems Security. 2015.
10. 10. Cardinal J, Hoffmann U. Recognition and complexity of point visibility graphs. Discrete and Computational Geometry. 2017; 57: 164–178.
11. 11. Himmel AS, Hoffmann C, Kunz P, Froese V, Sorge M. Computational complexity aspects of point visibility graphs. Discrete Applied Mathematics. 2019; 254: 283–290.
12. 12. Bahoo Y, Banyassady B, Bose P K, Durocher S, Mulzer W. A time–space trade-off for computing the k -visibility region of a point in a polygon. Theoretical Computer Science, 2019; 789: 13–21.
13. 13. Chen DZ, Wang H. Visibility and ray shooting queries in polygonal domains. Computational Geometry—Theory and Applications. 2015; 48(2): 31–41.
14. 14. Chen DZ, Wang H. Weak visibility queries of line segments in simple polygons. Computational Geometry. 2015; 48(6): 443–452.