🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

5 total messages Started by Kurt Feldbush Thu, 02 Apr 1998 00:00
Help! Need Best-Fit Circle Equation.
#21
Author: Kurt Feldbush
Date: Thu, 02 Apr 1998 00:00
9 lines
998 bytes
    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 Feldbush
Kurt@conversionsinc.com
Conversions, inc
(630) 790-3355 ext 29
Re: Help! Need Best-Fit Circle Equation.
#22
Author: Peter Spellucci
Date: Thu, 02 Apr 1998 00:00
17 lines
1406 bytes
In article <3523A24A.F9C10F3B@conversionsinc.com>, Kurt Feldbush <kurt@conversionsinc.com> writes:
|>     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?
|> 
take odrpack from netlib. there is an ellipse-fit in the user-guide,
and, of course, the circle is the simpler case. you could do the
circle fit in a special manner (not using general orthogonal regression)
simply by minimizing 

   sum_i { ( (x_i-xm)**2+(y_i-ym)**2-r**2 )**2 }

with respect to xm,ym and r (midpoint and radius), with x_i,y_i the
given points
hope this helps
peter
Re: Help! Need Best-Fit Circle Equation.
#23
Author: Gerald Recktenwald
Date: Thu, 02 Apr 1998 00:00
23 lines
1373 bytes
In article <3523A24A.F9C10F3B@conversionsinc.com>, Kurt Feldbush
<kurt@conversionsinc.com> 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?

Have a look at

  "Least-squares fitting of circles and ellipses", W.Gander, G.H. Golub,
  and R. Strebel, BIT, vol 34 (1994), pp. 448-578

Gander et al compare different methods.  MATLAB source codes are
available at ftp.inf.etch.ch.

Gerry

-- 
+-+-+-+-+-+-+-+-...
Gerald Recktenwald    (503) 725-4296
gerry@me.pdx.edu      http://www.me.pdx.edu/~gerry/
PSU Mechanical Engineering, P.O. Box 751, Portland, OR 97207
Re: Help! Need Best-Fit Circle Equation.
#24
Author: Allan Hayes
Date: Fri, 03 Apr 1998 00:00
76 lines
2888 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 onlinearRegress

	<<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
Re: Help! Need Best-Fit Circle Equation.
#25
Author: Allan Hayes
Date: Fri, 03 Apr 1998 00:00
76 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads