3

I need to draw a zig-zag line inside a circle without using decorations. The size and positioning of the line should be relative to the size of the circle. I used this code:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\node[draw,circle,minimum size=1cm] (C) at (0,0){};

\draw    ($($ (C.west)!.1!(C.east) $)-(0,30pt)$)  --($ (C.west)!.1!(C.east) $)
       --($ (C.west)!.25!(C.east) $)              --($($ (C.west)!.3!(C.east) $)+(0,3pt)$)
       --($($ (C.west)!.4!(C.east) $)-(0,3pt)$)   --($($ (C.west)!.5!(C.east) $)+(0,3pt)$)
       --($($ (C.west)!.6!(C.east) $)-(0,3pt)$)   --($($ (C.west)!.7!(C.east) $)+(0,3pt)$)
       --($ (C.west)!.75!(C.east) $)              --($ (C.west)!.9!(C.east) $)
       --($($ (C.west)!.9!(C.east) $)-(0,30pt)$);
\end{tikzpicture}



\end{document}

to get this:

enter image description here

The problem is that if I want to resize the circle, the vertical lines gets too short (or too long) and I have to fix the "vertical coordinate" manually.

enter image description here

It is possible to anchor the vertical coordinate relative to the node's shape??

Angelo
  • 413

1 Answers1

7

Instead of defining the "legs" as (0,-30pt) (which, of course, doesn't scale), you can use ($(C.north)-(C.south)$):

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}

\node[draw,circle,minimum size=1.2cm] (C) at (0,0){};

\draw    ($($ (C.west)!.1!(C.east) $)-($(C.north)-(C.south)$)$)--($ (C.west)!.1!(C.east) $)
       --($ (C.west)!.25!(C.east) $)--($($ (C.west)!.3!(C.east) $)+(0,3pt)$)
       --($($ (C.west)!.4!(C.east) $)-(0,3pt)$)--($($ (C.west)!.5!(C.east) $)+(0,3pt)$)
       --($($ (C.west)!.6!(C.east) $)-(0,3pt)$)--($($ (C.west)!.7!(C.east) $)+(0,3pt)$)
       --($ (C.west)!.75!(C.east) $)--($ (C.west)!.9!(C.east) $)
       --($($ (C.west)!.9!(C.east) $)-($(C.north)-(C.south)$)$);
\end{tikzpicture}
\begin{tikzpicture}

\node[draw,circle,minimum size=1.8cm] (C) at (0,0){};

\draw    ($($ (C.west)!.1!(C.east) $)-($(C.north)-(C.south)$)$)--($ (C.west)!.1!(C.east) $)
       --($ (C.west)!.25!(C.east) $)--($($ (C.west)!.3!(C.east) $)+(0,3pt)$)
       --($($ (C.west)!.4!(C.east) $)-(0,3pt)$)--($($ (C.west)!.5!(C.east) $)+(0,3pt)$)
       --($($ (C.west)!.6!(C.east) $)-(0,3pt)$)--($($ (C.west)!.7!(C.east) $)+(0,3pt)$)
       --($ (C.west)!.75!(C.east) $)--($ (C.west)!.9!(C.east) $)
       --($($ (C.west)!.9!(C.east) $)-($(C.north)-(C.south)$)$);
\end{tikzpicture}



\end{document}
Jake
  • 232,450