如何顺利地限制/裁剪/绑定弯曲的箭头?

如何顺利地限制/裁剪/绑定弯曲的箭头?

我正在寻找一种方法,使向上弯曲的 TikZ 箭头在“碰到”上限时受到上限的限制,即它不得超过不可见的上线,但要平滑地跟随它(圆角)。挑战还在于两种不同的情况:

  1. 有凸块:箭头实际上碰到了上限
    有凸块
  2. 无凹凸:箭头保持在限制以下
    无凸起

备注:在我的具体情况下,我给出了两个坐标对象,但我无法控制确切的位置。我将箭头弯曲了out一定in角度,请参见示例。

TeX 示例其中箭头超出上限(虚线): 失败的例子

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}
    % two nodes that shall be connected via arrow
    \node[draw, circle] (A) at (0, 0) {};
    \node[draw, circle] (B) at (4, -0.1) {};
    
    % invisible bound to "bump" against
    \draw[dashed, red] (0, 0.3) -- (4, 0.3);
    
    % arrow that shall limited by the upper bound
    \draw[->] (B.north west) to [out=160,in=25] (A.north east);
  \end{tikzpicture}
\end{document}

答案1

通过使用选项max distance

在此处输入图片描述

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}

\begin{document}
  \begin{tikzpicture}[
every node/.style = {circle, draw, minimum size=4mm, inner sep=0pt}
                     ]
% two nodes that shall be connected via arrow
\node   (A) at (0, 0) {};
\node   (B) at (4, 0) {};

% invisible bound to "bump" against
\draw[dashed, red] (0, 0.3) -- (4, 0.3);

% arrow that shall limited by the upper bound
\draw[->] (B.north west) to [out=160,in=25] (A.north east);
\draw[blue, ->] (B.north west) to [out=160,in=25, 
                                   max distance=5mm]    % <---
                                        (A.north east);
  \end{tikzpicture}
\end{document}

相关内容