如何在 tikz 中绘制图形

如何在 tikz 中绘制图形

基于绘制五边形图和标签经过土拨鼠(编辑曼努埃尔·库纳

我希望以与图像相同的方式从所有节点对角线绘制。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=white,minimum size=\r,inner sep=0pt,
anchor=center},
d/.style={draw,circle,fill=black,minimum size=\r,inner sep=0pt, anchor=center}}

\begin{tikzpicture}

\pgfmathtruncatemacro{\Ncorners}{5}
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=2cm] 
(poly\Ncorners) {};
\node[draw,regular polygon,regular polygon sides=\Ncorners,minimum size=4cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
    \node[d] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
    \draw (poly\Ncorners-\x) -- (outerpoly\Ncorners-\x);
}

\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) -- (poly\Ncorners-\Y);
\fi
}
}
\node at (0,-2) {$G^2$};
\end{tikzpicture}
\end{document}

例图: 在此处输入图片描述

答案1

我也不确定我是否理解了你的问题。所以也许最简单的方法就是我发布一些可能有用的内容,然后你告诉我还应该做什么。

\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=white,minimum size=\r,inner sep=0pt,
anchor=center},
d/.style={draw,circle,fill=black,minimum size=\r,inner sep=0pt, anchor=center}}

\begin{tikzpicture}

\pgfmathtruncatemacro{\Ncorners}{5}
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=2cm] 
(poly\Ncorners) {};
\node[draw,regular polygon,regular polygon sides=\Ncorners,minimum size=4cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
    \node[d] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
    \draw (poly\Ncorners-\x) -- (outerpoly\Ncorners-\x);
}

\foreach\X in {1,...,\Ncorners}{
\foreach\Y in {1,...,\Ncorners}{
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-2)}
\ifnum\Z=0
\draw (poly\Ncorners-\X) to (poly\Ncorners-\Y);
\draw (outerpoly\Ncorners-\X) to[bend left=15] (poly\Ncorners-\Y);
\draw (outerpoly\Ncorners-\X) to[bend left=30] (outerpoly\Ncorners-\Y);
\fi
\pgfmathtruncatemacro{\Z}{abs(mod(abs(\Ncorners+\X-\Y),\Ncorners)-1)}
\ifnum\Z=0
\draw (outerpoly\Ncorners-\X) to[bend left=15] (poly\Ncorners-\Y);
\fi
}
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容