Re: Re: Smalest enclosing circle

*To*: mathgroup at smc.vnet.net*Subject*: [mg50111] Re: [mg50082] Re: Smalest enclosing circle*From*: DrBob <drbob at bigfoot.com>*Date*: Sun, 15 Aug 2004 03:14:49 -0400 (EDT)*References*: <cfi8tm$4p6$1@smc.vnet.net> <200408140550.BAA15340@smc.vnet.net>*Reply-to*: drbob at bigfoot.com*Sender*: owner-wri-mathgroup at wolfram.com

Finally! NMinimize does a better job than FindMinimum, and constraints are not needed: Needs["Statistics`"] Needs["Graphics`"] Needs["DiscreteMath`ComputationalGeometry`"] data=RandomArray[NormalDistribution[0,1],{3,2}]; hull=data[[ConvexHull@data]]; sq=#.#&; sqDiff=sq[{x,y}-#]&; radius[x_?NumericQ,y_?NumericQ]=Sqrt@Max[sqDiff/@hull]; {r,ptRule}=NMinimize[radius[x,y],{x,y}]; pt={x,y}/.ptRule; Show[Graphics[{PointSize[0.02],Point/@ data,Red,Point@pt,Circle[pt, \ r],Blue,Line@Join[hull,{First@hull}],Point/@hull}],AspectRatio\[Rule] Automatic]; Bobby On Sat, 14 Aug 2004 01:50:42 -0400 (EDT), Kezhao Zhang <kzhang at flashmail.com> wrote: > Steve Gray <stevebg at adelphia.net> wrote in message news:<cfi8tm$4p6$1 at smc.vnet.net>... >> Given n points in the plane, I want to find the smallest >> enclosing circle. Does anyone have Mathematica code to do this? >> I will be grateful for any tips. >> >> Steve Gray > > Here is one way to do it: > Suppose the equation for the circle is (x-x0)^2+(y-y0)^2==r^2. We want > to minimize r. > > Generate some points: > In[]:=points=Partition[Table[Random[NormalDistribution[0,1]],{200}],2]; > > Constraints that all points are enclosed by the circle: > In[]:= const=(#[[1]]-x0)^2+(#[[2]]-y0)^2<= r^2&/@points; > > Numerical minimization with constraints: > In[]:=NMinimize[ Join[{r, r>0},const], {x0,y0, {r,5,10}}] > > Please note that it's better to provide some starting values for r > otherwise NMinimize will complains that a starting value that doesn't satisfy > the constraint is used. > > K. Z. > > > -- DrBob at bigfoot.com www.eclecticdreams.net

**References**:**Re: Smalest enclosing circle***From:*kzhang@flashmail.com (Kezhao Zhang)