{"id":2939,"date":"2011-11-11T13:08:52","date_gmt":"2011-11-11T13:08:52","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2011\/11\/11\/3d-polar-plotting\/"},"modified":"2011-11-11T13:08:52","modified_gmt":"2011-11-11T13:08:52","slug":"3d-polar-plotting","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2011\/11\/11\/3d-polar-plotting\/","title":{"rendered":"3D Polar Plotting"},"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\/1320-circuit-level-analog---mixed-signal-examples-3d-polar-plot\">polarplot3d,<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/18049\">Ken Garrard<\/a>.\r\n   <\/p>\r\n   <p>I don't often get suggestions from readers of this blog for which files to feature. Typically, I just focus on files that\r\n      I've found, or that look useful or intriguing based on descriptions and comments. This week is different; I received an email\r\n      from long-time MATLABber <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/27420\">Yair Altman<\/a>, suggesting that I consider Ken's file as a Pick of the Week. Yair is one of the most downloaded authors on the MATLAB Central\r\n      File Exchange (and is recognized as an expert in \"undocumented MATLAB.\") So I was quite pleased to see his recommendation\r\n      come in, and happier still to be able to feature it.\r\n   <\/p>\r\n   <p>Ken's code allows you to easily plot a 3D surface from polar coordinate data. With an easy-to-use syntax, his code supports\r\n      the creation of several standard (and some custom) plot types, including surface plots (with and without lines, and with and\r\n      without contours) and mesh plots (with and without contours). You can also specify lots of different parameters, including\r\n      the polar direction (cw or ccw), the type of interpolation, and the color scheme. Optional outputs readily provide the Cartesian\r\n      locations corresponding to input polar coordinates (T,R,Zp). To illustrate, here is Ken's own example from his code:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">[t,r] = meshgrid(linspace(0,2*pi,361),linspace(-4,4,101));\r\n[x,y] = pol2cart(t,r);\r\nP = peaks(x,y);                       <span style=\"color: #228B22\">% peaks function on a polar grid<\/span>\r\n\r\nfigure(<span style=\"color: #A020F0\">'color'<\/span>,<span style=\"color: #A020F0\">'white'<\/span>);              <span style=\"color: #228B22\">% draw 3d polar plot<\/span>\r\npolarplot3d(P,<span style=\"color: #A020F0\">'PlotType'<\/span>,<span style=\"color: #A020F0\">'surfn'<\/span>,<span style=\"color: #A020F0\">'PolarGrid'<\/span>,{4 24},<span style=\"color: #A020F0\">'TickSpacing'<\/span>,8,<span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'AngularRange'<\/span>,[30 270]*pi\/180,<span style=\"color: #A020F0\">'RadialRange'<\/span>,[.8 4]);\r\n\r\n<span style=\"color: #228B22\">% set plot attributes<\/span>\r\nset(gca,<span style=\"color: #A020F0\">'DataAspectRatio'<\/span>,[1 1 10],<span style=\"color: #A020F0\">'View'<\/span>,[-12,38],<span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Xlim'<\/span>,[-4.5 4.5],<span style=\"color: #A020F0\">'Xtick'<\/span>,[-4 -2 0 2 4],<span style=\"color: #0000FF\">...<\/span>\r\n    <span style=\"color: #A020F0\">'Ylim'<\/span>,[-4.5 4.5],<span style=\"color: #A020F0\">'Ytick'<\/span>,[-4 -2 0 2 4]);\r\ntitle(<span style=\"color: #A020F0\">'polarplot3d example'<\/span>);<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/polarplot3d_potw_01.png\"> <p>As always, <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2939#respond\">comments to this blog post<\/a> are welcome. Or leave a comment for Ken <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/1320-circuit-level-analog---mixed-signal-examples-3d-polar-plot#comments\">here<\/a>. And if you have any suggestions for files (other than your own, please) that you think should be considered as a future\r\n      Pick of the Week, please email me! I can be reached directly at:\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">char(cumsum(<span style=\"color: #0000FF\">...<\/span>\r\n    [98 16 -13 15 0 -70 69 -11 7 -10 7 7 -4 -1 <span style=\"color: #0000FF\">...<\/span>\r\n    -46 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2]));<\/pre><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_6d06fc8b40074436a5b9835f6d221703() {\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='6d06fc8b40074436a5b9835f6d221703 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 6d06fc8b40074436a5b9835f6d221703';\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_6d06fc8b40074436a5b9835f6d221703()\"><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\n6d06fc8b40074436a5b9835f6d221703 ##### SOURCE BEGIN #####\r\n%% 3D Polar Plotting\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\/1320-circuit-level-analog---mixed-signal-examples-3d-polar-plot polarplot3d,> by \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/18049 Ken Garrard>.\r\n\r\n%%\r\n% I don't often get suggestions from readers of this blog\r\n% for which files to feature. Typically, I just focus on\r\n% files that I've found, or that look useful or intriguing\r\n% based on descriptions and comments. This week is\r\n% different; I received an email from long-time MATLABber\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/27420 Yair Altman>, \r\n% suggesting that I consider Ken's file as a Pick of the\r\n% Week. Yair is one of the most downloaded authors on the\r\n% MATLAB Central File Exchange (and is recognized as an\r\n% expert in \"undocumented MATLAB.\") So I was quite pleased\r\n% to see his recommendation come in, and happier still to be\r\n% able to feature it.\r\n\r\n%%\r\n% Ken's code allows you to easily plot a 3D surface from\r\n% polar coordinate data. With an easy-to-use syntax, his\r\n% code supports the creation of several standard (and some custom) plot\r\n% types, including surface plots (with and without lines,\r\n% and with and without contours) and mesh plots (with and\r\n% without contours). You can also specify lots of different\r\n% parameters, including the polar direction (cw or ccw), the\r\n% type of interpolation, and the color scheme. Optional outputs\r\n% readily provide the Cartesian locations corresponding to\r\n% input polar coordinates (T,R,Zp). To illustrate, here is\r\n% Ken's own example from his code:\r\n\r\n%%\r\n[t,r] = meshgrid(linspace(0,2*pi,361),linspace(-4,4,101));\r\n[x,y] = pol2cart(t,r);\r\nP = peaks(x,y);                       % peaks function on a polar grid\r\n\r\nfigure('color','white');              % draw 3d polar plot\r\npolarplot3d(P,'PlotType','surfn','PolarGrid',{4 24},'TickSpacing',8,...\r\n    'AngularRange',[30 270]*pi\/180,'RadialRange',[.8 4]);\r\n\r\n% set plot attributes\r\nset(gca,'DataAspectRatio',[1 1 10],'View',[-12,38],...\r\n    'Xlim',[-4.5 4.5],'Xtick',[-4 -2 0 2 4],...\r\n    'Ylim',[-4.5 4.5],'Ytick',[-4 -2 0 2 4]);\r\ntitle('polarplot3d example');\r\n\r\n%% \r\n% As always, <https:\/\/blogs.mathworks.com\/pick\/?p=2939#respond comments to this blog post> are welcome. Or leave a\r\n% comment for Ken\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/1320-circuit-level-analog---mixed-signal-examples-3d-polar-plot#comments here>.\r\n% And if you have any suggestions for files (other than your\r\n% own, please) that you think should be considered as a\r\n% future Pick of the Week, please email me! I can be\r\n% reached directly at:\r\nchar(cumsum(...\r\n    [98 16 -13 15 0 -70 69 -11 7 -10 7 7 -4 -1 ...\r\n    -46 45 -12 19 -12 15 -8 3 -7 8 -69 53 12 -2]));\r\n##### SOURCE END ##### 6d06fc8b40074436a5b9835f6d221703\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   \r\n   Brett's Pick this week is polarplot3d, by Ken Garrard.\r\n   \r\n   I don't often get suggestions from readers of this blog for which files to feature. Typically, I just focus on files that\r\n  ... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2011\/11\/11\/3d-polar-plotting\/\">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\/2939"}],"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=2939"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2939\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}