Comportamiento inesperado de las decoraciones de flechas en los nudos: aparecen múltiples flechas y espacios

Comportamiento inesperado de las decoraciones de flechas en los nudos: aparecen múltiples flechas y espacios

Estoy usando knotstikzlibrary para dibujar algunos nudos y quería orientarlos, es decir, agregar una flecha. Utilizo un estilo de decoración que he llamado "arrowat", que inserta una flecha en el lugar deseado (por ejemplo, \draw[arrowat=0.5]producirá una flecha a mitad de la línea resultante). Se define de la siguiente manera

\tikzset{% 
    arrowat/.style={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
    }
}

Sin embargo, surgen algunos problemas cuando intento usar este estilo en un nudo: en ciertos puntos, las cosas funcionan bien, pero si intento dibujar una flecha en otros puntos, aparecen múltiples flechas (y espacios en la línea). A continuación se muestra un MWE, que muestra un caso en el que las cosas funcionan bien (izquierda) y otro en el que no (derecha). Mi pregunta es: ¿Cómo soluciono esto o más bien evito que suceda?

ingrese la descripción de la imagen aquí

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}

\tikzset{% 
    arrowat/.style={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
    }
}
\begin{document}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick, arrowat=0.8] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick, arrowat=0.5] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
    \end{knot}
\end{tikzpicture}

\end{document}

Respuesta1

No tengo una solución verdadera (es decir, elegante). Solo tengo curiosidad por entender en parte lo que está pasando y verifiqué con qué frecuencia Tikzpiensaestá en la posición 0,5. En este ejemplo, esto es 10 veces; puede verificarlo descomentando \typeout{\number\value{arrowcount}}. Luego se puede agregar un interruptor que indique en cuál de ellos se debe dibujar realmente la flecha. El estilo correspondiente se llama conditional arrow at.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\newcounter{arrowcount}
\tikzset{% 
    arrowat/.style={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
    },
    conditional arrow at/.style 2 args={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\stepcounter{arrowcount}%
                %\typeout{\number\value{arrowcount}}%
                \ifnum\value{arrowcount}=#2
                \arrow[xshift=2pt]{>}%
                \fi}}}
    },
}
\begin{document}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick, arrowat=0.8] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick,conditional arrow at={0.5}{6}] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
   \end{knot}
\end{tikzpicture}

\end{document}

ingrese la descripción de la imagen aquí

La situación mejora en un factor 2 (como se esperaba) cuando se usa la only when renderingclave. Entonces tienes "sólo" 5 espacios, y cada uno de ellos realmente conduce a una flecha.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\newcounter{arrowcount}
\tikzset{% 
    arrowat/.style={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\arrow[xshift=2pt]{>}}}}
    },
    conditional arrow at/.style 2 args={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\stepcounter{arrowcount}%
                \typeout{\number\value{arrowcount}}%
                \ifnum\value{arrowcount}=#2
                \arrow[xshift=2pt]{>}%
                \fi}}}
    },
}
\begin{document}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick, arrowat=0.8] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick,only when rendering/.style={conditional arrow at={0.5}{3}}] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
   \end{knot}
\end{tikzpicture}

\end{document}

Entonces parece que el problema es que el camino se descompone en segmentos. Esto nos dice que podemos adjuntar la flecha a un camino invisible.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,knots}
\newcounter{arrowcount}
\tikzset{% 
    arrowat/.style={%
        postaction={decorate,decoration={
                markings,
                mark=at position #1 with {\arrow[xshift=2pt,opacity=1]{>}}}}
    },
}
\begin{document}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \strand [thick, arrowat=0.8] (0,0)
    to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0);
\end{knot}
\end{tikzpicture}

\begin{tikzpicture}
    \begin{knot} [consider self intersections, ignore endpoint intersections=false, clip width=7, flip crossing=3]
    \def\mypath{(0,0) to [out=180, in=270] (-1,1)
    to [out=90, in=180] (1,2.5)
    to [out=0, in=90] (3,1)
    to [out=270, in=0] (2,0)
    to [out=180, in=270] (-0.2,2.5)
    to [out=90, in=180] (1,3.8)
    to [out=0, in=90] (2.2,2.5)
    to [out=270, in=0] (0,0)}
    \draw[thick,opacity=0,arrowat=0.55] \mypath;
    \strand [thick] \mypath;
   \end{knot}
\end{tikzpicture}

\end{document}

ingrese la descripción de la imagen aquí

Esta podría ser la más elegante de estas propuestas y también revela que la flecha "verdadera" en 0,5 está oscurecida por un cruce.

información relacionada