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

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 [2][3][4]. 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 trianglebased 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.

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].

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 [10][11][12].  1. There is a ray t starting at point v i and it intersects with both lines v 1 v 2 and v 3 v 4 , at different points.
2. If the intersections of ray t with lines v 1 v 2 and v 3 v 4 are s i and s j (i 6 ¼ j), respectively, then d [13][14].

Generation of a simple polygon
Consider a set of ordered points v = {v i (x i , y i ); 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, v i is used to indicate the point i, n is the number of points in the set (usually n > 3), and (x i , y i )⊰R 2 represent the coordinates of point i.
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 Because the x-coordinates of all the points are different, their y-coordinates were not considered when ordering.
Polygon v c (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 v nc . Therefor, one line is selected randomly and the point v s1 , v 2 /v c2 , k = 1, . . ., nc (1) }, where nc (1) = 4 and the remaining set v s }. If line v 2 v 3 is selected, the resulting polygon is as shown in Fig 6(B).
, v 4 /v c3 }. Evidently, the insertion method affects the order of the set v c and polygon geometry. However, it has no impact on the order of the sets v and v s .

Lemma 1
The point before point v s1 is v nc . In the case of two lines r 1 and r 2 on which v nc is located, at least one line is visible from v s1 .
Proof: Assume that the two lines r 1 and r 2 are not visible from v s1 . If line r 1 is not visible from v s1 , line r 2 occludes r 1 . A ray t starting from point v s1 intersects lines r 1 and r 2 at points s m and s n , respectively. According to the definition of occlusion, d(s m , v s1 ) > d(s n , v s1 ). If line r 2 is not visible from v s1 , then r 1 occludes r 2 . When ray t starts at point v s1 , it intersects lines r 1 and r 2 at points s m and s n , respectively. According to the definition of occlusion, d(s n , v s1 ) > d(s m , v s1 ). Contrary to the assumptions, there is no situation in which both lines r 1 and r 2 are not visible from the point v s1 . Therefore, it can be demonstrated that at least one line, i.e., either r 1 or r 2 or both, is visible from point v s1 . According to the order of the points, point v s1 is in the R region. The ray t starting at point v s1 intersects lines r 1 and r 2 at points s m and s n , respectively. If d(s m , v s1 ) > d(s n , v s1 ), r 1 is not visible from v s1 ; similarly, if d(s n , v s1 ) > d(s m , v s1 ), r 2 is not visible from v s1. If there is no ray t that can simultaneously intersect lines r 1 and r 2 (except line v s1 v nc , as shown in Fig 3(D)), both lines are visible from v s1 . Lemma 1 indicates that either r 1 or r 2 or both lines are visible from point v s1 . As shown in Fig 7(B), region R can be divided into three parts by extending lines r 1 and r 2 , i.e., R = {R 1 , R 2 , R 3 }. When point v s1 is in R 1 , line r 1 is visible and line r 2 is not visible. When point v s1 is in R 3 , line r 2 is visible and line r 1 is not visible from it. When point v s1 is in R 2 , both r 1 and r 2 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 and v c3 (0) and hence, we insert point v s1 (0) into the line to form the new polygon v c (1) = {v c1 (1) , v c2 (1) , v c3 (1) , v c4 (1) } and the remaining set of points can be written as v s (1) (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.

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 = {v i (x i , y i ); i = 1, . . ., n}. Evidently, the first three points v 1 , v 2 , and v 3 can be used to construct one polygon. Based on our proposed method, point v 4 is inserted into the polygon generated by the first three points, i.e., point v 4 is inserted on either line v 1 v 3 or line v 2 v 3 . Therefore, when both lines are visible from point v 4 , 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 v 5 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 2 n -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 = {v 1 , v 2 , v 3 , v 4 , v 5 }, the first three points v 1 , v 2 , and v 3 are selected to construct a triangle Δv 1 v 2 v 3 . subsequently, point v 4 is inserted into the triangle formed by the first three points. Because the points follow a particular order, point v 4 can exist only in the R region, which is divided into three parts denoted as R = {R 1 , R 2 , R 3 }. When point v 4 is present in R 1 or R 3 , only one of the two lines containing point v 3 is visible from it. Therefore, only one polygon can be constructed. When point v 4 is in R 2 , both lines containing v 3 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 v 5 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,   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. 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 convexhull 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 = {v 1 , v 2 , v 3 , v 4 , v 5 , v 6 , v 7 }, 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. 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 v 4 . Therefore, in this situation, point v 4 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 2 n -3 simple polygons can be formed, where n is the number of non-collinear points in a set.