有没有办法将爱好路径和线条组合成一条路径,以便我可以应用后续操作?
基本上,我希望我的方向箭头沿着整个路径而不是单个组件等距分布。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{hobby}
\usetikzlibrary{backgrounds}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{arrows.meta}
\tikzset{>=stealth}
\tikzset{
clockwise arrows/.style={
postaction={
decorate,
decoration={
markings,
mark=between positions 0 and 1 step 40pt with {\arrow{>}},
}}}}
\begin{document}
\begin{tikzpicture}[framed]
\coordinate (B1) at (7,-1);
\coordinate (B2) at (7,1);
\coordinate (A1) at (1,2);
\coordinate (A2) at (1,-2);
\draw[magenta, thick, clockwise arrows] (A1) -- (A2);
\draw[magenta, thick, clockwise arrows] (B1) -- (B2);
\draw[magenta,thick,use Hobby shortcut, clockwise arrows] (B2) .. (4.5,2) .. (3,3) .. (A1);
\draw[magenta,thick,use Hobby shortcut, clockwise arrows] (A2) .. (3,-3) .. (4.5,-2) .. (B1);
\end{tikzpicture}
\end{document}
答案1
您可以将四个draw
语句合并为一个语句:
\draw[magenta,thick,use Hobby shortcut, clockwise arrows]
(B2) .. (4.5,2) .. (3,3) .. (A1) --
(A2) .. (3,-3) .. (4.5,-2) .. (B1) -- cycle;
请注意,您可以混合..
和--
以cycle
形成闭合循环。
但是,你仍然会在路径的起点看到那个可怕的箭头。要解决这个问题,你可以让装饰的起点稍微远一点:
mark=between positions 0.05 and 1 step 40pt with {\arrow{>}},
通过这些更改,您的示例产生了以下内容: