{"id":2413,"date":"2009-04-10T11:00:06","date_gmt":"2009-04-10T11:00:06","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2009\/04\/10\/fitting-circles-again-and-ellipses\/"},"modified":"2017-01-06T21:23:10","modified_gmt":"2017-01-07T02:23:10","slug":"fitting-circles-again-and-ellipses","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2009\/04\/10\/fitting-circles-again-and-ellipses\/","title":{"rendered":"Fitting Circles (again) and Ellipses"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+chernov\">suite of fitting functions<\/a> by Nikolai.\r\n      <\/p>\r\n   <\/introduction>\r\n   <p>Just over a year ago, I <a href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/14\/fitting-a-circle-easily\/\">highlighted in this blog<\/a> a useful bit of code for fitting circles to data. I pointed out that I have had numerous opportunities to use the code over\r\n      the years, and that I have had good success with it.\r\n   <\/p>\r\n   <p>That blog entry sparked some interesting comments, including an intriguing one from <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/41620\">Nikolai Chernov<\/a>. Now, I readily admit to being naive about the topic. If you search the File Exchange for the words \"fit circle,\" you'll\r\n      find at least <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+circle\">9 different relevant submissions<\/a> for peforming the task. Without additional information, you're pretty much on your own to figure out which one to use. What\r\n      struck me about Nikolai's comment was that not only did he reveal the name of the method implemented in <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/1583\">Izhak<\/a>'s <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/5557-circle-fit\">code<\/a> (it's referred to as the \"Kasa method\"), he also described the conditions under which it was a reasonable approach (\"it works\r\n      well when points cover a large part of the circle but is heavily biased when points are restricted to a small arc\"). With\r\n      a link to his <a href=\"http:\/\/www.math.uab.edu\/~chernov\/cl\">UAB website<\/a>, Nikolai shared his impressive body of work on circle-fitting and ellipse-fitting, and provided access to his m-code implementations\r\n      thereof.\r\n   <\/p>\r\n   <p>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,\r\n      he was quick to comply with my request. Nikolai's <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+chernov\">suite of fitting functions<\/a> is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911\">Brett<\/a>'s choice for this week's Pick of the Week.\r\n   <\/p>\r\n\r\n   <p>Each of the five files (Taubin, Pratt, and Kasa methods for fitting circles; and Direct and Taubin methods for fitting ellipses)\r\n      includes references, and detailed notes on the relative strengths and weaknesses of the approach. (By the way, the \"Taubin\r\n      Ellipse Method\" will fit hyperbolas, too, if that conic section better approximates the data.)\r\n   <\/p>\r\n   <p>As always, your <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2413#respond\">comments<\/a> are welcome, and appreciated!\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_8037ed43f3b74d1a93be85d075b40c85() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='8037ed43f3b74d1a93be85d075b40c85 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 8037ed43f3b74d1a93be85d075b40c85';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Robert Bemis';\r\n        copyright = 'Copyright 2009 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_8037ed43f3b74d1a93be85d075b40c85()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.9<br><\/p>\r\n<\/div>\r\n<!--\r\n8037ed43f3b74d1a93be85d075b40c85 ##### SOURCE BEGIN #####\r\n%% Fitting Circles (again) and Ellipses\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s \r\n% pick this week is \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+chernov suite of fitting functions>\r\n% by Nikolai.\r\n%%\r\n% Just over a year ago, I <https:\/\/blogs.mathworks.com\/pick\/2008\/03\/14\/fitting-a-circle-easily\/ highlighted in this blog> a useful bit\r\n% of code for fitting circles to data. I pointed out that I have\r\n% had numerous opportunities to use the code over the years, and\r\n% that I have had good success with it.\r\n%\r\n%% \r\n% That blog entry sparked some interesting comments, including\r\n% an intriguing one from\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/41620 Nikolai Chernov>. \r\n% Now, I readily admit to being naive about the topic. If you search the File Exchange \r\n% for the words \"fit circle,\" you'll find at least \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+circle 9 different relevant submissions>\r\n% for peforming the task. Without additional information, you're\r\n% pretty much on your own to figure out which one to use. What\r\n% struck me about Nikolai's comment was that not only did he\r\n% reveal the name of the method implemented in  \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/1583 Izhak>'s \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/5557-circle-fit code> \r\n% (it's referred to as the \"Kasa method\"), he also described the conditions \r\n% under which it was a reasonable approach (\"it works well when points cover a large \r\n% part of the circle but is heavily biased when points are restricted to a small arc\").\r\n% With a link to his <http:\/\/www.math.uab.edu\/~chernov\/cl UAB website>, \r\n% Nikolai shared his impressive body of work on circle-fitting and ellipse-fitting,\r\n% and provided access to his m-code implementations thereof.\r\n%\r\n%%\r\n% In a follow-up email, I asked Nikolai to put his files on\r\n% the File Exchange; his work was too good not to share! Happily, he was quick to\r\n% comply with my request. Nikolai's\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+chernov\r\n% suite of fitting functions> \r\n% is <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s choice\r\n% for this week's Pick of the Week.\r\n\r\n%%\r\n% \r\n% <<https:\/\/www.mathworks.com\/matlabcentral\/fx_files\/22683\/1\/ellipse.png>>\r\n% \r\n\r\n%%\r\n% Each of the five files (Taubin, Pratt, and Kasa methods for\r\n% fitting circles; and Direct and Taubin methods for fitting\r\n% ellipses) includes references, and detailed notes on the\r\n% relative strengths and weaknesses of the approach. (By the way,\r\n% the \"Taubin Ellipse Method\" will fit hyperbolas, too, if that\r\n% conic section better approximates the data.)\r\n\r\n%%\r\n% As always, your \r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=2413#respond comments> \r\n% are welcome, and appreciated!\r\n\r\n##### SOURCE END ##### 8037ed43f3b74d1a93be85d075b40c85\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n      Brett's pick this week is suite of fitting functions by Nikolai.\r\n      \r\n   \r\n   Just over a year ago, I highlighted in this blog a useful bit of code for fitting circles... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2009\/04\/10\/fitting-circles-again-and-ellipses\/\">read more >><\/a><\/p>","protected":false},"author":34,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2413"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/34"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2413"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2413\/revisions"}],"predecessor-version":[{"id":8323,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2413\/revisions\/8323"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2413"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2413"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2413"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}