绘制 7 节点多边形

绘制 7 节点多边形

我正在尝试绘制七边形的 7 个节点,我已经找到了如何绘制七边形的方法,但我不知道如何将每个节点标记为 1-7,然后如何在节点之间绘制边。

\begin{tikzpicture}[fill=white, thick, node distance = 2cm, auto,rotate=90,transform shape]
\foreach \a in {51.43,102.86,...,361} {%\a is the angle variable
\draw[fill] (\a:3cm) circle (10pt); % 2cm is the radius; 10pt is the radius of the small bullet
}
\end{tikzpicture}

答案1

您可以regular polygon在背景上使用七边形,并在其角上绘制标签。

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric}

\begin{document}

\begin{tikzpicture}

\node[draw, regular polygon, regular polygon sides=7, minimum size=3cm] (a) {};
\foreach \i in {1,2,...,7}
    \node[circle, draw, fill=white] at (a.corner \i) {\i};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您似乎正在寻找下图:

在此处输入图片描述

\documentclass[border=3mm,tikz]{standalone}
\usetikzlibrary{arrows.meta}

    \begin{document}

    \begin{tikzpicture}[
every node/.style = {circle, draw, fill=white, minimum size=1.5em},
       arr/.style = {-Stealth, shorten >=1pt}
                        ]
%%%% variable data
\def\numpoly{7}%number of nodes
\def\startangle{90}%angle of the first node
\def\pradius{32mm}
%------- calculations positions angles
\pgfmathparse{int(\startangle-360/\numpoly)}%
    \let\nextangle=\pgfmathresult
\pgfmathparse{int(\startangle-7*360/\numpoly)}%
    \let\endangle=\pgfmathresult
%--- polygon nodes
    \foreach \i [count=\ii from 0,  count=\k] in {\startangle,\nextangle,...,\endangle}
{
\path (\i:\pradius) node (p\ii) {\k};
}
%--- nodes interconnections
\foreach \i in {0,...,6}
{
    \pgfmathsetmacro{\ii}{int(Mod(\i+1,\numpoly))}
    \pgfmathsetmacro{\ij}{int(Mod(\i+2,\numpoly))}
    \pgfmathsetmacro{\ik}{int(Mod(\i+4,\numpoly))}
\draw[arr] (p\i) -- (p\ii);
\draw[arr] (p\i) -- (p\ij);
\draw[arr] (p\i) -- (p\ik);
}
     \end{tikzpicture}
\end{document}

笔记:上面的 MWE 可以绘制任意(规则)多边形。您只需选择在 中定义的节点数\def\numpoly{...}

相关内容