(Geometry: non-cross polygon) Write a program that enables the user to add/ remove points by clicking the left/right mouse button, and displays a noncrossed polygon that links all the points, as shown in Figure 22.11 a. A polygon is crossed if two or more sides intersect, as shown in Figure 22.11b. Use the following algorithm to construct a polygon from a set of points.FIGURE CANT COPY
Figure 22.11 (a) Programming Exercise22.15 displays a non-crossed polygon for a set of points. (b) Two or more sides intersect in a crossed polygon.
Step 1: Given a set of points $S$, select the rightmost lowest point $p_0$ in the set $S$.
Step 2: Sort the points in $S$ angularly along the $x$-axis with $p_0$ as the center. If there is a tie and two points have the same angle, the one that is closer to $p_0$ is considered greater. The points in $S$ are now sorted as $p_0, p_1, p_2, \ldots$, $p_{n-1}$.
Step 3: The sorted points form a non-cross polygon.