
Я пытаюсь нарисовать путь в Tikz, используя решение Пола Габорита здесьTikZ: Как нарисовать стрелку посередине линии?Мне удалось получить это, где путь будет представлять собой половину кольца.
Но я хочу, чтобы нижняя левая стрелка и внутренняя полукруглая стрелка шли вправо (чтобы все стрелки имели одинаковое направление при пересечении пути и чтобы внутренняя часть кольца была слева).
Моя плохая редакция в Paint
И код, который я использую
\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}
Любая помощь будет оценена по достоинству :)
решение1
В будущем, пожалуйста, рассмотрите возможность публикации полногоминимальный рабочий пример (MWE). Это облегчит другим задачу начать помогать вам. :-)
Код Пола Габорита применяет стрелки в направлении прохождения пути. Так что в этом случае все, что нужно, это изменить направление сегментов пути, вызывающих проблемы.
Мне пришлось изменить только две строки кода внутри tikzpicture
среды; оба эти изменения подробно описаны в строках комментариев в коде ниже.
\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}