Positionierung von Pfeilen und Beschriftungen in einer Bilddatei mit Tikz

Positionierung von Pfeilen und Beschriftungen in einer Bilddatei mit Tikz

Ich versuche eine Figur zu zeichnen, die wiederholt ähnliche Bilder enthält. Dazu verwende ich .picbereitgestellte Bilder tikzfolgendermaßen:

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

% define colors and other constants
\colorlet{line color}{black!30}
\def\line thickness{1pt}

% define primitive shapes for the drawing
\tikzset{
line/.style={
    -, draw=line color, line width=\line thickness},
z plus joint/.pic={
    \draw[black, line width=\line thickness, fill=gray!50]  (0,0)
          circle (0.5);
    \draw[black, line width=\line thickness, fill=white]  (0,0) circle (0.3);
    \draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}] 
          (270:0.4) arc (270:150:0.4);
    \draw[latex-,blue, shorten <=2pt] (-0.5, 0.5) -- ++ (-0.5, 0.5) 
          node[above=2pt, black]{#1};
         },
z minus joint/.pic={
    \pic[yscale=-1, rotate=180] {z plus joint=#1};},
}


\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {z plus joint=1} --
                (2, 0) pic {z minus joint=3} --
                (4, 0) pic {z minus joint=2} --
                (4, 2) pic {z plus joint=4} --
                (4, 4) pic {z minus joint=6};
\end{tikzpicture}
\end{document}

Bitte sehen Sie sich unten die generierte Abbildung an:

Bildbeschreibung hier eingeben

Ich benötige die folgenden zwei Ausrichtungsarten für Pfeile:

  • Linker Pfeil mit Beschriftung
  • Rechter Pfeil mit Beschriftung

Ich suche nach einer Möglichkeit, dem Bild ein zusätzliches Argument hinzuzufügen, das die Ausrichtung des Pfeils bestimmen kann.Siehe beispielsweise den folgenden Pseudocode:

\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {z plus joint={1}{right}} --
                (2, 0) pic {z minus joint={3}{right}} --
                (4, 0) pic {z minus joint={2}{left}} --
                (4, 2) pic {z plus joint={4}{left}} --
                (4, 4) pic {z minus joint={6}{left}};
\end{tikzpicture}

PS: Da die Orientierung nur zwei mögliche Werte hat, nämlich leftund right, können wir leftalsdefault

Antwort1

Sowas in der Art? -1Für links und 1für rechts.

\documentclass[tikz, border=2px]{standalone}
\usetikzlibrary{arrows.meta, bending, shapes.misc, shapes.geometric}

% define colors and other constants
\colorlet{line color}{black!30}
\def\line thickness{1pt}

% define primitive shapes for the drawing
\tikzset{
line/.style={
    -, draw=line color, line width=\line thickness},    
pics/z plus joint/.style n args={2}{code={
    \draw[black, line width=\line thickness, fill=gray!50]  (0,0)
          circle (0.5);
    \draw[black, line width=\line thickness, fill=white]  (0,0) circle (0.3);
    \draw[line width=2pt, red, -{Triangle[bend, length=6pt, width=8pt]}] 
          (270:0.4) arc (270:150:0.4);
    \draw[latex-,blue, shorten <=2pt] (0.5*#2, 0.5) -- ++ (0.5*#2, 0.5) 
          node[above=2pt, black]{#1};
         }},
pics/z minus joint/.style n args={2}{code={
    \pic[yscale=-1, rotate=180] {z plus joint={#1}{-1*#2}};}},
}


\begin{document}
\begin{tikzpicture}[node distance=2cm]
    \path[line] (0, 0) pic {z plus joint={1}{1}}
     --         (2, 0) pic {z minus joint={3}{1}} --
                (4, 0) pic {z minus joint={2}{-1}} --
                (4, 2) pic {z plus joint={4}{-1}} --
                (4, 4) pic {z minus joint={6}{-1}}
                ;
\end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen