//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