Article View: sci.stat.math
Article #25Re: Help! Need Best-Fit Circle Equation.
From: Allan Hayes
Date: Fri, 03 Apr 1998 00:00
Date: Fri, 03 Apr 1998 00:00
76 lines
2894 bytes
2894 bytes
Kurt Feldbush wrote:
> I am looking for an equation or algorithm to find the best fit
>circle or ellipse to a set of data points. I have searched everywhere I
>could think of with no luck. Can anyone help?
Kurt,
I used the Mathematica function NonlinearRegress
<<Statistics`NonlinearFit
I made 50 perturbed points, a list points, for an ellipse center {.2, .4}
with semi-axes 3 in direction -Pi/3 and 5 at right angles to this.
First I need a model (for a circle this can be much simpler)
u ={Cos[t],Sin[t]}; (*t = angle of one axis*)
p= {x,y}; (*p is a generic data point*)
c = {cx,cy}; (*c is the center of the ellipse*)
pc = p-c;
model = ((pc).u)^2 /a^2 + (pc.pc - (pc.u)^2)/b^2 - 1 ;
(* a is semi-axis in direction of u , a the other one*)
(*equation of ellipse is model == 0*)
vars = {x,y};
params = {a,b,t,cx,cy};
data = Append[#,0.0]&/@points;
We calculate the optimal model
bestparams=
BestFitParameters/.NonlinearRegress[data, model, vars, params,
RegressionReport ->BestFitParameters]
{a -> 3.33709, b -> 4.87806, t -> 1.03938, cx -> -0.24978,
cy -> 0.486313}
Put thes values into the model
fmla = Expand[model /. bestparams]
2
0.0166528 + 0.00682348 x + 0.0542927 x - 0.0649814 y +
2
0.0417406 x y + 0.0775296 y
Examine the fit graphically
<<Graphics`ImplicitPlot`
ft=ImplicitPlot[fmla==0,{x,-5,4.5},{y,-4.5,4.5}, DisplayFunction -> Identity]
(*DisplayFunction -> Identity turns display off*)
pts =Show[Graphics[
{PointSize[.02],Hue[0],Point/@points}
], DisplayFunction -> Identity]
Show[ft, pts, DisplayFunction -> $DisplayFunction]
(*DisplayFunction -> $DisplayFunction turns display on*)
--
Allan Hayes
Mathematica Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642
Technical Details
Message-ID:
<35251025.F6FFA075@haystack.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3523A24A.F9C10F3B@conversionsinc.com> <gerry-0204982127160001@slip09.ee.pdx.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d632,63ed556734094c9b X-Google-Attributes: gid10d632,public X-Google-Thread: 107079,63ed556734094c9b X-Google-Attributes: gid107079,public X-Google-Thread: 10d67e,63ed556734094c9b X-Google-Attributes: gid10d67e,public From: Allan Hayes <hay@haystack.demon.co.uk> Subject: Re: Help! Need Best-Fit Circle Equation. Date: 1998/04/03 Message-ID: <35251025.F6FFA075@haystack.demon.co.uk> X-Deja-AN: 340533002 Content-Transfer-Encoding: 7bit X-NNTP-Posting-Host: haystack.demon.co.uk [158.152.22.155] References: <3523A24A.F9C10F3B@conversionsinc.com> <gerry-0204982127160001@slip09.ee.pdx.edu> To: KurtFeldbush <kurt@conversionsinc.com> Content-Type: text/plain; charset=us-ascii MIME-Version: 1.0 Reply-To: Allan Hayes <hay@haystack.demon.co.uk> Newsgroups: sci.stat.math,sci.math.num-analysis,aus.mathematics