File Exchange Pick of the Week

April 10th, 2009

Fitting Circles (again) and Ellipses

Brett's pick this week is suite of fitting functions by Nikolai.

Just over a year ago, I highlighted in this blog a useful bit of code for fitting circles to data. I pointed out that I have had numerous opportunities to use the code over the years, and that I have had good success with it.

That blog entry sparked some interesting comments, including an intriguing one from Nikolai Chernov. Now, I readily admit to being naive about the topic. If you search the File Exchange for the words "fit circle," you'll find at least 9 different relevant submissions for peforming the task. Without additional information, you're pretty much on your own to figure out which one to use. What struck me about Nikolai's comment was that not only did he reveal the name of the method implemented in Izhak's code (it's referred to as the "Kasa method"), he also described the conditions under which it was a reasonable approach ("it works well when points cover a large part of the circle but is heavily biased when points are restricted to a small arc"). With a link to his UAB website, Nikolai shared his impressive body of work on circle-fitting and ellipse-fitting, and provided access to his m-code implementations thereof.

In a follow-up email, I asked Nikolai to put his files on the File Exchange; his work was too good not to share! Happily, he was quick to comply with my request. Nikolai's suite of fitting functions is Brett's choice for this week's Pick of the Week.

Each of the five files (Taubin, Pratt, and Kasa methods for fitting circles; and Direct and Taubin methods for fitting ellipses) includes references, and detailed notes on the relative strengths and weaknesses of the approach. (By the way, the "Taubin Ellipse Method" will fit hyperbolas, too, if that conic section better approximates the data.)

As always, your comments are welcome, and appreciated!


Get the MATLAB code

Published with MATLAB® 7.9

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Bob, Brett & Jiro share their favorite user-contributed submissions from the File Exchange.

  • Jon: This is a useful tool - but in fairness I have to point out that it is remarkably similar to a routine of the...
  • oleg: The author has implemented skewness, kurtosis and checks answering appropriately to the critic.
  • Ashok: how to store 10 or more random number in a loop a loop for i = 1:n mean(i) = input(’enter the mean value...
  • Ben: Doug, Thanks for the very helpful videos! Uitables seem like a convenient way to make a customized property...
  • oleg: Allstats has no checks, no comments and could also be improved (talking about prctile implementatio). Not to...
  • Todd: Additional information and a link to download free MATLAB and Simulink LEGO MINDSTORMS NXT code can be found at...
  • Doug: @Leo, Here is the “English version” of that code. “vec = []” makes an empty variable...
  • leo: Dear Doug I have a question in your code ‘October 9th, 2009 at 13:53′ vec = []; vec = [vec val]; I...
  • Shanker Keshavdas: You sir, are a gentleman and a scholar… No really, helped me out a lot. As to what is...
  • Quan Zheng: how can I get a copy of stepspecs.m?

These postings are the author's and don't necessarily represent the opinions of The MathWorks.