
Ich versuche, einen Pfad in Tikz zu zeichnen, mit Paul Gaborits Lösung hierTikZ: Wie zeichne ich einen Pfeil in die Mitte der Linie?Mir ist es gelungen, dies so hinzubekommen, dass der Pfad die Hälfte des Rings darstellt.
Ich möchte aber, dass der Pfeil unten links und der Pfeil im inneren Halbkreis nach rechts zeigen (damit alle Pfeile beim Durchqueren des Pfads die gleiche Richtung haben und sich die Innenseite des Rings links befindet).
Meine schlechte Bearbeitung in Paint
Und der Code, den ich verwende
\usepackage{tikz}
\usetikzlibrary{positioning, calc, arrows, decorations.markings, decorations.pathreplacing}
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}
\begin{center}
\begin{tikzpicture}[domain=0:4]
\draw [<->, very thick] (0,4) node (yaxis) [above] {$y$}
|- (-4,0) node (zaxis) [left] {}
|- (4,0) node (xaxis) [right] {$x$}
;
\path [draw=black, ultra thick, postaction={on each segment={mid arrow=black}}] (3,0) arc (0:180:3cm)
(1,0) -> (3,0)
(1,0) arc (0:180:1cm)
(-1,0) -> (-3,0) ;
\end{tikzpicture}
\end{center}
Ich bin für jede Hilfe dankbar :)
Antwort1
Bitte denken Sie in Zukunft daran, eine vollständigeminimales Arbeitsbeispiel (MWE). So fällt es anderen leichter, Ihnen zu helfen. :-)
Der Code von Paul Gaborit wendet die Pfeile in der Richtung an, in der der Pfad durchlaufen wird. In diesem Fall muss also nur die Richtung der fehlerhaften Pfadsegmente geändert werden.
Ich musste nur zwei Codezeilen innerhalb der tikzpicture
Umgebung ändern. Beide Änderungen werden in den Kommentarzeilen im folgenden Code ausführlich beschrieben.
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc, arrows, decorations.markings, decorations.pathreplacing}
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[#1]{stealth}}
}}},
}
\begin{document}
\begin{tikzpicture}[domain=0:4]
\draw [<->, very thick] (0,4) node (yaxis) [above] {$y$}
|- (-4,0) node (zaxis) [left] {}
|- (4,0) node (xaxis) [right] {$x$}
;
\path [draw=black, ultra thick, postaction={on each segment={mid arrow=black}}] (3,0) arc (0:180:3cm)
(1,0) -> (3,0)
(-1,0) arc (180:0:1cm) % changed starting point and swapped arc bounding angles
(-3,0) -> (-1,0) ; % swapped coordinates here
\end{tikzpicture}
\end{document}