File Exchange

image thumbnail

Circle fit

version 1.0 (1.83 KB) by

Fit a circle to a set of measured x,y points.

150 Downloads

Updated

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.

Comments and Ratings (26)

Scott

Scott (view profile)

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

Scott

Scott (view profile)

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.

Scott

Scott (view profile)

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

Xin

Xin (view profile)

tejas harish

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

Daniel Golden

Yasmine

Hi,

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

Nikolai Chernov (view profile)

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
http://www.math.niu.edu/~rusin/known-math/99/circlefit
 (last "t" was missing)

Hedi Kawano

http://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. 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

Yuri,

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
MATLAB 5.2 (R10)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video