我有一個圖像,我想在節點之間繪製箭頭,其中箭頭全部「在同一個圓上」。我可以手動實現我想要的目標,如下所示:
\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
海科·奧伯迪克統治! --
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}