Introduction

The article shows you a visual implementation of Graham's scan algorithm's data movement to choose the smallest polygon.

Background

Graham's scan is a method of computing the convex hull of a finite set of points in the plane with time complexity O(n log n). It is named after Ronald Graham,
who published the original algorithm in 1972.[1] The algorithm finds all vertices of the convex hull ordered along its boundary.

The first step in this algorithm is to find the point with the lowest y-coordinate.

Next, the set of points must be sorted in increasing order of the angle and the point P made with the x-axis.

The algorithm proceeds by considering each of the points in the sorted array in sequence. For each point, it is determined
whether moving from the two previously considered points to this point is a "left turn" or a "right turn". If it is a "right turn",
this means that the second-to-last point is not part of the convex hull and should be removed from consideration. This process is continued
for as long as the set of the last three points is a "right turn". As soon as a "left turn" is encountered, the algorithm moves on to the next point in the sorted array.

Using the Code

At first, we take input in a picturebox and show by drawing a point with the mouse.

Then we take the third point and calculate whether it is a right turn or left turn. If three points move at clockwise, then it is a right turn.
Then we eliminate the middle point and also the line. Removing the line is simple, just draw the line again in white colour. After eliminating the point,
we go one step back and calculate the turn with the other checked points. If three points make left turn, then we have to take the next point and calculate until all points are not traversed.