Tikz 3 个完美六边形重叠的图片

Tikz 3 个完美六边形重叠的图片

对于一些大学的东西,我需要对齐 3 个完美的六边形,并且它们必须重叠,见下面的附图。这意味着,我需要每对节点之间的距离相等。当然,我可以手动计算并为每个节点提供其坐标。但有没有更简单的方法?例如使用角度?如果我可以在以下示例中使用角度而不是“右上方”,我会非常高兴。但我还没有找到办法。

\begin{tikzpicture}[>=stealth', shorten >=1pt, auto,
node distance=1cm, scale=1, 
transform shape, align=center, 
state/.style={circle, draw, minimum size=2.5em}]

\node[state]    (MP) {$v_{10}$};  
\node[state, above right=of MP] (GS) {$v_{10}$};
\node[state, above left=of MP] (BP) {$v_{10}$};

\path[-] (MP) edge node {} (GS)
(MP) edge node {} (GS)
(BP) edge node {} (MP);
\end{tikzpicture}

任何帮助和/或想法都值得赞赏!

干杯

我想要的结果

编辑:这是我在 Ignasi 的帮助下得到的。而且它很完美。作为奖励:我怎样才能在不“猜测”其大小的情况下将三角形 D 居中?目前尺寸 3.5 并不完美,而且“略有”偏移。并不是说它可以用眼睛看到,只是出于好奇!如果使用节点会更简单,我怎么才能准确地知道它的坐标?:)

\begin{tikzpicture}[
hexagon/.style={regular polygon, regular polygon sides=6, minimum size=6cm, outer sep=0pt},
triangle/.style={regular polygon, regular polygon sides=3, minimum size=3.5cm, outer sep=0pt, shape border rotate=180},
state/.style={circle, draw, minimum size=2.5em}]
\node[hexagon] (A) {A};
\node[hexagon, anchor=corner 4] at (A.corner 1) (B){B};
\node[hexagon, anchor=corner 2] at (B.corner 5) (C){C};
\node[triangle, anchor=corner 3] at (B.corner 4) (D) {D};

% Top Hexagon
\node[state, label=above:$1$] (4) at (B.corner 1) {$v_{4}$};
\node[state, label=above:$1$] (3) at (B.corner 2) {$v_{3}$};
\node[state, label=above:$1$] (2) at (B.corner 3) {$v_{2}$};
\node[state, label=above:$1$] (1) at (B.corner 4) {$v_{1}$};
\node[state, label=above:$1$] (6) at (B.corner 5) {$v_{6}$};
\node[state, label=above:$1$] (5) at (B.corner 6) {$v_{5}$};

% Right Hexagon
\node[state, label=above:$1$] (7) at (C.corner 1) {$v_{7}$};
\node[state, label=above:$1$] (11) at (C.corner 3) {$v_{11}$};
\node[state, label=above:$1$] (10) at (C.corner 4) {$v_{10}$};
\node[state, label=above:$1$] (9) at (C.corner 5) {$v_{9}$};
\node[state, label=above:$1$] (8) at (C.corner 6) {$v_{8}$};

% Left Hexagon
\node[state, label=above:$1$] (15) at (A.corner 2) {$v_{15}$};
\node[state, label=above:$1$] (14) at (A.corner 3) {$v_{14}$};
\node[state, label=above:$1$] (13) at (A.corner 4) {$v_{13}$};
\node[state, label=above:$1$] (12) at (A.corner 5) {$v_{12}$};

% Edges
\foreach \i in {1,...,14}{
    \path[-]
    (\i) edge node {} (\the\numexpr\i+1);
}
\path[-]
(1) edge node {} (6)
(6) edge node {} (11)
(11) edge node {} (1)
(15) edge node {} (1);
\end{tikzpicture}

在此处输入图片描述

答案1

像这样吗?

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric, positioning}
                
\begin{document}
                             
\begin{tikzpicture}[
  hexagon/.style={regular polygon, regular polygon sides=6, minimum size=2cm, outer sep=0pt, draw},
  mylabel/.style={circle, inner sep=1pt}
  ]

\node[hexagon] (A) {A};
\node[hexagon, anchor=corner 4] at (A.corner 1) (B){B};
\node[hexagon, anchor=corner 2] at (B.corner 5) (C){C};

\foreach \i in {A,B,C}{
    \foreach \j in {1,...,6}
        \filldraw (\i.corner \j) circle(1pt);
    }
    
\node[mylabel, right= 0mm of B.corner 6] {$v_1$};
\node[mylabel, above right= 0mm of B.corner 1] {$v_2$};
\node[mylabel, above left= 0mm of B.corner 2] {$v_3$};       
   
