0

My professor wrote a proof about Prim’s algorithm in LaTeX, and used a graph to illustrate how cuts are made, etc. What I’m curious about is how he did the wavy lines coming out of the circle in the middle.

https://www.uncg.edu/cmp/faculty/srtate/330.f16/primsproof.pdf

Can anyone explain how this was done? I’d like to reproduce it in a paper. Thanks!

TheProgrammer
  • 404
  • 2
  • 11

1 Answers1

1

Welcome! There are many ways to draw a smooth curve. You can use a plot with smooth or smooth cycle, or use in and out, etc.

\documentclass[tikz,border=3mm]{standalone}

\begin{document}
\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=1.4pt}]
  \draw[semithick]  plot[smooth cycle,looseness=1.3] coordinates 
  {(0,1) (0.5,0.7) (1.2,0.9) (2,1.3) (2.5,1.2) (3.6,1.1) (3.7,2.2)
  (3,3.2) (1.6,2.9) (0.3,2.5)  };
 \draw[semithick] 
  (1,1.7) node{$W$}
  (2.8,2.6) node[bullet,label=above left:$a$](a){}
  (a) +(20:1.2)   node[bullet,label=above right:$b$](b){}
  (2.8,1.5) node[bullet,label=left:$x$](x){}
  (x) +(-10:1.2)   node[bullet,label=below right:$y$](y){}
  (x) to[out=60,in=-60] (3,1.9) to[out=120,in=-120] (a) 
  -- (b) to[out=-80,in=90] (3.4,1.9)
  to[out=-90,in=100] (y) -- (x);
\end{tikzpicture}
\end{document}

enter image description here

To draw the wavy line you can just use coil decoration.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[bullet/.style={circle,fill,inner sep=1.4pt,outer sep=0pt}]
  \draw[semithick]  plot[smooth cycle,looseness=1.3] coordinates 
  {(0,1) (0.5,0.7) (1.2,0.9) (2,1.3) (2.5,1.2) (3.6,1.1) (3.7,2.2)
  (3,3.2) (1.6,2.9) (0.3,2.5)  };
 \draw[semithick] 
  (1,1.7) node{$W$}
  (2.8,2.6) node[bullet,label=above left:$a$](a){}
  (a) +(20:1.2)   node[bullet,label=above right:$b$](b){}
  (2.8,1.5) node[bullet,label=left:$x$](x){}
  (x) +(-10:1.2)   node[bullet,label=below right:$y$](y){}
   (a) 
  -- (b) to[out=-80,in=90] (3.4,1.9)
  to[out=-90,in=100] (y) -- (x);
  \draw[thick,blue,decorate,decoration={coil,aspect=0,segment length=5.9mm}] (x) -- (a);
\end{tikzpicture}
\end{document}

enter image description here

Nicer wavy lines can be found here.