Convex Hull
(Only for Convex packets in two-dimensional planes)
I. Definition
Simply put, there is a set of N points in a two-dimensional plane S. Now you need to select a point set C, and the points in C form a convex polygon G, so that all points in the s set are either within g or on g, and the area of the convex polygon is minimized. What we need is the C set.
Ii. Algorithms
There are many algorithms for finding convex packets. There are two common algorithms:
1. Graham scanning method. The running time is O (nlgn ).
2. The Jarvis stepping method runs at O (NH) and H is the number of vertices in the convex hull.
The first algorithm is discussed here: Graham Scanning
Graham scanning method:
Basic Idea: Use a stack to judge all vertices one by one and screen out non-conforming vertices.
Operation: each vertex in the input set Q is pushed to the stack once. vertices in non-CH (q) (indicating the convex packet of Q) will be popped up. When the algorithm ends, stack S contains only the vertices in CH (Q). The order of these vertices is the order in which each vertex appears on the boundary in a counterclockwise direction.
First, find a vertex on the convex bag and place the vertex at the position P0 of the first vertex. Then ~ PM is ordered in the direction of p0pi and can be determined by the yarn product (cross product.
Determination process:
After preprocessing is completed, start to set the points in the stack <P3, P4 ,..., PM> iterates each vertex in the stack. In the while loop of rows 1 to 8, the vertex not found in the convex hull is removed from the stack. (Principle: When the convex hull is passed in the counterclockwise direction, the left turn should be made at each vertex. Therefore, the while loop pops up the vertex from the stack every time it finds that there is no left turn at a vertex .) When the algorithm advances to the vertex PI and all non-left-turn vertices are popped up, the PI is pushed into the stack.
The entire algorithm process: