我有 4 个不同大小的圆形节点。
有没有简单的方法(TikZ,Asymptote,...)将它们与圆形箭头弧连接起来?
\documentclass[border=5mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw,fill=white}]
\def\r{3}
\draw[red] (0,0) circle (\r);
% 4 nodes with different sizes
\path
(180:\r) node (Sp) {Spring}
(90:\r) node (Su) {Summer}
(0:\r) node (Au) {Autumn}
(-90:\r) node (Wi) {Winter};
% How to make arrow arcs cicular? (the red one with arrow tips)
\begin{scope}[-stealth,bend left]
\draw (Sp) to (Su);
\draw (Su) to (Au);
\draw (Au) to (Wi);
\draw (Wi) to (Sp);
\end{scope}
\end{tikzpicture}
\end{document}
答案1
Asymptote
这是使用真弧来实现的一种方法。
函数返回两个路径相交处intersect
的数组。该函数将圆弧修剪到相交处。time
subpath
time
我没有将代码包装到 LaTeX 文档中,因为我倾向于使用命令来处理 Asymptote asy
。
unitsize(1inch);
path Autumn = shift( 1, 0)*scale(0.35)*unitcircle;
path Winter = shift( 0,-1)*scale(0.30)*unitcircle;
path Spring = shift(-1, 0)*scale(0.32)*unitcircle;
path Summer = shift( 0, 1)*scale(0.36)*unitcircle;
draw(Autumn);
draw(Winter);
draw(Spring);
draw(Summer);
label("Autumn", ( 1, 0));
label("Winter", ( 0,-1));
label("Spring", (-1, 0));
label("Summer", ( 0, 1));
path p1 = arc((0,0), 1, 0, -90);
draw(subpath(p1, intersect(p1,Autumn)[0], intersect(p1,Winter)[0]), red, Arrow);
path p2 = arc((0,0), 1, 270, 180);
draw(subpath(p2, intersect(p2,Winter)[0], intersect(p2,Spring)[0]), red, Arrow);
path p3 = arc((0,0), 1, 180, 90);
draw(subpath(p3, intersect(p3,Spring)[0], intersect(p3,Summer)[0]), red, Arrow);
path p4 = arc((0,0), 1, 90, 0);
draw(subpath(p4, intersect(p4,Summer)[0], intersect(p4,Autumn)[0]), red, Arrow);
答案2
您可以计算节点边界和圆的交点来绘制圆弧。为了方便起见,我将所有内容都打包在一张图片中。我保留了红色圆圈以证明圆弧完美覆盖了它。
\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{arrows.meta,bending,calc,intersections}
\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw,fill=white},
pics/circular arc/.style args={from #1 to #2}{code={
\path[name path=arc]
let \p1=(#1),\p2=(#2),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
\n3={ifthenelse(abs(\n1-\n2)<180,\n2,\n2-360)}
in (\n1:\r) arc(\n1:\n3:\r);
\draw[-{Stealth[bend]},pic actions,
name intersections={of=#1 and arc,by=arcstart},
name intersections={of=#2 and arc,by=arcend}]
let \p1=(arcstart),\p2=(arcend),\n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)},
\n3={ifthenelse(abs(\n1-\n2)<180,\n2,\n2-360)}
in (\n1:\r) arc(\n1:\n3:\r);
}}]
\def\r{3}
\draw[red] (0,0) circle (\r);
% 4 nodes with different sizes
\path
(180:\r) node[name path=Sp] (Sp) {Spring}
(90:\r) node[name path=Su] (Su) {Summer}
(0:\r) node[name path=Au] (Au) {Autumn}
(-90:\r) node[name path=Wi] (Wi) {Winter};
% How to make arrow arcs cicular? (the red one with arrow tips)
\begin{scope}[-stealth,bend left]
\path pic{circular arc=from Sp to Su}
pic{circular arc=from Su to Au}
pic{circular arc=from Au to Wi}
pic{circular arc=from Wi to Sp};
\end{scope}
\end{tikzpicture}
\end{document}
答案3
这就是graphdrawing
图书馆necklace routing
是为……而生的。
代码
% !TeX TS-program = lualatex
\documentclass[tikz]{standalone}
\usetikzlibrary{
arrows.meta, bending, % for Stealth arrow tips and bended arrow tips
graphs, graphdrawing} % for \graph syntax and \usegdlibrary → needs LuaTeX
\usegdlibrary{
circular, % for simple necklace layout
routing} % for necklace routing
\tikzgraphsset{
circ routing/.style={
/tikz/>={Stealth[sep,bend]},
nodes={draw, circle},
radius=3cm,
->, cycle, % all edges are directed, last connects to first
simple necklace layout, % place nodes on a circle
grow'=down, % first node is at the top, ' = clockwise
necklace routing}} % make connections follow the circle
\begin{document}
\tikz\graph[circ routing]{Summer, Autumn, Winter, Spring};
\end{document}
输出(添加了半径为3cm的圆)
答案4
我刚刚用库找到了一个看似简单的方法angles
。每个圆形箭头弧都是一个角度标记。
\documentclass[border=5mm,tikz]{standalone}
\usetikzlibrary{angles}
\begin{document}
\begin{tikzpicture}[every node/.style={circle,draw,fill=white}]
\def\r{3}
\draw[red] (0,0) circle (\r);
% 4 nodes with different sizes
\path
(0,0) coordinate (O)
(180:\r) node (Sp) {Spring}
(90:\r) node (Su) {Summer}
(0:\r) node (Au) {Autumn}
(-90:\r) node (Wi) {Winter};
% Make arrow arcs cicular using angles library as angle mark
\path
(Sp.north) coordinate (SpN)
(Su.west) coordinate (SuW)
pic[draw=blue,fill=none,stealth-,angle radius=\r cm]{angle=SuW--O--SpN}
(Su.east) coordinate (SuE)
(Au.north) coordinate (AuN)
pic[draw=blue,fill=none,stealth-,angle radius=\r cm]{angle=AuN--O--SuE};
\end{tikzpicture}
\end{document}