沿圆形路径移动图形节点,同时保持圆形

沿圆形路径移动图形节点,同时保持圆形

我想在图表上显示节点。图表形状应该是圆形。我想移动节点,同时保持圆形。以下是我可以用四个节点创建的,看起来确实不错:

\tikzstyle{cblue}=[circle, draw, thin,fill=cyan!20, scale=0.5]

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick,main node/.style={rectangle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]
\draw[help lines] (-1,-1) grid (1,1);
\node[cblue] (1) at ( 90:1 ) {1};
\node[cblue] (2) at ( 0:1 ) {2};
\node[cblue] (3) at ( -90:1) {3};
\node[cblue] (4) at ( 180:1) {4};

\path[every node/.style={font=\sffamily\small}]
(1) edge  [bend left]  node [right] {} (2)
(2) edge  [bend left]  node [right] {} (3)
(3) edge  [bend left]  node [right] {} (4)
(4) edge  [bend left]  node [right] {} (1) ;
\end{tikzpicture}

好的

但是,当我沿圆移动节点时,圆形形状不会保留。以下是一些修改后的坐标:

\node[cblue] (1) at ( 90:1 ) {1};
\node[cblue] (2) at ( 30:1 ) {2};
\node[cblue] (3) at ( 340:1) {3};
\node[cblue] (4) at ( 180:1) {4};

坏的

我想这是因为正如所解释的那样这里,向右弯曲的选项并不完全是圆形图案。

我研究过 pgf 的“通过库”,虽然我可以画一个穿过节点的圆,但我真正想要的是一个分成四块的圆,每块由两个节点隔开。

如果有人能告诉我该如何做我将非常感激。

答案1

如果您不介意对一堆东西进行参数化(包括比例),那么可以通过计算节点半径形成的弦在主圆上的角度来相当精确地绘制圆弧。

pgf由于沿圆弧端点切线“后退”,圆弧仍然会产生轻微误差。CVSpgf版本的bending库(此处未使用)可以解决这个问题。

\documentclass[border=0.125cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.markings}

\begin{document}

\def\r{1cm}% radius of circle
\def\R{0.25cm}% radius of node
\def\s{2}% scaling factor
\def\o{1pt}% outer sep
\def\shO{0}% shorten angle out
\def\shI{2}% shorten angle in

% chord angle = 2*asin(R/(2*r))
%
% Here the radius R must also include the outer sep
% and the radius r must include the scaling factor
%
\pgfmathparse{2*asin((\R+\o)/(2*\r*\s))+\shO}\let\aO=\pgfmathresult
\pgfmathparse{2*asin((\R+\o)/(2*\r*\s))+\shI}\let\aI=\pgfmathresult

\begin{tikzpicture}[scale=\s, cblue/.style={circle, draw, fill=cyan!20, font=\footnotesize, outer sep=\o, minimum size=\R*2}, >=stealth]

\draw [ultra thick, gray!50] circle [radius=\r];

\node[cblue] (1) at ( 90:\r ) {1};
\node[cblue] (2) at ( 30:\r ) {2};
\node[cblue] (3) at ( 340:\r) {3};
\node[cblue] (4) at ( 180:\r) {4};

% By default there will still be an error
% in the paths due to PGF `backing up'
% to draw the arrow head.
\draw [->] (90-\aO:\r)  arc (90-\aO:30+\aI:\r);
\draw [->] (30-\aO:\r)  arc (30-\aO:-20+\aI:\r);
\draw [->] (340-\aO:\r) arc (340-\aO:180+\aI:\r);
\draw [->] (180-\aO:\r) arc (180-\aO:90+\aI:\r);

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

使用bend left在这里没有用。但使用inout精心选择的角度looseness可能会有帮助。调整它们以满足您的需求。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{cblue/.style={circle, draw, thin,fill=cyan!20, scale=0.5}}

\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=3cm,thick,main node/.style={rectangle,fill=blue!20,draw,font=\sffamily\Large\bfseries}]
\draw[help lines] (-1,-1) grid (1,1);
\draw[gray] (0,0) circle (1cm);
\node[cblue] (1) at ( 90:1 ) {1};
\node[cblue] (2) at ( 30:1 ) {2};
\node[cblue] (3) at ( 340:1) {3};
\node[cblue] (4) at ( 180:1) {4};

\path[every node/.style={font=\sffamily\small}]
(1) edge  [in=125,out=0,looseness=.7]  node [right] {} (2)
(2) edge  [in=80,out=-65,looseness=.85]  node [right] {} (3)
(3) edge  [in=280,out=-115,looseness=1.25]  node [right] {} (4)
(4) edge  [in=185,out=90,looseness=.8]  node [right] {} (1) ;
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案3

看来重点是当节点沿着圆圈移动时,保持圆圈的保留。为此,这次尝试提出了arc命令。

\draw (alpha:radius) arc (alpha:beta:radius);  % alpha=start angle, beta=end angle

在此处输入图片描述

代码:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{cblue/.style={circle, draw, thin,fill=cyan!20, scale=0.5}
}

\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=5pt,auto,thick, scale=2]
\draw [help lines] (-1,-1) grid (1,1);
\draw (90:1)     arc (90:30:1);
\draw (30:1)     arc (30:-20:1);
\draw (-20:1)    arc (-20:-180:1);
\draw (-180:1)   arc (-180:-270:1);
\node[cblue] (1) at ( 90:1 ) {1};
\node[cblue] (2) at ( 30:1 ) {2};
\node[cblue] (3) at ( 340:1) {3};
\node[cblue] (4) at ( 180:1) {4};
\end{tikzpicture}

\hspace{1cm}

\begin{tikzpicture}[->,>=stealth',shorten >=5pt,auto,thick,scale=2] 
\draw[help lines] (-1,-1) grid (1,1);
\draw (120:1)    arc (120:30:1);
\draw (30:1)     arc (30:-60:1);
\draw (-60:1)    arc (-60:-200:1);
\draw (-200:1)   arc (-200:-240:1);
\node[cblue] (1) at ( 120:1 ){1};
\node[cblue] (2) at ( 30:1 )  {2};
\node[cblue] (3) at ( 300:1) {3};
\node[cblue] (4) at ( 160:1) {4};
\end{tikzpicture}
\end{document}

相关内容