{"id":2152,"date":"2008-03-21T13:01:39","date_gmt":"2008-03-21T18:01:39","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/21\/drawing-a-circle\/"},"modified":"2016-05-10T15:19:21","modified_gmt":"2016-05-10T19:19:21","slug":"drawing-a-circle","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/21\/drawing-a-circle\/","title":{"rendered":"Drawing a Circle"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<i>You may have noticed some recent changes in the format of this blog. Here\u2019s what to expect on a regular basis \u2013 two topics\r\nper week.<\/i>\r\n\r\n&nbsp;\r\n<div>\r\n<ul>\r\n\t<li><i>On Tuesdays Doug will provide MATLAB tutorials.<\/i><\/li>\r\n\t<li><i>On Fridays guest bloggers Jiro, Brett and Bob will highlight File Exchange submissions.<\/i><\/li>\r\n<\/ul>\r\n<\/div>\r\nIn <a href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/14\/fitting-a-circle-easily\/\">last week's Pick of the Week<\/a>, I talked about fitting a circle to a collection of points. With a small example, I showed how Izhak\r\nBucher's <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=5557&amp;objectType=FILE (link no longer works)\">CircFit<\/a> makes short work of that task. But to visualize the circle I fit through my faked data, I used MATLAB's rectangle command!\r\nIf that seems odd to you, then this week's pick is for you: Zhenhai Wang's <a title=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=2876&amp;objectType=FILE (link no longer works)\">Draw a Circle<\/a> submission lets you visualize your circle with (to me) a much more natural syntax, specifying the coordinates of the center,\r\nthe radius of the circle, and the number of points to plot. Optionally, the file also lets you specify the style parameters\r\nfor the plotted curve.\r\n\r\nFor instance:\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">R = 10;\r\nCenter = [5,8];\r\ncircle(Center,R,1000,<span style=\"color: #a020f0;\">'b-'<\/span>);\r\nhold <span style=\"color: #a020f0;\">on<\/span>\r\nplot(Center(1),Center(2),<span style=\"color: #a020f0;\">'g.'<\/span>)<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/circle_potw_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\nOkay, so you may be thinking that plotting a circle with this syntax isn't the most difficult thing you've ever tried to do.\r\nStill, nearly 24,000 people have downloaded Zhenhai's file! This suggests that it might not be trivially easy, either. Or\r\nat least, that it's awfully convenient to be just be the beneficiary of someone else's work. And \"Draw a Circle\" is pretty\r\nwell vetted, too; it has an average of 4.29 (out of 5) stars, from 42 reviews. That means a lot of people are happy with Zhenhai's\r\neffort. In fact, years after its submission, \"Draw a Circle\" continues to get hundreds of downloads every month (661 in the\r\npast 30 days). Moreover, two other files cite this week's selection as an inspiration. Nice work, Zhenhai!\r\n\r\nGot a favorite plotting routine that makes your life easier? Let us know about it!\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_42535c0b40794d7985aa4488ca8bca38() {\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='42535c0b40794d7985aa4488ca8bca38 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 42535c0b40794d7985aa4488ca8bca38';\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 = 'Brett Shoelson';\r\n        copyright = 'Copyright 2008 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<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>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae 7.6<\/p>\r\n\r\n<\/div>\r\n<!--\r\n42535c0b40794d7985aa4488ca8bca38 ##### SOURCE BEGIN #####\r\n%%\r\n% _You may have noticed some recent changes in the format of this blog. Here\u00e2\u20ac\u2122s\r\n% what to expect on a regular basis \u00e2\u20ac\u201c two topics per week._\r\n%%\r\n% * _On Tuesdays Doug will provide MATLAB tutorials._\r\n% * _On Fridays guest bloggers Jiro, Brett and Bob will highlight File\r\n% Exchange submissions._\r\n%%\r\n% In last week's (*** REF) Pick of the Week, I talked about fitting a\r\n% circle to a collection of points. With a small example, I showed how\r\n% Izhak Bucher's <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=5557&objectType=FILE CircFit> makes short work of that task. But to\r\n% visualize the circle I fit through my faked data, I used MATLAB's\r\n% rectangle command! If that seems odd to you, then this week's pick is for\r\n% you:\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadAuthor.do?objectType=author&objectId=965875 Zhenhai Wang>'s\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/loadFile.do?objectId=2876&objectType=FILE Draw a Circle> submission lets you visualize your\r\n% circle with (to me) a much more natural syntax, specifying the\r\n% coordinates of the center, the radius of the circle, and the number of\r\n% points to plot. Optionally, the file also lets you specify the style\r\n% parameters for the plotted curve.\r\n\r\n%%\r\n% For instance:\r\nR = 10;\r\nCenter = [5,8];\r\ncircle(Center,R,1000,'b-');\r\nhold on\r\nplot(Center(1),Center(2),'g.')\r\n\r\n%%\r\n% Okay, so you may be thinking that plotting a circle with this syntax\r\n% isn't the most difficult thing you've ever tried to do. Still, nearly\r\n% 24,000 people have downloaded Zhenhai's file! This suggests that it might\r\n% not be trivially easy, either. Or at least, that it's awfully convenient\r\n% to be just be the beneficiary of someone else's work. And \"Draw a Circle\"\r\n% is pretty well vetted, too; it has an average of 4.29 (out of 5) stars,\r\n% from 42 reviews. That means a lot of people are happy with Zhenhai's\r\n% effort. In fact, years after its submission, \"Draw a Circle\" continues to\r\n% get hundreds of downloads every month (661 in the past 30 days).\r\n% Moreover, two other files cite this week's selection as an inspiration.\r\n% Nice work, Zhenhai!\r\n\r\n%%\r\n% Got a favorite plotting routine that makes your life easier? Let us know\r\n% about it!\r\n\r\n##### SOURCE END ##### 42535c0b40794d7985aa4488ca8bca38\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n\r\nYou may have noticed some recent changes in the format of this blog. Here\u2019s what to expect on a regular basis \u2013 two topics\r\nper week.\r\n\r\n&nbsp;\r\n\r\n\r\n\tOn Tuesdays Doug will provide MATLAB... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/21\/drawing-a-circle\/\">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\/2152"}],"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=2152"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2152\/revisions"}],"predecessor-version":[{"id":7109,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2152\/revisions\/7109"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}