[Tex/LaTex] Golden spiral in TiKZ: how to get the right shape and background

tikz-pgf

I want to use tikz to draw a golden spiral, growing clockwise, ideally (but not necessarily) superimposed over a set of golden rectangles (you all know the image I'm talking about). A little bit of searching led me to this code, which yields a counterclockwise spiral:

\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.markings,calc}
\tikzset{nctopath/.style={
     to path=(\tikztostart) ..controls ($(\tikztostart)!1cm*#1!-90:(\tikztotarget)$) and 
        ($(\tikztotarget)!($(\tikztostart)!1cm*#1!-50:(\tikztotarget)$)!70:    (\tikztostart)$).. 
    (\tikztotarget)
    },
}
\begin{document}    
\begin{tikzpicture}
\def\totx{1}
\coordinate (n-1-1) at (0,0) {};
\foreach \x[count=\xi from 2, evaluate=\x as \temptotx using int(\x+\totx)] in {1,...,9}{
\draw[decoration={
    markings,mark=between positions 0 and 1 step 0.249 with {
            \coordinate (n-\x-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number})     ;
        }
   },postaction=decorate
] 
(n-\x-1) arc (\x*90+180:(\x+1)*90+180:{(\temptotx)*3mm}) 
coordinate (n-\xi-1) 
\pgfextra{\xdef\totx{\temptotx}};
}

\end{tikzpicture}
\end{document}

The thing is that I'm still new to tikz and thus not sure what code here does what. My questions are:

  1. How do I reverse the growth direction?

  2. How do I set phi as the growth factor (which I don't think it is currently, just from looking at the resulting spiral)?

  3. How cumbersome would it be to add in the golden rectangles (i.e., would I have to draw each one individually, or is there some way to define a pattern)?

Best Answer

Basically, the same approach as JLDiaz but using a recursive macro and letting tikz scopes and transformations do all the work.

\documentclass[tikz, border=0.125cm]{standalone}
\begin{document}

\def\spiral#1{%
  \pgfmathparse{int(#1)}%
  \ifnum\pgfmathresult>0
    \draw [help lines] (0,0) rectangle ++(1,1);
    \begin{scope}[shift={(1,1)}, rotate=90, scale=1/1.6180339887]
      \spiral{#1-1}
    \end{scope}
    \draw [red] (0,0) arc (270:360:1);
  \fi
}

\tikz[scale=2]{\spiral{12}}

\end{document}

enter image description here

And perhaps...

\documentclass[border=0.125cm, tikz]{standalone}

\begin{document}

\def\spiral#1#2#3{%
  \pgfmathparse{int(#1)}%
  \ifnum\pgfmathresult>0
    \draw [help lines] (0,0) rectangle ++(1,1);
    \begin{scope}[shift={(1,1)}, rotate=#2, scale=1/#3]
      \spiral{#1-1}{#2}{#3}%
    \end{scope}
    \pgfmathparse{int(\a)}%
    \ifnum\pgfmathresult=0
      \draw [red] (0,0) -- (1,1);
    \else%
      \draw [red] (0,0) arc (270+45-#2/2:360-45+#2/2:{1/sqrt(2) / sin(#2/2)});
    \fi
  \fi
}

\foreach \a in {90,85,...,-90,-85,-80,...,85}{
 \tikz[scale=2]{\spiral{12}{\a}{1.6180339887}\useasboundingbox (-0.5,-0.5) rectangle (3.5,3.5);}
}

\end{document}

enter image description here