Computational ry: convex bag learning notes --- Graham Scanning

Source: Internet
Author: User

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:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.