{"id":674,"date":"2013-05-27T12:00:12","date_gmt":"2013-05-27T17:00:12","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=674"},"modified":"2014-03-15T13:50:55","modified_gmt":"2014-03-15T18:50:55","slug":"golden-spiral","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2013\/05\/27\/golden-spiral\/","title":{"rendered":"Golden Spiral"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>A Golden Spiral is simulated by a continuously expanding sequence of golden rectangles and inscribed quarter circles.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/golden_spiral.gif\" alt=\"\"> <\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#32e60c03-e48d-4e9d-bb5e-83a7a5f6258e\">Golden Rectangles<\/a><\/li><li><a href=\"#567cdd9d-3d73-4366-803d-23b5126f196d\">True Golden Spiral<\/a><\/li><li><a href=\"#266d9089-851d-4554-84a2-ae9494431a41\"><tt>golden_spiral.m<\/tt><\/a><\/li><\/ul><\/div><h4>Golden Rectangles<a name=\"32e60c03-e48d-4e9d-bb5e-83a7a5f6258e\"><\/a><\/h4><p>We begin with an animated .gif of an imitation Golden Spiral. You can see that removing a square from a golden rectangle leaves a smaller rectangle with the same shape.  Connecting inscribed quarter circles produces a continuously expanding spiral. The aspect ratio of the rectangles is the golden ratio.<\/p><p>$$ \\phi = \\frac{1 + \\sqrt{5}}{2} $$<\/p><p>A MATLAB function for generating these expanding golden rectangles and quarter circles is given at the end of this blog post, but this is not a true Golden Spiral.<\/p><h4>True Golden Spiral<a name=\"567cdd9d-3d73-4366-803d-23b5126f196d\"><\/a><\/h4><p>A logarithmic spiral is a curve given in polar coordinates by<\/p><p>$$ r = \\alpha e^{\\lambda \\theta} $$<\/p><p>The angular coordinate $\\theta$ must be multi-valued as the point circles around the origin multiple times.  We get the particular logarithmic spiral known as the <i>Golden Spiral<\/i> by involving the golden ratio and setting<\/p><p>$$ \\lambda = \\frac{2}{\\pi}{\\ln{\\phi}} $$<\/p><p>Then the radius is scaled powers of $\\phi$, with integer powers as $\\theta$ crosses the cartesian axes.<\/p><p>$$ r = \\alpha \\phi^{\\frac{2}{\\pi} \\theta} $$<\/p><p>Here is the plot for $0 \\le \\theta \\le 2 \\pi$.<\/p><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/spiral_pic.jpeg\" alt=\"\"> <\/p><p>I do not see any obvious analytic way to specify the scale factor $\\alpha$.  By taking $\\alpha$ = 1.48699214 the numeric values generated by the logarithmic Golden Spiral approach those generated by golden rectangles and inscribed quarter circles as the angle $\\theta$ gets large.<\/p><h4><tt>golden_spiral.m<\/tt><a name=\"266d9089-851d-4554-84a2-ae9494431a41\"><\/a><\/h4><pre>function golden_spiral\r\n% GOLDEN_SPIRAL  Explosion of golden rectangles.\r\n%    GOLDEN_SPIRAL  Constructs a continuously expanding sequence\r\n%    of golden rectangles and inscribed quarter circles.<\/pre><pre>%   Copyright 2013 Cleve Moler\r\n%   Copyright 2013 The MathWorks, Inc.<\/pre><pre>   % Initialize_variables<\/pre><pre>   % Golden ratio\r\n   phi = (1+sqrt(5))\/2;<\/pre><pre>   % Control speed of zoom\r\n   n = 256;\r\n   f = phi^(1\/n);<\/pre><pre>   % Scaling\r\n   a = 1;\r\n   s = phi;\r\n   t = 1\/(phi+1);<\/pre><pre>   % Centers\r\n   x = 0;\r\n   y = 0;<\/pre><pre>   % A square\r\n   us = [-1 1 1 -1 -1];\r\n   vs = [-1 -1 1 1 -1];<\/pre><pre>   % Four quarter circles\r\n   theta = 0:pi\/20:pi\/2;\r\n   u1 = 2*cos(theta) - 1;\r\n   v1 = 2*sin(theta) - 1;\r\n   u2 = 2*cos(theta+pi\/2) + 1;\r\n   v2 = 2*sin(theta+pi\/2) - 1;\r\n   u3 = 2*cos(theta+pi) + 1;\r\n   v3 = 2*sin(theta+pi) + 1;\r\n   u4 = 2*cos(theta-pi\/2) - 1;\r\n   v4 = 2*sin(theta-pi\/2) + 1;<\/pre><pre>   initialize_graphics<\/pre><pre>   % Loop<\/pre><pre>   k = 0;\r\n   while get(klose,'value') == 0\r\n      if mod(k,n) == 0\r\n         power\r\n         switch mod(k\/n,4)\r\n            case 0, right\r\n            case 1, up\r\n            case 2, left\r\n            case 3, down\r\n         end\r\n      end\r\n      zoom\r\n      k = k+1;\r\n   end\r\n   pause(1)\r\n   close(gcf)<\/pre><pre>% ------------------------------------<\/pre><pre>   function power\r\n      a = s;\r\n      s = phi*s;\r\n      t = phi*t;\r\n   end % power<\/pre><pre>% ------------------------------------<\/pre><pre>   function zoom\r\n      axis(f*axis)\r\n      drawnow\r\n   end % zoom<\/pre><pre>% ------------------------------------<\/pre><pre>   function right\r\n      x = x + s;\r\n      y = y + t;\r\n      line(x+a*us,y+a*vs,'color','black')\r\n      line(x+a*u4,y+a*v4)\r\n   end % right<\/pre><pre>% ------------------------------------<\/pre><pre>   function up\r\n      y = y + s;\r\n      x = x - t;\r\n      line(x+a*us,y+a*vs,'color','black')\r\n      line(x+a*u1,y+a*v1)\r\n   end % up<\/pre><pre>% ------------------------------------<\/pre><pre>   function left\r\n      x = x - s;\r\n      y = y - t;\r\n      line(x+a*us,y+a*vs,'color','black')\r\n      line(x+a*u2,y+a*v2)\r\n   end % left<\/pre><pre>% ------------------------------------<\/pre><pre>   function down\r\n      y = y - s;\r\n      x = x + t;\r\n      line(x+a*us,y+a*vs,'color','black')\r\n      line(x+a*u3,y+a*v3)\r\n   end % down<\/pre><pre>% ------------------------------------<\/pre><pre>   function initialize_graphics\r\n      clf reset\r\n      set(gcf,'color','white','menubar','none','numbertitle','off', ...\r\n          'name','Golden Spiral')\r\n      shg\r\n      axes('position',[0 0 1 1])\r\n      axis(3.5*[-1 1 -1 1])\r\n      axis square\r\n      axis off\r\n      line(us,vs,'color','black')\r\n      line(u3,v3)\r\n      klose = uicontrol('units','normal','position',[.04 .04 .12 .04], ...\r\n         'style','toggle','string','close','vis','on');\r\n      drawnow\r\n   end % initialize graphics<\/pre><pre>end % golden_spiral<\/pre><script language=\"JavaScript\"> <!-- \r\n    function grabCode_c31b753f8fba4041b53ccd322160e180() {\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='c31b753f8fba4041b53ccd322160e180 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' c31b753f8fba4041b53ccd322160e180';\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        copyright = 'Copyright 2013 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 copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\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     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_c31b753f8fba4041b53ccd322160e180()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><p class=\"footer\"><br>\r\n      Published with MATLAB&reg; R2013b<br><\/p><\/div><!--\r\nc31b753f8fba4041b53ccd322160e180 ##### SOURCE BEGIN #####\r\n%% Golden Spiral\r\n% A Golden Spiral is simulated by a continuously expanding sequence\r\n% of golden rectangles and inscribed quarter circles.\r\n%\r\n% <<golden_spiral.gif>>\r\n%\r\n\r\n%% Golden Rectangles\r\n% We begin with an animated .gif of an imitation Golden Spiral.\r\n% You can see that removing a square from a golden rectangle leaves a\r\n% smaller rectangle with the same shape.  Connecting inscribed quarter\r\n% circles produces a continuously expanding spiral.\r\n% The aspect ratio of the rectangles is the golden ratio.\r\n%\r\n% $$ \\phi = \\frac{1 + \\sqrt{5}}{2} $$\r\n%\r\n% A MATLAB function for generating these expanding golden rectangles and\r\n% quarter circles is given at the end of this blog post, but this is\r\n% not a true Golden Spiral.\r\n\r\n%% True Golden Spiral\r\n% A logarithmic spiral is a curve given in polar coordinates by\r\n%\r\n% $$ r = \\alpha e^{\\lambda \\theta} $$\r\n%\r\n% The angular coordinate $\\theta$ must be multi-valued as the point circles\r\n% around the origin multiple times.  We get the particular logarithmic spiral\r\n% known as the _Golden Spiral_ by involving the golden ratio and setting\r\n%\r\n% $$ \\lambda = \\frac{2}{\\pi}{\\ln{\\phi}} $$\r\n%\r\n% Then the radius is scaled powers of $\\phi$, with integer powers as $\\theta$\r\n% crosses the cartesian axes.\r\n%\r\n% $$ r = \\alpha \\phi^{\\frac{2}{\\pi} \\theta} $$\r\n%\r\n% Here is the plot for $0 \\le \\theta \\le 2 \\pi$.\r\n%\r\n% <<spiral_pic.jpeg>>\r\n%\r\n% I do not see any obvious analytic way to specify the scale factor\r\n% $\\alpha$.  By taking $\\alpha$ = 1.48699214 the numeric values generated\r\n% by the logarithmic Golden Spiral approach those generated by golden\r\n% rectangles and inscribed quarter circles as the angle $\\theta$ gets large.\r\n\r\n%% |golden_spiral.m|\r\n%  function golden_spiral\r\n%  % GOLDEN_SPIRAL  Explosion of golden rectangles.\r\n%  %    GOLDEN_SPIRAL  Constructs a continuously expanding sequence\r\n%  %    of golden rectangles and inscribed quarter circles.\r\n%  \r\n%  %   Copyright 2013 Cleve Moler\r\n%  %   Copyright 2013 The MathWorks, Inc.\r\n%  \r\n%     % Initialize_variables\r\n%  \r\n%     % Golden ratio\r\n%     phi = (1+sqrt(5))\/2;\r\n%  \r\n%     % Control speed of zoom\r\n%     n = 256;\r\n%     f = phi^(1\/n);\r\n%  \r\n%     % Scaling\r\n%     a = 1;\r\n%     s = phi;\r\n%     t = 1\/(phi+1);\r\n%  \r\n%     % Centers\r\n%     x = 0;\r\n%     y = 0;\r\n%  \r\n%     % A square\r\n%     us = [-1 1 1 -1 -1];\r\n%     vs = [-1 -1 1 1 -1];\r\n%  \r\n%     % Four quarter circles\r\n%     theta = 0:pi\/20:pi\/2;\r\n%     u1 = 2*cos(theta) - 1;\r\n%     v1 = 2*sin(theta) - 1;\r\n%     u2 = 2*cos(theta+pi\/2) + 1;\r\n%     v2 = 2*sin(theta+pi\/2) - 1;\r\n%     u3 = 2*cos(theta+pi) + 1;\r\n%     v3 = 2*sin(theta+pi) + 1;\r\n%     u4 = 2*cos(theta-pi\/2) - 1;\r\n%     v4 = 2*sin(theta-pi\/2) + 1;\r\n%  \r\n%     initialize_graphics\r\n%  \r\n%     % Loop\r\n%  \r\n%     k = 0;\r\n%     while get(klose,'value') == 0\r\n%        if mod(k,n) == 0\r\n%           power\r\n%           switch mod(k\/n,4)\r\n%              case 0, right\r\n%              case 1, up\r\n%              case 2, left\r\n%              case 3, down\r\n%           end\r\n%        end\r\n%        zoom \r\n%        k = k+1;\r\n%     end\r\n%     pause(1)\r\n%     close(gcf)\r\n%  \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%  \r\n%     function power\r\n%        a = s;\r\n%        s = phi*s;\r\n%        t = phi*t;\r\n%     end % power\r\n%     \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%  \r\n%     function zoom\r\n%        axis(f*axis)\r\n%        drawnow\r\n%     end % zoom\r\n%     \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%  \r\n%     function right\r\n%        x = x + s;\r\n%        y = y + t;\r\n%        line(x+a*us,y+a*vs,'color','black')\r\n%        line(x+a*u4,y+a*v4)\r\n%     end % right\r\n%  \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%     \r\n%     function up\r\n%        y = y + s;\r\n%        x = x - t;\r\n%        line(x+a*us,y+a*vs,'color','black')\r\n%        line(x+a*u1,y+a*v1)\r\n%     end % up\r\n%  \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%     \r\n%     function left\r\n%        x = x - s;\r\n%        y = y - t;\r\n%        line(x+a*us,y+a*vs,'color','black')\r\n%        line(x+a*u2,y+a*v2)\r\n%     end % left\r\n%  \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%     \r\n%     function down\r\n%        y = y - s;\r\n%        x = x + t;\r\n%        line(x+a*us,y+a*vs,'color','black')\r\n%        line(x+a*u3,y+a*v3)\r\n%     end % down\r\n%  \r\n%  % REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH\r\n%     \r\n%     function initialize_graphics\r\n%        clf reset\r\n%        set(gcf,'color','white','menubar','none','numbertitle','off', ...\r\n%            'name','Golden Spiral')\r\n%        shg\r\n%        axes('position',[0 0 1 1]) \r\n%        axis(3.5*[-1 1 -1 1])\r\n%        axis square\r\n%        axis off\r\n%        line(us,vs,'color','black')\r\n%        line(u3,v3)\r\n%        klose = uicontrol('units','normal','position',[.04 .04 .12 .04], ...\r\n%           'style','toggle','string','close','vis','on');\r\n%        drawnow\r\n%     end % initialize graphics\r\n%  \r\n%  end % golden_spiral\r\n\r\n##### SOURCE END ##### c31b753f8fba4041b53ccd322160e180\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/cleve\/golden_spiral.gif\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>A Golden Spiral is simulated by a continuously expanding sequence of golden rectangles and inscribed quarter circles.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2013\/05\/27\/golden-spiral\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,23],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/674"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=674"}],"version-history":[{"count":13,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/674\/revisions"}],"predecessor-version":[{"id":935,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/674\/revisions\/935"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}