# TikZ — logarithmic (golden) spiral in a golden rectangle [closed]

I'm almost happy with my golden spiral in golden rectangles:

\documentclass[12pt, border=0.5mm]{standalone}

\usepackage{etex}
\usepackage{graphicx}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{calc, arrows, shapes}
\usepackage{fp}
\usetikzlibrary{fixedpointarithmetic}

\begin{document}

\begin{tikzpicture}[x=1mm, y=1mm]

\pgfmathsetmacro{\w}{98}
\pgfmathsetmacro{\h}{\w*(2/(1+sqrt(5)))}

\pgfmathsetmacro{\dx}{(-(\h/(\h-\w))*\w)/((\h/\w) - (\h/(\h-\w)))}
\pgfmathsetmacro{\dy}{(\h/\w)*\dx}

\draw[line width=0.01mm] (0, 0) rectangle (\w, \h);

\draw[line width=0.01mm] (\h, 0) -- (\h, \h);
\draw[line width=0.01mm] (\h, {\w-\h}) -- (\w, {\w-\h});
\draw[line width=0.01mm] ({2*\w-2*\h)}, {\w-\h}) -- ({2*\w-2*\h}, \h);
\draw[line width=0.01mm] (\h, {4*\h-2*\w}) -- ({2*\w-2*\h)}, {4*\h-2*\w});
\draw[line width=0.01mm] ({6*\h-3*\w}, {4*\h-2*\w}) -- ({6*\h-3*\w}, {\w-\h});
\draw[line width=0.01mm] ({6*\h-3*\w}, {6*\w-9*\h}) -- ({2*\w-2*\h}, {6*\w-9*\h});
\draw[line width=0.01mm] ({2*\w-2*\h-13*\h+8*\w}, {4*\h-2*\w}) -- ({2*\w-2*\h-13*\h+8*\w}, {4*\h-2*\w-13*\h+8*\w});

\pgfmathsetmacro{\a}{(-2/pi)*ln((1+sqrt(5))/2)}
\pgfmathsetmacro{\d}{sqrt(pow(\dx, 2) + pow((\dy - \h), 2))}

\draw[rotate around={{-atan((2*\h-\w)/\w)}:(\dx,\dy)}, line width=0.01mm, domain=0:6*pi, variable=\t, samples=5000]
plot[fixed point arithmetic] ({\dx-\d*exp(\a*\t)*cos(deg(\t))}, {\dy-\d*exp(\a*\t)*sin(deg(\t))});

\end{tikzpicture}


\end{document}

But even with 5000 samples and very thin lines there is a small problem:

The logarithmic spiral should stay inside the box, but it doesn't. The spirals here have the same problem as mine. Is there a way to fix this?

The line width is not the problem. It's getting even worse with thinner lines of same width:

## closed as off-topic by Jake, Torbjørn T., Martin Schröder, user13907, Henri MenkeJan 3 '16 at 15:40

• This question does not fall within the scope of TeX, LaTeX or related typesetting systems as defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

• Is that from the double line width (0.2mm spiral, 0.1mm grid)? Does it vanish if you set the spiral to 0.1mm? – Tom Bombadil Nov 27 '15 at 1:20
• Please post complete code! Completing your code in the most obvious way, I just get gazillions of errors. – cfr Nov 27 '15 at 3:03
• No, the line width is not the problem. – GeMir Nov 27 '15 at 5:45
• I believe this is the correct result: The golden spiral passes through the points that divide the golden rectangles, but it's not tangent to the rectangle borders at these points. Take a look at Fig. 34 in Spirals and the Golden Section or see Golden Rectangle on Wolfram MathWorld – Jake Nov 27 '15 at 9:41
• @Jake An answer? (Or is this off-topic as it's about maths, or ...? – Joseph Wright Dec 17 '15 at 11:12