答案1
该问题可以用正多边形的节点形状来解决:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[
regular polygon,
regular polygon sides=16,
minimum size=4cm,
rotate=180/16,
] (a) {};
\draw[blue]
(a.corner 15) \foreach \i in {16, 1, 2, 3, 4, 5} { -- (a.corner \i) }
(a.corner 7) \foreach \i in {8, ..., 14} { -- (a.corner \i) }
;
\draw[densely dashed]
(a.corner 5) -- (a.corner 14)
(a.corner 7) -- (a.corner 15)
;
\fill[radius=1pt] \foreach \i in {1, ..., 16} { (a.corner \i) circle[] };
\end{tikzpicture}
\end{document}
第二个类似:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[
regular polygon,
regular polygon sides=16,
minimum size=4cm,
rotate=180/16,
] (a) {};
\draw[blue]
(a.corner 14) \foreach \i in {15, 16, 1, 2, 3} { -- (a.corner \i) }
(a.corner 5) \foreach \i in {6, ..., 13} { -- (a.corner \i) }
;
\draw[densely dashed]
(a.corner 3) -- (a.corner 13)
(a.corner 5) -- (a.corner 14)
;
\fill[radius=1pt] \foreach \i in {1, ..., 16} { (a.corner \i) circle[] };
\end{tikzpicture}
\end{document}
无节点极坐标的替代方法
在下面的例子中,角按逆时针方向从 0 到 15 编号,从右侧的零角度开始。
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\path
(0, 0)
\foreach \i in {0, ..., 15} {
+(360/16 * \i:3cm) coordinate (corner \i)
}
;
\draw[blue]
(corner 2) \foreach \i in {3, ..., 8} { -- (corner \i) }
(corner 10) \foreach \i in {11, ..., 15, 0, 1} { -- (corner \i) }
;
\draw[densely dashed]
(corner 1) -- (corner 8)
(corner 2) -- (corner 10)
;
\fill[radius=1pt] \foreach \i in {0, ..., 15} { (corner \i) circle[] };
\end{tikzpicture}
\end{document}