是否可以绘制符合节点边界形状的抛物线?在简单的线或圆弧中,可以使用以节点作为inner sep
端点来实现,但抛物线并不关心这种分离选项。
这是一个例子,显示了差异。我希望抛物线像圆弧一样。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\node[circle,fill=white,draw=black,inner sep=2mm] at (0.0,0.0) (p1) {};
\node[draw=none] at (1.0,1.0) (p2) {};
\node[circle,fill=white,draw=black,inner sep=2mm] at (3.0,0.0) (p3) {};
\draw[->] (p1) parabola bend (p2) (p3);
\draw[->] (p1) -- (p3);
\end{tikzpicture}
\end{document}
答案1
有点笨拙的解决方案,但对于这种特殊情况它是有效的:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\usetikzlibrary{intersections}
\begin{tikzpicture}
\node[circle,fill=white,draw=black,minimum size=6mm] at (0.0,0.0) (p1) {};
\coordinate (p2) at (1.0,1.0);
\node[circle,fill=white,draw=black,minimum size=6mm] at (3.0,0.0) (p3) {};
\path[name path=circle 1] (0,0) circle(3mm);
\path[name path=circle 2] (3,0) circle(3mm);
\path[name path=parabola] (p1) parabola bend (p2) (p3);
\path[name intersections = {of = parabola and circle 1, name = pp1}];
\path[name intersections = {of = parabola and circle 2, name = pp3}];
\draw[->] (pp1-1) parabola bend (p2) (pp3-1);
\draw[->] (p1) -- (p3);
\end{tikzpicture}
\end{document}
答案2
这是JLDiaz 的方法隐藏在一条to
小路里。
这非常类似于我的另一个答案但不使用计数器覆盖每个先前的路径qrr@parabola
和先前的坐标qrr@parabola-start-1
和qrr@parabola-target-1
。
样式parabola
只是将其参数转发给parabola
路径运算符。您甚至可以使用to[parabola={[bend pos=0.5] bend +(0,2)}]
(摘自 PGF 手册)。
代码
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections,calc}
\tikzset{
name/.append style={
/tikz/name path={qrr@path-#1},
},
parabola/.style={
to path={
\pgfextra
\path[name path=qrr@parabola] (\tikztostart) parabola #1 (\tikztotarget);
\path[name intersections = {of = qrr@parabola and qrr@path-\tikztostart, name=qrr@parabola-start}];
\path[name intersections = {of = qrr@parabola and qrr@path-\tikztotarget, name=qrr@parabola-target}];
\endpgfextra
(qrr@parabola-start-1) parabola #1 (qrr@parabola-target-1)
}
}
}
\begin{document}
\begin{tikzpicture}
\node[circle,fill=white,draw=black,minimum size=6mm] at (0.0,0.0) (p1) {};
\coordinate (p2) at (1.0,1.0);
\node[circle,fill=white,draw=black,minimum size=6mm] at (3.0,0.0) (p3) {};
\draw[->, green] (p1) to[parabola=bend (p2)] (p3);
\draw[->, red] (p3) to[parabola={bend (1,-1)}] (p1);
\end{tikzpicture}
\end{document}