# How can I draw this spiral (with vertical sides) in tikz?

How can I draw this spiral (with vertical sides) in tikz?

The only way I would know how, would be to copy and paste code to draw semicircles of different radius, followed by connecting the semicircles one at a time, which would take a very long time.

• Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – L. F. May 12 at 5:45

I hope nobody gets mad at me for reopening the question but I feel that for the first question one may make exceptions. Instead of copying you could use foreach.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\vlength{3}
\def\hstep{0.6}
\def\Xmax{9}
\fill[gray!40] ({-(\Xmax+3)*\hstep},-\vlength)
rectangle (\hstep/2,\vlength);
\draw[thick,dashed] (-1*\hstep,\vlength)
-- (-1*\hstep,-\vlength)
foreach \X in {1,...,\Xmax}
{\ifodd\X
--  ({\hstep*(\X+1)},\vlength)
\else
--  ({-\hstep*(\X+1)},-\vlength)
\fi}
--  ({-\hstep*(\Xmax+2)},-1*\vlength);
\draw[thick] (-1*\hstep,\vlength)
-- (0,-\vlength)
(\hstep,-1*\vlength)
foreach \X in {1,...,\Xmax}
{\ifodd\X
-- (\hstep*\X,\vlength)
\else
-- ({-\hstep*\X},-1*\vlength)
\fi} -- ({-\hstep*(\Xmax+1)},-1*\vlength)
\end{tikzpicture}
\end{document}


Or with pgf keys.

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}[hstep/.initial=0.6,vlength/.initial=3,
Xmax/.store in=\Xmax,Xmax=9]
\fill[gray!40] ({-(\Xmax+3)*\pgfkeysvalueof{/tikz/hstep}},-\pgfkeysvalueof{/tikz/vlength})
rectangle (\pgfkeysvalueof{/tikz/hstep}/2,\pgfkeysvalueof{/tikz/vlength});
\draw[thick,dashed] (-1*\pgfkeysvalueof{/tikz/hstep},\pgfkeysvalueof{/tikz/vlength})
-- (-1*\pgfkeysvalueof{/tikz/hstep},-\pgfkeysvalueof{/tikz/vlength})
foreach \X in {1,...,\Xmax}
{\ifodd\X
--  ({\pgfkeysvalueof{/tikz/hstep}*(\X+1)},\pgfkeysvalueof{/tikz/vlength})
\else
--  ({-\pgfkeysvalueof{/tikz/hstep}*(\X+1)},-\pgfkeysvalueof{/tikz/vlength})
\fi}
--  ({-\pgfkeysvalueof{/tikz/hstep}*(\Xmax+2)},-1*\pgfkeysvalueof{/tikz/vlength});
\draw[thick] (-1*\pgfkeysvalueof{/tikz/hstep},\pgfkeysvalueof{/tikz/vlength})
-- (0,-\pgfkeysvalueof{/tikz/vlength})
(\pgfkeysvalueof{/tikz/hstep},-1*\pgfkeysvalueof{/tikz/vlength})
foreach \X in {1,...,\Xmax}
{\ifodd\X
-- (\pgfkeysvalueof{/tikz/hstep}*\X,\pgfkeysvalueof{/tikz/vlength})