![以适当的方式连接节点](https://linux22.com/image/383352/%E4%BB%A5%E9%80%82%E5%BD%93%E7%9A%84%E6%96%B9%E5%BC%8F%E8%BF%9E%E6%8E%A5%E8%8A%82%E7%82%B9.png)
我如何将第 $n$ 个节点与 $n-1$ 个节点连接起来?
\documentclass[border=5pt,tikz]{standalone}
\tikzset{
io/.style={
fill=black,circle,inner sep=.1pt
}
}
\begin{document}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,10,...,350}
{
% \draw[rotate around={(-\x:(-\x:1))}] (0,0) -- (0,1) -- (.5,1) -- (.5,0) arc(0:-180:.25);
\node[rotate around={(\x:(\x:1))},io] {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\node[rotate around={(-\x:(4*\x:1))},io] {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{cos(\x)*\x}
\node[rotate around={(-\x:(\a:1))},io] {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{12*\x}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^sin(\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^cos(\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^sin(2*\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{17*\x}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
}
\end{tikzpicture}
\end{document}
输出如下:
答案1
这是针对您的第一张图片的答案,它适用于您的所有图片。
\documentclass[border=5pt,tikz]{standalone}
\tikzset{
io/.style={
fill=black,circle,inner sep=.1pt
}
}
\begin{document}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [count=\n] in {0,10,...,350}
{
% \draw[rotate around={(-\x:(-\x:1))}] (0,0) -- (0,1) -- (.5,1) -- (.5,0) arc(0:-180:.25);
\node[rotate around={(\x:(\x:1))},io] (io-\n) {};
\ifnum\n>1
\pgfmathtruncatemacro{\prevn}{\n-1}
\draw (io-\prevn) -- (io-\n);
\fi
\xdef\nmax{\n}
}
\draw (io-\nmax) -- (io-1);
\end{tikzpicture}
\end{document}
以下是完整内容。
\documentclass[border=5pt,tikz]{standalone}
\tikzset{
io/.style={
fill=black,circle,inner sep=.1pt
}
}
\begin{document}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [count=\n] in {0,10,...,350}
{
% \draw[rotate around={(-\x:(-\x:1))}] (0,0) -- (0,1) -- (.5,1) -- (.5,0) arc(0:-180:.25);
\node[rotate around={(\x:(\x:1))},io] (io-\n) {};
\ifnum\n>1
\pgfmathtruncatemacro{\prevn}{\n-1}
\draw (io-\prevn) -- (io-\n);
\fi
\xdef\nmax{\n}
}
\draw (io-\nmax) -- (io-1);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\node[rotate around={(-\x:(4*\x:1))},io] (io-\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (io-\prevx) -- (io-\x);
\fi
\xdef\xmax{\x}
}
\draw (io-\xmax) -- (io-0);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{cos(\x)*\x}
\node[rotate around={(-\x:(\a:1))},io] (io-\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (io-\prevx) -- (io-\x);
\fi
\xdef\xmax{\x}
}
\draw (io-\xmax) -- (io-0);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{12*\x}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (\prevx) -- (\x);
\fi
\xdef\xmax{\x}
}
\draw (\xmax) -- (0);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^sin(\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (\prevx) -- (\x);
\fi
\xdef\xmax{\x}
}
\draw (\xmax) -- (0);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^cos(\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (\prevx) -- (\x);
\fi
\xdef\xmax{\x}
}
\draw (\xmax) -- (0);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^sin(2*\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (\prevx) -- (\x);
\fi
\xdef\xmax{\x}
}
\draw (\xmax) -- (0);
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x in {0,1,...,359}
{
\pgfmathsetmacro{\a}{17*\x}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0
\pgfmathtruncatemacro{\prevx}{\x-1}
\draw (\prevx) -- (\x);
\fi
\xdef\xmax{\x}
}
\draw (\xmax) -- (0);
\end{tikzpicture}
\end{document}
答案2
非常漂亮!使用比您的图表简单得多的图表,我标记节点并使用以下代码记住标签:
\foreach \x [remember=\x as \X] in {0,10,...,350}
{
\node[rotate around={(\x:(\x:1))},io](\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
存储remember=\x as \X
节点标签的最后一个值(\x)
,然后我使用它\ifnum
来确保我位于第二个或更后面的标签。使用这个,您的第一个图表将变成:
如果您想要连接第一个和最后一个坐标,那么只需添加:
\draw(350)--(0);
完整代码如下:
\documentclass[border=5pt,tikz]{standalone}
\tikzset{
io/.style={
fill=black,circle,inner sep=.1pt
}
}
\begin{document}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,10,...,350}
{
% \draw[rotate around={(-\x:(-\x:1))}] (0,0) -- (0,1) -- (.5,1) -- (.5,0) arc(0:-180:.25);
\node[rotate around={(\x:(\x:1))},io](\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\node[rotate around={(-\x:(4*\x:1))},io] (\x){};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\pgfmathsetmacro{\a}{cos(\x)*\x}
\node[rotate around={(-\x:(\a:1))},io] (\x){};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\pgfmathsetmacro{\a}{12*\x}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^sin(\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^cos(\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\pgfmathsetmacro{\a}{\x^sin(2*\x)}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\begin{tikzpicture}
\useasboundingbox (-2,-2) rectangle (2,2);
\foreach \x [remember=\x as \X] in {0,1,...,359}
{
\pgfmathsetmacro{\a}{17*\x}
\draw[ultra thin] ([rotate around={(-\x:(\a:1))}]0,0) -- (0,0);
\node[rotate around={(-\x:(\a:1))},io] (\x) {};
\ifnum\x>0\draw(\X)--(\x);\fi
}
\end{tikzpicture}
\end{document}