Computational geometry-convex hull problem (II.)

Source: Internet
Author: User

Note: This is one of the brief personal summary series of the MOOC course in Deng Junhui, Tsinghua University, in spring 2016, and I will synchronize the course content updates. However, it is possible to write not exactly the course content, but also some personal understanding. If you are interested in computational geometry after reading this article, please go to the appropriate MOOC platform to learn the full course of teacher Deng. Such well-designed and choreographed courses should not be betrayed. Thank you, teacher Deng!

knowledge Dependence: You only need to have basic geometry knowledge and algorithmic knowledge before reading this article. The code implementation requires a lost C + + base.

Because the author is lazy and doesn't want to draw, you need a little bit of brain theater. But believe me, it will be interesting to visualize the problem step-by-step in my head. Don't believe me? Look down.

Polar Edge (Extreme edge) algorithm

In the previous article, we focused on the pole, and came up with a time complexity of up to O (n^4) algorithm, which is unacceptable.

Now, let's switch our attention to the polar side.

What is the polar side? It's also simple: the edges that make up the convex hull are polar edges.

So how do we use the polar edges to solve convex hull? As with the pole algorithm, we also examine the characteristics of the polar edges.

For any of the two-pole segments (including the "polar side" we're looking for), we can clearly find that the right side of the polar side must be empty (as in the previous article, which specifies that the counterclockwise direction is the positive direction)! That is to say, for a given set of points, there is no point on the right side of the pole! For those who are not on the polar side of the line, we can clearly find that both sides of it are definitely not empty.

Based on this feature of the polar side, we can naturally get the algorithm for finding the polar edge:

First, we enumerate the "directed segment" (Directed Edge), which is made up of any two points of the fixed point set, and then for the current directed segment, we enumerate a bit (except for the two points that make up the vertex of the directed segment) and determine whether the point is on the right side of the directed segment, if so, That means that the directed segment we're currently enumerating is not the polar side we're looking for.

It is also worth mentioning that, in the implementation process, since we are enumerating any two points to determine the directed segment of the enumeration, but "directed" the matter is not so well-defined. However, in fact, we do not need to strictly determine whether the point is in the direction of the "right" side of the line, and only need to determine the direction of the line of the "one" side is empty.

So how do you tell which side of the point is on the line?

Good familiar with the problem Ah! Yes, in the last article we have the same problem has been attributed to this sub-problem! The answer is to use twice times the area to do ToLeft test!

At this point, the algorithm has been clearly understood.

The exact code is implemented as follows, the code is also very clear, I still suggest you follow the code again clearly comb again:

1 /*******************************2 * extreme_edge_algorithm for convex Hull construction3 * Time Complexity:o (n^3)4 ********************************/5 6 voidMarkee (Point s[],intN) {7     //initialization: "Guilty inference", that is, the preset all points are not Poles (i.e. all directed segments are not polar edges)8      for(intK =0; K < n; k++) S[k].extreme =false;9     //enumerate all "forward edges"Ten      for(intp =0; P < n; p++) One          for(intQ = p +1; Q < n; q++) ACheckedge (S, N, p, q);//directed Edge PQ - } -  the voidCheckedge (Point s[],intNintPintq) { -     //initialization: First assume that there are both sides of the PQ are empty (that is, there is no point) -     BOOLLempty =true, Rempty =true; -     //enumerates all points except P, Q, and ToLeft Test with a forward edge PQ +      for(intK =0; K < n && (Lempty | | Rempty); k++) { -         if(k! = P && k! =q) { +             //if ToLeft Test is True the left is not empty, otherwise the right side is not empty AToLeft (S[p], s[q], s[k])? Lempty =false: Rempty =false; at         } -     } -     //If there is an empty side of the edge PQ, the PQ is the polar edge, and the vertices that make up the polar edges are marked as -     if(Lempty | |rempty) -S[p].extreme = S[q].extreme =true; - } in  - BOOLToLeft (point P, point Q, point s) { to     //The toleft Test is equivalent to twice times "direction area" to avoid the problem of precision caused by division or trigonometric operation. +     returnAREA2 (P, Q, s) >0; - } the  * intArea2 (point P, point Q, point s) { $     //twice times "forward area"Panax Notoginseng     return -p.x * Q.Y-P.Y *q.x the+ q.x * S.Y-Q.Y *s.x ++ s.x * P.Y-S.Y *p.x; A}

In the same way, we analyze the complexity of the algorithm.

First we enumerate the directed segments as a double loop, and then for each directed segment we need to enumerate through all the points for toleft test, and toleft test is constant time.

Yes, the time complexity of the polar algorithm is O (n^3).

Although we have reduced the complexity of time by an order of magnitude compared to the previous pole algorithm, we still find it unacceptable that we still need a new perspective for better algorithms.

"To Be Continued"

Computational geometry-convex hull problem (II.)

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.