我有一张图像,我想在节点之间绘制箭头,并且所有箭头都“在同一个圆上”。我可以手动实现我想要的效果,如下所示:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[ultra thick, -stealth]
\node[circle,fill] (a) at (0: 1) {};
\node[rectangle,minimum width=1cm,fill](b) at (120: 1) {};
\node[rectangle,minimum height=1cm,fill](c) at (240: 1) {};
\draw[dashed] (85: 1) arc (85: 30: 1) ;
\draw (330:1) arc (330: 280:1) ;
\draw[dashed] (200:1) arc (200: 140:1);
\end{tikzpicture}
\end{document}
但是如果我的节点形状和大小不同,我必须手动找到可用的坐标。我真正想做的是找到节点边缘与圆相交的位置,并使用这些边缘绘制圆弧。有没有自动的方法可以做到这一点?这个答案是一个部分解决方案,但似乎我仍然必须shorten
手动选择弧和长度......
实际用例是节点将包含不同纵横比的图片。我使用一些形状奇怪的节点来近似解决这个问题。
答案1
Heiko Oberdiek 太棒了!!!——
https://tex.stackexchange.com/a/250270/197451
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{bending}
\begin{document}
\begin{tikzpicture}[
->,
thick,
main node/.style={circle, fill=blue!20, draw},
]
\newcommand*{\MainNum}{5}
\newcommand*{\MainRadius}{1.5cm}
\newcommand*{\MainStartAngle}{90}
% Print main nodes, node names: p1, p2, ...
\path
(0, 0) coordinate (M)
\foreach \t [count=\i] in {A, Hello\\World, 3, foobar, $\cdot$} {
+({\i-1)*360/\MainNum + \MainStartAngle}:\MainRadius)
node[main node, align=center] (p\i) {\t}
}
;
% Calculate the angle between the equal sides of the triangle
% with side length \MainRadius, \MainRadius and radius of circle node
% Result is stored in \p1-angle, \p2-angle, ...
\foreach \i in {1, ..., \MainNum} {
\pgfextracty{\dimen0 }{\pgfpointanchor{p\i}{north}}
\pgfextracty{\dimen2 }{\pgfpointanchor{p\i}{center}}
\dimen0=\dimexpr\dimen2 - \dimen0\relax
\ifdim\dimen0<0pt \dimen0 = -\dimen0 \fi
\pgfmathparse{2*asin(\the\dimen0/\MainRadius/2)}
\global\expandafter\let\csname p\i-angle\endcsname\pgfmathresult
}
% Draw the arrow arcs
\foreach \i [evaluate=\i as \nexti using {int(mod(\i, \MainNum)+1}]
in {1, ..., \MainNum} {
\pgfmathsetmacro\StartAngle{
(\i-1)*360/\MainNum + \MainStartAngle
+ \csname p\i-angle\endcsname
}
\pgfmathsetmacro\EndAngle{
(\nexti-1)*360/\MainNum + \MainStartAngle
- \csname p\nexti-angle\endcsname
}
\ifdim\EndAngle pt < \StartAngle pt
\pgfmathsetmacro\EndAngle{\EndAngle + 360}
\fi
\draw
(M) ++(\StartAngle:\MainRadius)
arc[start angle=\StartAngle, end angle=\EndAngle, radius=\MainRadius]
;
}
\end{tikzpicture}
\end{document}