File Exchange

image thumbnail

Circle fit

version (1.83 KB) by Izhak Bucher
Fit a circle to a set of measured x,y points.


Updated 29 Jul 2004

View License

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.

Cite As

Izhak Bucher (2021). Circle fit (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (33)

Christopher Wilcox

David Romero

Oliver Brownbridge

Konogan Baranton

Far Bod

Matthieu FURET

Saved me a lot of time, thank you !



Sorry, 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)".


tejas 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.


My 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 Baidillah

ahmet dogrusadik


tejas harish

can anyone please tell what is significance of variables th,R,xe and sigma in the circlefit code?

Daniel Golden



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

SengChoy Liew

I 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 Chernov

This 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 Alpay

Works like a charm :-)

Darren Hewett

Sebastian Laechele

Works 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 Brown

Note: 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 Nurhadi

Just... Excellent.. thanks.

Sanjeev Sharma

I found it to be very effective.

shmi braun

Luigi Rosa

High-quality code, simple and effective

Tomaz Pepelnjak

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

Hedi Kawano

Sorry, it is
(last "t" was missing)

Hedi Kawano tells you that the equation used in this "circle_fit.m" gives an approximate solution.

Knut C. Naue

Nice 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 Hemming

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

Yogesh Mehta


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 ?

MATLAB Release Compatibility
Created with R10
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!