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.

  • Zach: Hi Doug and Les, I didn’t have a lot of time to mess with this, but I did find a work-around. I plotted...
  • hamed: k
  • Les: @Zach This isn’t exactly what you are looking for but at least it puts all three parameters on the same...
  • Zach: Thanks for your suggestions Doug. I’ll give that a shot and see what happens. I’ve seen many of...
  • Doug: @Zach, I would say to use plotYYY, because that is close to what you want, but using depth as Y makes sense....
  • Doug: @Teja, I think this will work: http://www.mathworks .com/access/helpdesk /help/techdoc/ref...
  • Gify: merry christmas :) nice christmas tree! Regards, Janet Gify
  • Teja: Dear Doug Is there anyway to plot a surface from nonuniform data without meshgrid and griddata? Basically i...
  • Zach: I’m working with geophysical data, so I’d like to produce a depth profile. The y-axis would be...
  • Doug: @Ashok First, please do not use variable names that are MATLAB commands (std and mean). Second, p(j) should be...

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