Q: TikZ — logarithmic (golden) spiral in a golden rectangle I'm almost happy with my golden spiral in golden rectangles:
    \documentclass[a4paper,class=article,border=5pt,tikz]{standalone}
    \usepackage{fp}
    \usetikzlibrary{fixedpointarithmetic}

    \begin{document}
    \begin{tikzpicture}[thick, scale=4]
        \pgfmathsetmacro{\w}{1}
        \pgfmathsetmacro{\h}{\w*(2/(1+sqrt(5)))}
        \pgfmathsetmacro{\dx}{(-(\h/(\h-\w))*\w)/((\h/\w)-(\h/(\h-\w)))}
        \pgfmathsetmacro{\dy}{(\h/\w)*\dx}

        \draw (0,0) rectangle (\w,\h);
        \draw (\h,0) -- (\h,\h); 
        \draw (\h,{\w-\h}) -- (\w,{\w-\h});        
        \draw ({2*\w-2*\h)},{\w-\h}) -- ({2*\w-2*\h},\h);      
        \draw (\h,{4*\h-2*\w}) -- ({2*\w-2*\h)},{4*\h-2*\w});
        \draw ({6*\h-3*\w},{4*\h-2*\w}) -- ({6*\h-3*\w},{\w-\h});
        \draw ({6*\h-3*\w},{6*\w-9*\h}) -- ({2*\w-2*\h},{6*\w-9*\h});
        \draw ({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[red, rotate around={{-atan((2*\h-\w)/\w)}:(\dx,\dy)}, domain=0:6*pi, variable=\t, samples=300] 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:

