![多边形内含另一个多边形](https://linux22.com/image/456285/%E5%A4%9A%E8%BE%B9%E5%BD%A2%E5%86%85%E5%90%AB%E5%8F%A6%E4%B8%80%E4%B8%AA%E5%A4%9A%E8%BE%B9%E5%BD%A2.png)
我需要在一个更大的多边形(x)内制作一个多边形(y),如下图所示,但需要将 x 的每个顶点连接到 y 的两个相邻顶点:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[regular polygon, regular polygon sides=10, minimum size=8cm, draw=black, shape border rotate=30, name=x] at (6,6) {};
\node[regular polygon, regular polygon sides=5, minimum size=5cm, draw=black, shape border rotate=30, name=y] at (6,6) {};
\end{tikzpicture}
\end{document}
答案1
的顶点regular polygon
形状可以作为锚点.corner 1
、.corner 2
、... 来访问,我们可以用它们来连接多边形。
为此,我将外部 sep 设置为零,以便锚点位于线的中间,而不是字面上的角尖端。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
rp/.style={
regular polygon, draw, shape border rotate=30, outer sep=+0pt, regular polygon sides={#1}}]
\node[rp=10, minimum size=8cm, name=x] at (6,6) {};
\node[rp= 5, minimum size=5cm, name=y] at (6,6) {};
\draw foreach[
evaluate={\cornerA=int(2*\c);
\cornerB=int(\cornerA-1);}] \c in {1,...,5}{
(x.corner \cornerB) -- (y.corner \c) -- (x.corner \cornerA)};
\end{tikzpicture}
\end{document}