\end{tikzpicture}
\end{document}

在此处输入图片描述

最终版本?

对 OP 的代码做了一些小的修改:

  • 标签的位置D用 计算barycentric cs。看来我们需要特定的坐标(不接受锚点名称)并且坐标列表之间没有空格。
  • state定义已经改变以模拟边和顶点之间的距离。states是白色填充的圆圈,并且在内部绘制的圆圈中添加了一个path picture选项。

这是新代码:

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric, positioning}
                
\begin{document}

\begin{tikzpicture}[
hexagon/.style={regular polygon, regular polygon sides=6, minimum size=6cm, outer sep=0pt, draw},
state/.style={circle, fill=white, minimum size=2.5em, path picture={\draw[black] (path picture bounding box.center) circle(1em);}}]
\node[hexagon] (A) {A};
\node[hexagon, anchor=corner 4] at (A.corner 1) (B){B};
\node[hexagon, anchor=corner 2] at (B.corner 5) (C){C};
%\node at (3,1.8) {D};
\coordinate (aux1) at (B.corner 4);
\coordinate (aux2) at (B.corner 5);
\coordinate (aux3) at (C.corner 3);
\node at (barycentric cs:aux1=1,aux2=1,aux3=1) {D};

% Top Hexagon
\node[state, label=above:$1$] (12) at (B.corner 1) {$v_{4}$};
\node[state, label=above:$1$] (12) at (B.corner 2) {$v_{3}$};
\node[state, label=above:$1$] (12) at (B.corner 3) {$v_{2}$};
\node[state, label=above:$1$] (12) at (B.corner 4) {$v_{1}$};
\node[state, label=above:$1$] (12) at (B.corner 5) {$v_{6}$};
\node[state, label=above:$1$] (12) at (B.corner 6) {$v_{5}$};

% Right Hexagon
\node[state, label=above:$1$] (12) at (C.corner 1) {$v_{7}$};
\node[state, label=above:$1$] (12) at (C.corner 3) {$v_{11}$};
\node[state, label=above:$1$] (12) at (C.corner 4) {$v_{10}$};
\node[state, label=above:$1$] (12) at (C.corner 5) {$v_{9}$};
\node[state, label=above:$1$] (12) at (C.corner 6) {$v_{8}$};

% Left Hexagon
\node[state, label=above:$1$] (12) at (A.corner 2) {$v_{15}$};
\node[state, label=above:$1$] (12) at (A.corner 3) {$v_{14}$};
\node[state, label=above:$1$] (12) at (A.corner 4) {$v_{13}$};
\node[state, label=above:$1$] (12) at (A.corner 5) {$v_{12}$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

\foreach您的代码中存在严重冗余,您可以使用并将label=above...选项插入到 tikzset 中,从而轻松缩短代码。
此外,为了简化,您可以用triangle点 D 的简单重心定义替换 tikzset。
您的代码运行得很好,但我宁愿使用更短的代码:

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, positioning}

\begin{document}

\begin{tikzpicture}[
hexagon/.style={regular polygon, regular polygon sides=6, minimum size=6cm, outer sep=0pt},
state/.style={circle, draw, minimum size=2.5em, label=above:$1$}]
\node[hexagon] (A) {A};
\node[hexagon, anchor=corner 4] at (A.corner 1) (B){B};
\node[hexagon, anchor=corner 2] at (B.corner 5) (C){C};

\node at (barycentric cs:A=1,B=1,C=1) {D};  % <---- Here

% Top Hexagon
\foreach \nodenum/\corner in {4/1,3/2,2/3,1/4,6/5,5/6}
    {
    \node[state] (\nodenum) at (B.corner \corner) {$v_{\nodenum}$};
    }

% Right Hexagon
\foreach \nodenum/\corner in {7/1,11/3,10/4,9/5,8/6}
    {
    \node[state] (\nodenum) at (C.corner \corner) {$v_{\nodenum}$};
    }
    

% Left Hexagon
\foreach \nodenum/\corner in {15/2,14/3,13/4,12/5}
    {
    \node[state] (\nodenum) at (A.corner \corner) {$v_{\nodenum}$};
    }

% Edges
\foreach \i in {1,...,14}{
    \path[-]
    (\i) edge node {} (\the\numexpr\i+1);
}
\path[-]
(1) edge node {} (6)
(6) edge node {} (11)
(11) edge node {} (1)
(15) edge node {} (1);
\end{tikzpicture}

\end{document}

制作了相同的图片所以我没有添加任何图片。

相关内容