微调五边形网络

微调五边形网络

我使用以下代码创建了五边形网络的主要版本:

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=black,minimum size=.2cm,inner sep=0pt,anchor=center},
d/.style={draw,circle,fill=white,minimum size=.5cm,inner sep=0pt, anchor=center}}
\begin{tikzpicture}[font=\large]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[draw, regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){};
    \node (outerpoly\Ncorners-\x) at (outerpoly\Ncorners.corner \x){$R_\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}

在此处输入图片描述

我想从以下几个方面来改进网络:

1)将这些节点标签放置在圆圈内;

2) 在适当位置用标签 $y_{ij}$ 标记每个连接,其中 i 和 j 是两个关联节点的索引;

3) 将两条特定的连接线及其标签(例如 $y_{23}$ 和 $y_{35}$)涂成红色。

谢谢你!

答案1

这最多只能算是一个临时解决办法。问题是数字太小,标签会被卡住。

\documentclass{book}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric,backgrounds}
\begin{document}

\def\r{4pt}
\def\dy{1cm}
\tikzset{c/.style={draw,circle,fill=black,minimum size=.2cm,inner sep=0pt,anchor=center},
d/.style={draw,circle,fill=white,minimum size=.5cm,inner sep=0pt, anchor=center}}
\begin{tikzpicture}[font=\large]
\pgfmathtruncatemacro{\Ncorners}{5}
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3cm] 
(poly\Ncorners) {};
\node[regular polygon,regular polygon sides=\Ncorners,minimum size=3.5cm] 
(outerpoly\Ncorners) {};
\foreach\x in {1,...,\Ncorners}{
    \node[d] (poly\Ncorners-\x) at (poly\Ncorners.corner \x){$R_\x$};
}
\foreach\X [evaluate=\X as \NextX using {int(\X+1)}]in {1,...,\Ncorners}{
\ifnum\NextX<6
 \foreach\Y in {\NextX,...,\Ncorners}{
 \pgfmathtruncatemacro{\Ztest}{10*\X+\Y}
 \ifnum\Ztest=23
  \colorlet{mycolor}{red}
 \else
  \ifnum\Ztest=35
   \colorlet{mycolor}{red}
  \else
   \colorlet{mycolor}{black}
  \fi
 \fi
 \draw[color=mycolor] (poly\Ncorners-\X) -- node[midway,fill=white,font=\tiny,sloped,inner
 sep=0.2pt]{$y_{\X\Y}$} (poly\Ncorners-\Y);
 }
\fi
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

为了好玩,下面是一个简短的代码pstricks

\documentclass[border=12pt, svgnames]{standalone}

\usepackage{pst-poly}
\usepackage{auto-pst-pdf}

\begin{document}

\psset{unit=3.5cm, dimen=middle, linejoin=1, linewidth=1.2pt}
\begin{pspicture}(-1,-1)(1,1)
    \providecommand{\PstPolygonNode}{\psdots[dotsize=16pt, linecolor=Lavender!75 ](1;\INode)}
    \rput{72}(0,0){\PstPentagon[PolyName=R] }
    \rput(0,0){\PstPentagon[PolyName=A, PolyOffset=2] }
    \foreach \i in {1,2,3,4,5} {\rput(R\i){$R_{\i}$}}
    \psset{linestyle=none, nrot =:U}
    \foreach\i/\j in {1/4,1/5,2/4,2/5,3/4,3/5,4/5}{\ncline{R\i}{R\j}\ncput{\colorbox{white}{$y_{\i\j}$}}}
    \ncline{R2}{R1}\ncput{\colorbox{white}{$y_{12}$}}
    \psset{linestyle=solid, linewidth=1.25pt, linecolor=Tomato, nodesep=8pt}
    \foreach \i/\j in {2/3,3/5} {\ncline{R\i}{R\j}\ncput{\colorbox{white}{\color{Tomato}$y_{\i\j}$}}}
\end{pspicture}

\end{document}

在此处输入图片描述

相关内容