以适当的方式连接节点

以适当的方式连接节点

我如何将第 $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}

相关内容