Re: Circle Fit
- To: mathgroup at smc.vnet.net
- Subject: [mg38618] Re: Circle Fit
- From: atelesforos at hotmail.com (Orestis Vantzos)
- Date: Wed, 1 Jan 2003 03:39:42 -0500 (EST)
- References: <aueij4$522$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Dieter Palme" <dieter_palme at t-online.de> wrote in message news:<aueij4$522$1 at smc.vnet.net>... > Hi experts, > I have a set of points (xi, yi), i>30. I search for a solution to fit a > circle (x-x0)^2 + (y-y0)^2 = r^2 to these points. I need r and sigma_r. > It could be helpful to get x0,y0 also, but it is not nessecary. > I found a algorythm for another system (LeastSquareFit) but not for > Mathematica 4. > Who can help? > Thanks in advance > Dieter Let's say that sample is the list with your points in the form: sample={{x1,y1},...} Also: n=Length[sample] norm[v_]:=(v.v)^1/2 You can find a decent approximation of {x0,y0} by using: center=(Plus@@@Transpose[sample])/n Now you can get a decent approximation of the radius by using: radius=Plus@@(norm[center-#]&/@sample)/n Let's estimate the total error for an arbitrary c(center) and r(radius): error[c_,r_][sample_]:=Plus@@((norm[c-#]^2-r^2)^2&/@sample) You can check our approximation by evaluating error[center,radius][sample] It is not that good, right? OK, to get a better approximation we can try to minimize the total error numerically, using center and radius as initial values: FindMinimum[error[{x0,y0},r][sample],{x0,center[[1]]},{y0,center[[2]]},{r,radius}] This returns a list of the form: {min_,{x0->_,y0->_,r->_}} To begin with, min/n is (roughly) sigma_r. I can't recall the exact definition right now... Anyway, the {x0,y0} and r returned are much better fitted to your data. Visualize it: Show[Graphics[{Circle[{0, 2}, 1], {Hue[0], Circle[center, radius]}, {Hue[.7], Circle[{x0, y0}, r] /. sol}, Point /@ sample}], AspectRatio -> Automatic]; Hope that helped, Orestis