我想创建 6 个并排的六边形,每个六边形的虚线边数与正常边数不同。这怎么可能呢?
我目前用来创建单个六边形的代码是:
\foreach \n in {1,2,...,6} {
\node at (\n*2.5-4,1)[above left] {\n$.$} ;
\draw [xshift=\n*2.5cm-3cm] (0:1cm) \foreach \x in {1,2,...,6} {
-- (\x*60:1cm)} --cycle (90:1cm);
}
如果没有简单的方法在循环中创建六边形,我不介意单独创建每个六边形,但我甚至不知道如何做到这一点。
编辑:澄清:我想要实现的基本上是一个六边形列表,每个六边形都有不同的虚线边缘“顺序”(即虚线边缘的所有可能变化,以至于您无法通过旋转六边形从一个六边形到达另一个六边形)。我觉得这个问题有点太宽泛了,所以我问了一个具有特定虚线图案的六边形的着色问题,但我想我还不够清楚(抱歉,英语不是我的母语,所以事情往往会变得混乱)。
我正在通过 Lyx 使用 TeX,但不太了解如何很好地使用它,所以我不知道如何发布 MWE,抱歉 :(。
答案1
如果你真的想满足约束
所有可能的虚线边变化,使得你无法通过旋转六边形从一个虚线变为另一个虚线
那么就需要一个替代解决方案。
每行的虚线边数都会增加,并且通过旋转对称等效的虚线边会应用不透明度:
代码:
\documentclass{article}
\usepackage{tikz}
\tikzset{Dashed/.style={dashed, red}}
\tikzset{Duplicate/.style={opacity=0.5, thin, gray}}
\newcommand{\Hexagon}[8][]{%
%\node at (#1*2.5-4,1)[above left] {$#1.$};
\begin{scope}[xshift=#2*2.5cm-3cm,#1] %,rotate=#1*60
\draw[solid, #3] ( 0:1cm) -- (1*60:1cm);
\draw[solid, #4] (1*60:1cm) -- (2*60:1cm);
\draw[solid, #5] (2*60:1cm) -- (3*60:1cm);
\draw[solid, #6] (3*60:1cm) -- (4*60:1cm);
\draw[solid, #7] (4*60:1cm) -- (5*60:1cm);
\draw[solid, #8] (5*60:1cm) -- (6*60:1cm);
\end{scope}
}%
\begin{document}
\begin{tikzpicture}[ultra thick, blue]
\Hexagon {1}{Dashed}{}{}{}{}{}
\Hexagon[Duplicate]{2}{}{Dashed}{}{}{}{}
\Hexagon[Duplicate]{3}{}{}{Dashed}{}{}{}
\Hexagon[Duplicate]{4}{}{}{}{Dashed}{}{}
\Hexagon[Duplicate]{5}{}{}{}{}{Dashed}{}
\Hexagon[Duplicate]{6}{}{}{}{}{}{Dashed}
\begin{scope}[yshift=-3cm]
\Hexagon {1}{Dashed}{Dashed}{}{}{}{}
\Hexagon {2}{Dashed}{}{Dashed}{}{}{}
\Hexagon {3}{Dashed}{}{}{Dashed}{}{}
\Hexagon[Duplicate]{4}{Dashed}{}{}{}{Dashed}{}
\Hexagon[Duplicate]{5}{Dashed}{}{}{}{}{Dashed}
\end{scope}
\begin{scope}[yshift=-6cm]
\Hexagon {1}{Dashed}{Dashed}{Dashed}{}{}{}
\Hexagon {2}{Dashed}{Dashed}{}{Dashed}{}{}
\Hexagon {3}{Dashed}{Dashed}{}{}{Dashed}{}
\Hexagon[Duplicate]{4}{Dashed}{}{}{}{Dashed}{Dashed}
\end{scope}
\begin{scope}[yshift=-9cm]
\Hexagon{1}{Dashed}{Dashed}{Dashed}{Dashed}{}{}
\Hexagon{2}{Dashed}{Dashed}{Dashed}{}{Dashed}{}
\Hexagon{3}{Dashed}{}{Dashed}{Dashed}{}{Dashed}
\end{scope}
\begin{scope}[yshift=-12cm]
\Hexagon {1}{Dashed}{Dashed}{Dashed}{Dashed}{Dashed}{}
\Hexagon[Duplicate]{2}{Dashed}{Dashed}{Dashed}{Dashed}{}{Dashed}
\end{scope}
\begin{scope}[yshift=-15cm]
\Hexagon{1}{Dashed}{Dashed}{Dashed}{Dashed}{Dashed}{Dashed}
\end{scope}
\end{tikzpicture}
\end{document}
答案2
如果您能向我们提供一张您想要实现的目标的图片,那么回答您的问题至少会更容易一些。
以下确实产生了 6 个不同的六边形:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \n in {1,2,...,6}
{
\node at (\n*2.5-4,1)[above left] {\n$.$};
\begin{scope}[xshift=\n*2.5cm-3cm,rotate=\n*60]
\draw[dashed] (0:1cm) -- (60:1cm);
\draw (60:1cm) \foreach \x in {2,...,6} {-- (\x*60:1cm)};
\end{scope}
}
\end{tikzpicture}
\end{document}
导致: