
Mi profesor escribió una prueba sobre el algoritmo de Prim en LaTeX y usó un gráfico para ilustrar cómo se hacen los cortes, etc. Lo que tengo curiosidad es cómo hizo las líneas onduladas que salen del círculo en el medio.
https://www.uncg.edu/cmp/faculty/srtate/330.f16/primsproof.pdf
¿Alguien puede explicar cómo se hizo esto? Me gustaría reproducirlo en un artículo. ¡Gracias!
Respuesta1
¡Bienvenido! Hay muchas formas de dibujar una curva suave. Puedes usar una trama con smooth
o smooth cycle
, o usar in
y 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}
Para dibujar la línea ondulada puedes simplemente usar coil
decoración.
\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}
Se pueden encontrar líneas onduladas más bonitas.aquí.