The convex hull (two times scanning, the method of the upper and lower convex package is obtained)

Source: Internet
Author: User

Find Convex hull template

struct Point{Double XY;Double ValLen;}points[20];PointPoints1[20];PointPoints2[20];Constint INF=1e8;boolCmp(PointA,PointB){If(A. x==b. x)Return a. Y<b. Y;Return a. x<b. x;}DoubleChaji(PointA,PointB,PointC,PointD){Return(b. x-A. x) * (d. Y-C. Y)-(b. Y-A. Y) * (d. x-C. x);}int real[20];IntCover(int Potnum,int n){Sort(Points1, Points1+potnumCmp);int Ansnum=0;For(int I=0; I<potnum; I++){While(Ansnum>1&&Chaji(points2[Ansnum-2],points2[Ansnum-1],points2[Ansnum-1],points1[I]) <0) Ansnum--; Points2[Ansnum++]=points1[I];}int k=ansnum;For(int I=potnum-2; I>=0; I--){While(Ansnum>k&&Chaji(points2[Ansnum-2],points2[Ansnum-1],points2[Ansnum-1],points1[I]) <0) Ansnum--; Points2[Ansnum++]=points1[I];}If(n>1) Ansnum--;Return Ansnum;}Doubleway (point a ,point B) Span class= "Sh-cbracket" >{return sqrt ((A.x-b.x.x-b.x) + (A.y-b.y) * (A.y-b.y}  

The convex hull (two times scanning, the method of the upper and lower convex package is obtained)

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.