Minimum Circle Overlay Template

Source: Internet
Author: User

//Minimum Circle cover//input: Point set _ps and size starting from subscript 0 _n//output: The smallest circle covering all points//complexity: O (n)//Note: Random manipulation of _ps will change the internal order of the point setCircle Mincovercir (Point _ps[],int_n) {    //random processing, but changes the set of points that are passed in. Random_shuffle (_ps, _ps+_n);//complexity O (_n)Circle Rec; REC.R=0; REC.C= _ps[0];  for(intI=1; i<_n;i++)    {        if(GT (Dis (Rec.c,_ps[i]), REC.R))//I point outside the circle{REC.R=0; REC.C=_ps[i];  for(intj=0; j<i;j++)            {                if(GT (Dis (Rec.c,_ps[j]), REC.R))//J outside the Circle{rec.c.x= (_ps[i].x+_ps[j].x)/2.0; Rec.c.y= (_PS[I].Y+_PS[J].Y)/2.0; REC.R= Dis (_ps[i],_ps[j])/2.0;  for(intk=0; k<j;k++)                    {                        if(GT (Dis (Rec.c,_ps[k]), REC.R))//K outside the Circle{Rec=outcircle (_ps[i], _ps[j], _ps[k]); }                    }                }            }        }    }    returnRec;}

Why, I think the code is much clearer than the explanation. The most critical step to prove is why, after determining that the i,j must be on a circle, when there is a point k that is not within the circle, use I,j,k's circumscribed circle instead. This picture can be proved with some geometrical knowledge. Then the theoretical complexity is O (n), although it seems to be n^3, but each layer down may be log, so the average up is O (n+ (logn) ^3) = O (n). This algorithm is really a clever one.

Minimum Circle Overlay Template

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.