绘制带有顶点对的图形

绘制带有顶点对的图形

我想在 LaTex 中使用 Kneser 图 K(2,5) 符号绘制彼得森图。我将对超立方体执行相同操作。例如:请问我该怎么做? 在此处输入图片描述

答案1

该图的标签基于维基百科中的 Kneser 符号示例

\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\tikzset{c/.style={draw,circle,fill=black,minimum size=4pt,inner sep=0pt,
anchor=center},
d/.style={draw,circle,fill=white,minimum size=4pt,inner sep=0pt, anchor=center}}
% from https://tex.stackexchange.com/a/294254/121799
\def\colorlist{{"cyan", "red", "orange", "yellow", "green", "gray", "blue", "violet"}}

\begin{tikzpicture}[font=\tiny]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[draw,regular polygon,regular polygon sides=\Ncorners,minimum size=5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \pgfmathtruncatemacro{\myprevx}{ifthenelse(\x==1,5,mod(\Ncorners+\x-1,\Ncorners))}
    \pgfmathtruncatemacro{\mynextx}{mod(\Ncorners+\x,\Ncorners)+1}
    \pgfmathsetmacro\myfill{\colorlist[\myprevx]}
    \node[d,label={{18+\x*72}:{$\{\myprevx,\mynextx\}$}},color=\myfill] (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){};
    \pgfmathtruncatemacro{\myprevx}{ifthenelse(\x==2,5,mod(\Ncorners+\x-2,\Ncorners))}
    \pgfmathtruncatemacro{\mynextx}{mod(\Ncorners+\x+1,\Ncorners)+1}
    \ifcase\x
    \pgfmathtruncatemacro{\ang}{0}  
    \or
    \pgfmathtruncatemacro{\ang}{0}
    \or 
    \pgfmathtruncatemacro{\ang}{90}     
    \or 
    \pgfmathtruncatemacro{\ang}{120}        
    \or 
    \pgfmathtruncatemacro{\ang}{60}     
    \or 
    \pgfmathtruncatemacro{\ang}{90}     
    \fi
    \pgfmathsetmacro\myfill{\colorlist[\myprevx]}
    \node[d,label={{\ang}:{$\{\myprevx,\mynextx\}$}},color=\myfill] (poly\Ncorners-\x) at (poly\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
}
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

更新: 颜色。

相关内容