在 TikZ 中绘制复杂内接和外接多边形

在 TikZ 中绘制复杂内接和外接多边形

我正在为我的活动创建 Traveller TNE 角色和船舶表,并决定将其用作 TikZ 学习机会。但是,标题显示似乎超出了我目前的技能水平。具体来说,我似乎无法想出绘制三个内六边形和外十二边形上的方形标签的好主意:

在此处输入图片描述

我目前的代码是

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric}
\begin{document}
    \begin{tikzpicture}
    \node[draw,minimum size=5cm,regular polygon,regular polygon sides=12] (a) {};
    \draw ($(a.corner 2)!0.5!(a.corner 3)$) -- ($(a.corner 1)!0.5!(a.corner 12)$);
    \draw ($(a.corner 1)!0.5!(a.corner 12)$) -- ($(a.corner 10)!0.5!(a.corner 11)$);
    \draw ($(a.corner 10)!0.5!(a.corner 11)$) -- ($(a.corner 8)!0.5!(a.corner 9)$);
    \draw ($(a.corner 8)!0.5!(a.corner 9)$) -- ($(a.corner 6)!0.5!(a.corner 7)$);
    \draw ($(a.corner 6)!0.5!(a.corner 7)$) -- ($(a.corner 4)!0.5!(a.corner 5)$);
    \draw ($(a.corner 4)!0.5!(a.corner 5)$) -- ($(a.corner 2)!0.5!(a.corner 3)$);
    \end{tikzpicture}
\end{document}

我将非常感激有关正确结果的提示。TIA。

答案1

许多手动放置可能会编码得更漂亮,但以下内容接近您的图片(有些字体不匹配,因为我懒得搜索与数字匹配的字体):

\documentclass[border=3.14]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}

\begin{document}
\begin{tikzpicture}
  \draw[fill=gray!50,thick] (-4.5,-4.5) rectangle (4.5,4.5);
  \node[anchor=north, font=\sffamily\bfseries] at (0,4.5) {Heading Display};
  \node[fill,draw, minimum size=5cm, shape=regular polygon, regular polygon
    sides=6] (black) {};
  \node[fill=white, draw, minimum size=2.1cm, shape=regular polygon,
    regular polygon sides=6, rotate=30] at(-90:1.05cm) (innerB)  {};
  \node[fill=white, draw, minimum size=2.1cm, shape=regular polygon,
    regular polygon sides=6, rotate=30] at(30:1.05cm) (innerR)  {};
  \node[fill=white, draw, minimum size=2.1cm, shape=regular polygon,
    regular polygon sides=6, rotate=30] at(150:1.05cm) (innerL)  {};
  \node[anchor=north, font=\color{white}\sffamily\footnotesize, inner sep=5pt]
    at (black.north) {NEXT HEX};
  \begin{scope}[shift=(innerB),x=3mm, y=3mm]
    \filldraw (-.75,-1) -- (.75,-1) -- (0,1) -- cycle;
    \node[anchor=south, font=\sffamily\bfseries\tiny] at(0,1) {CURRENT};
    \node[anchor=north, font=\sffamily\bfseries\tiny] at(0,-1) {HEX};
  \end{scope}
  \foreach[count=\n]\x in {30,60,...,360}
    {
      \begin{scope}[shift=(90-\x:3.2cm),rotate=-\x]
        \draw[fill=white,thick]
          (-.5,-.5) -- (-.5,.5) -- (.5,.5) -- (.5,-.5) -- cycle;
        \draw[thick]
          (-.3,-.4) -- ++(0,.5) -- ++(-.1,0) -- ++(.4,.3) -- ++(.4,-.3)
          -- ++(-.1,0) -- ++(0,-.5) -- cycle
          ;
      \end{scope}
      \path (90-\x:3.2cm) node {\n};
    }
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

一切都是根据已知的 6 边形和 12 边形尺寸计算出来的。半径是一个定义好的变量,可以修改它来放大或缩小图形。\def\rayon{2.5cm}

箭头现在位于方块的中心,并且不会接触到方块的侧面。

截屏

\documentclass[tikz,border=5mm]{standalone}

\usetikzlibrary{calc,shapes}
\begin{document}
\def\rayon{2.5cm}
    \begin{tikzpicture}[every label/.style={draw,minimum size=1cm}]
    \node[draw,minimum size={2*\rayon},regular polygon,regular polygon sides=6,fill=black] (a) {};
        \node[circle,minimum size={\rayon * 2}](b){};
        \node[circle,minimum size={\rayon*2+sqrt(2-sqrt(3))*\rayon}](c){};
    \coordinate (i1) at ($(a.side 1)!.5!(a.side 5)$);
    \coordinate (i2) at ($(a.side 1)!.5!(a.side 3)$);
    \coordinate (i3) at ($(a.side 3)!.5!(a.side 5)$);
    \node[draw,minimum size={sqrt(3)/2*\rayon},regular polygon,regular polygon sides=6,rotate=30,fill=white]at(i1){};
    \node[draw,minimum size={sqrt(3)/2*\rayon},regular polygon,regular polygon sides=6,rotate=30,fill=white]at(i2){};
    \node[draw,minimum size={sqrt(3)/2*\rayon},regular polygon,regular polygon sides=6,rotate=30,fill=white]at(i3){};
    \begin{scope}[every label/.style={single arrow,draw,minimum size={sqrt(2-sqrt(3))*\rayon-10pt}}]
    \foreach \a [count=\n] in {60,30,...,-270}{
    \node[draw,minimum size={sqrt(2-sqrt(3))*\rayon},anchor=west,rotate=\a,label={[anchor=west,shift={(\a:5pt)},rotate=\a]west:\phantom{11}}] at (b.\a){};
    \node at (c.\a){\n};    
    }
    \end{scope}

    \end{tikzpicture}
\end{document}

相关内容