0

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.

spiral thing

  • 3
    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
4

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)
 arc[start angle=180,end angle=360,x radius={1.5*\hstep},
  y radius=0.75*\hstep]
  foreach \X in {1,...,\Xmax}
  {\ifodd\X
   --  ({\hstep*(\X+1)},\vlength) 
    arc[start angle=0,end angle=180,x radius={(\X+1.5)*\hstep},
   y radius={0.5*(\X+1.5)*\hstep}]
  \else
  --  ({-\hstep*(\X+1)},-\vlength)
   arc[start angle=180,end angle=360,x radius={(\X+1.5)*\hstep},
  y radius={0.5*(\X+1.5)*\hstep}]
  \fi}
  --  ({-\hstep*(\Xmax+2)},-1*\vlength);
 \draw[thick] (-1*\hstep,\vlength) 
 arc[start angle=180,end angle=0,x radius={0.5*\hstep},
  y radius=0.25*\hstep]
  -- (0,-\vlength)
  arc[start angle=180,end angle=360,x radius={0.5*\hstep},
  y radius=0.25*\hstep]
 (\hstep,-1*\vlength) 
 foreach \X in {1,...,\Xmax}
 {\ifodd\X
   -- (\hstep*\X,\vlength) 
   arc[start angle=0,end angle=180,x radius={(\X+0.5)*\hstep},
   y radius={0.5*(\X+0.5)*\hstep}]
 \else
  -- ({-\hstep*\X},-1*\vlength) 
  arc[start angle=180,end angle=360,x radius={(\X+0.5)*\hstep},
  y radius={0.5*(\X+0.5)*\hstep}]
 \fi} -- ({-\hstep*(\Xmax+1)},-1*\vlength) 
 arc[start angle=0,end angle=-180,x radius={0.5*\hstep},
  y radius=0.25*\hstep];
\end{tikzpicture}
\end{document}

enter image description here

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})
 arc[start angle=180,end angle=360,x radius={1.5*\pgfkeysvalueof{/tikz/hstep}},
  y radius=0.75*\pgfkeysvalueof{/tikz/hstep}]
  foreach \X in {1,...,\Xmax}
  {\ifodd\X
   --  ({\pgfkeysvalueof{/tikz/hstep}*(\X+1)},\pgfkeysvalueof{/tikz/vlength}) 
    arc[start angle=0,end angle=180,x radius={(\X+1.5)*\pgfkeysvalueof{/tikz/hstep}},
   y radius={0.5*(\X+1.5)*\pgfkeysvalueof{/tikz/hstep}}]
  \else
  --  ({-\pgfkeysvalueof{/tikz/hstep}*(\X+1)},-\pgfkeysvalueof{/tikz/vlength})
   arc[start angle=180,end angle=360,x radius={(\X+1.5)*\pgfkeysvalueof{/tikz/hstep}},
  y radius={0.5*(\X+1.5)*\pgfkeysvalueof{/tikz/hstep}}]
  \fi}
  --  ({-\pgfkeysvalueof{/tikz/hstep}*(\Xmax+2)},-1*\pgfkeysvalueof{/tikz/vlength});
 \draw[thick] (-1*\pgfkeysvalueof{/tikz/hstep},\pgfkeysvalueof{/tikz/vlength}) 
 arc[start angle=180,end angle=0,x radius={0.5*\pgfkeysvalueof{/tikz/hstep}},
  y radius=0.25*\pgfkeysvalueof{/tikz/hstep}]
  -- (0,-\pgfkeysvalueof{/tikz/vlength})
  arc[start angle=180,end angle=360,x radius={0.5*\pgfkeysvalueof{/tikz/hstep}},
  y radius=0.25*\pgfkeysvalueof{/tikz/hstep}]
 (\pgfkeysvalueof{/tikz/hstep},-1*\pgfkeysvalueof{/tikz/vlength}) 
 foreach \X in {1,...,\Xmax}
 {\ifodd\X
   -- (\pgfkeysvalueof{/tikz/hstep}*\X,\pgfkeysvalueof{/tikz/vlength}) 
   arc[start angle=0,end angle=180,x radius={(\X+0.5)*\pgfkeysvalueof{/tikz/hstep}},
   y radius={0.5*(\X+0.5)*\pgfkeysvalueof{/tikz/hstep}}]
 \else
  -- ({-\pgfkeysvalueof{/tikz/hstep}*\X},-1*\pgfkeysvalueof{/tikz/vlength}) 
  arc[start angle=180,end angle=360,x radius={(\X+0.5)*\pgfkeysvalueof{/tikz/hstep}},
  y radius={0.5*(\X+0.5)*\pgfkeysvalueof{/tikz/hstep}}]
 \fi} -- ({-\pgfkeysvalueof{/tikz/hstep}*(\Xmax+1)},-1*\pgfkeysvalueof{/tikz/vlength}) 
 arc[start angle=0,end angle=-180,x radius={0.5*\pgfkeysvalueof{/tikz/hstep}},
  y radius=0.25*\pgfkeysvalueof{/tikz/hstep}];
\end{tikzpicture}
\end{document}
  • 1
    Despite not being the OP, thanks for your unconditional continuous help. – Diaa May 12 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.