{"id":2934,"date":"2011-10-21T13:01:18","date_gmt":"2011-10-21T13:01:18","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/21\/drawing-ellipses\/"},"modified":"2011-10-21T13:01:18","modified_gmt":"2011-10-21T13:01:18","slug":"drawing-ellipses","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/21\/drawing-ellipses\/","title":{"rendered":"Drawing Ellipses"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction><\/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\/289-ellipse-m\">ellipse,<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2263\">David Long<\/a>.\r\n   <\/p>\r\n   <p>I've blogged before about <a href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/14\/fitting-a-circle-easily\/\">fitting circles<\/a>, and about simply <a href=\"https:\/\/blogs.mathworks.com\/pick\/2008\/03\/21\/drawing-a-circle\/\">drawing circles<\/a>. And I've blogged about <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+chernov\">fitting ellipses<\/a>. I like the general utility of functionality that facilitates those common tasks. Today, I complete the suite with a Pick\r\n      that trivializes the drawing of an ellipse.\r\n   <\/p>\r\n   <p>David's syntax is quite nice:<\/p>\r\n   <p><tt>h=ellipse(ra,rb,ang,x0,y0,C,Nb);<\/tt><\/p>\r\n   <p>There are defaults for all of the inputs (you'd get a circle of radius 1, plotted at [0,0]), but most usefully, you would\r\n      specify, at a minimum, the semi-major (<tt>ra<\/tt>) and semi-minor (<tt>rb<\/tt>) axes lengths, the desired angle, and the coordinates of the center (plus, optionally, the color and the number of points\r\n      used in the construction).\r\n   <\/p>\r\n   <p>Remember Spirograph? Here's a fun little graphic I created using David's ellipse function, and another previous pick, <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/29702-generate-maximally-perceptually-distinct-colors\">distinguishable_colors<\/a>:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">colors = distinguishable_colors(20);\r\nn = 20;\r\nangles = linspace(0,2*pi,n);\r\nh = zeros(n,1);\r\n<span style=\"color: #0000FF\">for<\/span> ii = 1:n\r\n   h(ii) = ellipse(2,1,angles(ii),0,0,colors(ii,:));\r\n<span style=\"color: #0000FF\">end<\/span>\r\naxis <span style=\"color: #A020F0\">equal<\/span>\r\naxis <span style=\"color: #A020F0\">off<\/span>\r\nset(h,<span style=\"color: #A020F0\">'linewidth'<\/span>,2)\r\nset(gcf,<span style=\"color: #A020F0\">'color'<\/span>,<span style=\"color: #A020F0\">'w'<\/span>)<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/ellipse_potw_01.png\"> <p>As always, <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2934#respond\">comments to this blog post<\/a> are welcome. Or leave a comment for David <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/289-ellipse-m#comments\">here<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_2d519d99306f422fba81ca77d332c863() {\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='2d519d99306f422fba81ca77d332c863 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 2d519d99306f422fba81ca77d332c863';\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 2011 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_2d519d99306f422fba81ca77d332c863()\"><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.13<br><\/p>\r\n<\/div>\r\n<!--\r\n2d519d99306f422fba81ca77d332c863 ##### SOURCE BEGIN #####\r\n%% Determine File Dependencies\r\n%% \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/911 Brett>'s Pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/289-ellipse-m ellipse,> by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/2263 David Long>.\r\n\r\n%%\r\n% I've blogged before about <https:\/\/blogs.mathworks.com\/pick\/2008\/03\/14\/fitting-a-circle-easily\/ fitting circles>, and about\r\n% simply <https:\/\/blogs.mathworks.com\/pick\/2008\/03\/21\/drawing-a-circle\/ drawing circles>. \r\n% And I've blogged about <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=fit+chernov fitting ellipses>. I like the general utility of functionality that\r\n% facilitates those common tasks. Today, I complete the\r\n% suite with a Pick that trivializes the drawing of an\r\n% ellipse.\r\n\r\n%%\r\n% David's syntax is quite nice:\r\n\r\n%%\r\n% |h=ellipse(ra,rb,ang,x0,y0,C,Nb);|\r\n\r\n%% \r\n% There are defaults for all of the inputs (you'd get a\r\n% circle of radius 1, plotted at [0,0]), but most usefully,\r\n% you would specify, at a minimum, the\r\n% semi-major (|ra|) and semi-minor (|rb|) axes lengths, the desired angle, and the\r\n% coordinates of the center (plus, optionally, the color and\r\n% the number of points used in the construction).\r\n\r\n%% \r\n% Remember Spirograph? Here's a fun little graphic I created using David's\r\n% ellipse function, and another previous pick,\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/29702-generate-maximally-perceptually-distinct-colors distinguishable_colors>:\r\n\r\ncolors = distinguishable_colors(20);\r\nn = 20;\r\nangles = linspace(0,2*pi,n);\r\nh = zeros(n,1);\r\nfor ii = 1:n\r\nh(ii) = ellipse(2,1,angles(ii),0,0,colors(ii,:));\r\nend\r\naxis equal\r\naxis off\r\nset(h,'linewidth',2)\r\nset(gcf,'color','w')\r\n\r\n%% \r\n% As always, <https:\/\/blogs.mathworks.com\/pick\/?p=2934#respond comments to this blog post> are welcome. Or leave a\r\n% comment for David <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/289-ellipse-m#comments here>.\r\n##### SOURCE END ##### 2d519d99306f422fba81ca77d332c863\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   Brett's Pick this week is ellipse, by David Long.\r\n   \r\n   I've blogged before about fitting circles, and about simply drawing circles. And I've blogged about fitting ellipses. I like the... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/10\/21\/drawing-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\/2934"}],"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=2934"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2934\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}