**Editor's Note:** This file was selected as MATLAB Central Pick of the Week

Revival of a 14 years old code (written in 1991 for MATLAB 2.x).

Given a set of measured x,y pairs that a re supposed to reside on a circle, but with some added noise. A circle to these points, i.e. find xc,yc,R, such that (x-xc)^2+(y-yc)^2=R^2

The method minimizes the sum of squared radial deviations.

Izhak Bucher (2020). Circle fit (https://www.mathworks.com/matlabcentral/fileexchange/5557-circle-fit), MATLAB Central File Exchange. Retrieved .

Created with
R10

Compatible with any release

**Inspired:**
Ellipse Fit, Circle Fit (Kasa method), Circle Fit (Pratt method), Circle Fit (Taubin method), Aquiles, Fast Circle fitting using Landau method, DiffractIndex, Best fit 3D circle to a set of points

Create scripts with code, output, and formatted text in a single executable document.

Christopher WilcoxDavid RomeroOliver BrownbridgeKonogan BarantonFar BodMatthieu FURETSaved me a lot of time, thank you !

JuanScottSorry, I still have it wrong---xe is "x" in the typical way the general equation for a circle is expressed, not R*cos(th). Thus "xe-xc=Rcos(th)", and "ye-yc=Rsin(th)".

Scotttejas harish: Might be too late to answer your question; perhaps others would like to know the answer to your question. The general equation for a circle in the x-y plane is "(x-xc)^2+(y-yc)^2=R^2". In cylindrical coordinates, a circle is defined by "x-xc=R*cos(th)" and "y-yc=R*sin(th)". Thus "th" is the angle "theta", "R" is the circle radius, "xe" and "ye" are the shifted coordinates, "xe==x-xc" and "ye=y-yc" so that it is equivalent to say "(x-xc)^2+(y-yc)^2=R^2" OR "(xe)^2+(ye)^2=R^2." "sigma" is simply a scaling parameter--note the "x" and "y" variables, which are the coordinates of the points on the circle, have noise added to them--sigma merely scales the noise.

ScottMy apologies, I made a small mistake which I can't figure out how to correct by editing my original post. The 2nd equation should say: This function fits the equation for a circle, (x-xc)^2+(y-yc)^2=R^2. In cylindrical coordinates, a circle is defined by "x-xc=R*cos(th)" and "y-yc=R*sin(th)".

Marlin Baidillahahmet dogrusadikXintejas harishcan anyone please tell what is significance of variables th,R,xe and sigma in the circlefit code?

Daniel GoldenYasmineHi,

Does anyone know how to calculate deviation from circularity of the measured points compared to the fitted circle using this code?

SengChoy LiewI have come to a death end in Image processing toolbox to evaluate the circles in a gray scale image.

Anyone how how to use the codes given to fit into those circles in the image so that an histogram for the distribution of circles diameter can be plot ?

Nikolai ChernovThis circle fit has been first published by P.Delogne and I.Kasa in the 1970s and is known as "Kasa method" in statistics. It works well when points cover a large part of the circle but is heavily biased when points are restricted to a small arc. Better fits were proposed by Pratt and Taubin.

Mehmet AlpayWorks like a charm :-)

Darren HewettSebastian LaecheleWorks very well!

I don't really know how, but it works! :D

You saved me a bunch of hours there.

Thank you very much!

Richard BrownNote: This code doesn't minimise the sum of squared radial deviations - that is a nonlinear least squares problem

This code minimises sum((x.^2 + y.^2 - R^2).^2)

Hendro NurhadiJust... Excellent.. thanks.

:-)

Sanjeev SharmaI found it to be very effective.

shmi braunRe: Hedi Kawano

see also

http://www.pitchup.com/matlab/print.aspx?article=168

Luigi RosaHigh-quality code, simple and effective

Tomaz PepelnjakVery useful if you need to fit measured points to the circle function and compare it further to reference value.

Hedi KawanoSorry, it is

http://www.math.niu.edu/~rusin/known-math/99/circlefit

(last "t" was missing)

Hedi Kawanohttp://www.math.niu.edu/~rusin/known-math/99/circlefi tells you that the equation used in this "circle_fit.m" gives an approximate solution.

Knut C. NaueNice tool for data covering almost a complete circle. But if data exists describing only an arc, circfit fails identifying the assumed center and radius.

Bjorn HemmingI have used this function to verify a feature in a Metrology software giving correctly first 4 digits, so it seems OK

Yogesh MehtaYuri,

It can be extremely useful. For example, trying to fit a nyquist plot to an experimentally acquired FRFs... Ideally, nyquist plot is supposed to be a circle, but is not due 'noise'

Yuri Slobo...Can someone please enlighten me where one meets such distributions to be fitted by a circle ?