有没有办法画出这个图形,让它不那么凌乱?我希望两个内六边形的顶点恰好位于某些对角线的交点上,就像我在给定的图片中画的那样。我知道我可以用
\begin{tikzpicture}[
dot/.style={circle,fill, inner sep=1.5pt, outer sep=0pt},
every label/.style={inner sep=0pt}]
\newdimen\R
\R=1.3cm
\draw[red]
(300:\R) \foreach \x in {360,60} { -- (\x:\R) };
\foreach \i [count=\j] in {1,2,3,4,5,6}
{
\node (n\j) [dot, label=60*\j:$\i$] at (60*\j:\R) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw (n\i) -- (n\j);
\else
\foreach \j in {\i,...,6}
\draw (n\i) -- (n\j);
\fi
}
\end{tikzpicture}
但我不确定如何像我描述的那样在这个六边形内添加两个六边形(顺便说一下,都是正六边形),以及手绘图片中来自顶点 $v$ 的红线。我该怎么做呢?最好不需要顶点的标签 ${1,...,6}$。
答案1
另一种稍微更紧凑的方法可能是这样的:
\documentclass[border=2mm]{standalone}
\usepackage{ifthen}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
\foreach\r in {1,2,4} \foreach[count=\i]\a in {0,60,...,300}
{% coordinates
\coordinate (\i-\r) at (\a:\r);
}
\foreach\r in {1,2,4} \foreach\i in {1,...,5}
{% gray lines
\pgfmathtruncatemacro\ii{\i+1}
\foreach\j in {\ii,...,6}
{%
\pgfmathtruncatemacro\d{\j-\i}
\ifthenelse{\NOT\(\d=3\) \OR \r=4}
{% to avoid duplicating the diagonals
\draw[gray] (\i-\r) -- (\j-\r);
}{}
}
}
\foreach\i in {2,3,5,6}
{% red lines
\draw[red] (4-4) -- (\i-1);
}
\foreach\r in {1,2,4} \foreach\i in {1,...,6}
{% dots
\fill (\i-\r) circle (2pt);
}
% labels
\node at (4-4) [left] {$V_1$};
\node at (4-2) [left] {$V_2$}; % 2 is the hexagon radius, 4 for the fourth vertex starting east, anticlockwise
\end{tikzpicture}
\end{document}
答案2
我只是使用了你的代码并改变了半径。
有轮廓
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usepackage{contour}
\contournumber{32}
\begin{document}
\begin{tikzpicture}[
dot/.style={circle,fill, inner sep=1pt, outer sep=0pt},
every label/.style={inner sep=0pt,font=\tiny,}
]
\def\Ra{2cm}
\def\Rb{1cm}
\def\Rc{0.5cm}
\foreach \i [count=\j] in {1,...,6}
{
\node (na-\j) [dot, label=60*\j:\contour{white}{\i}] at (60*\j:\Ra) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw[gray] (na-\i) -- (na-\j);
\else
\foreach \j in {\i,...,6}
\draw[gray] (na-\i) -- (na-\j);
\fi
}
\foreach \i [count=\j] in {1,...,6}
{
\node (nb-\j) [dot, label=60*\j:\contour{white}{\i}] at (60*\j:\Rb) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw[gray] (nb-\i) -- (nb-\j);
\else
\foreach \j in {\i,...,6}
\draw[gray] (nb-\i) -- (nb-\j);
\fi
}
\foreach \i [count=\j] in {1,...,6}
{
\node (nc-\j) [dot, label=60*\j:\contour{white}{\i}] at (60*\j:\Rc) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw[gray] (nc-\i) -- (nc-\j);
\else
\foreach \j in {\i,...,6}
\draw[gray] (nc-\i) -- (nc-\j);
\fi
}
\foreach \i in {1,2,4,5} {
\draw[red] (na-3) -- (nc-\i);
}
\end{tikzpicture}
\end{document}
无标签
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
dot/.style={circle,fill, inner sep=1pt, outer sep=0pt},
every label/.style={inner sep=0pt,font=\tiny,}
]
\def\Ra{2cm}
\def\Rb{1cm}
\def\Rc{0.5cm}
\foreach \i [count=\j] in {1,...,6}
{
\node (na-\j) [dot] at (60*\j:\Ra) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw[gray] (na-\i) -- (na-\j);
\else
\foreach \j in {\i,...,6}
\draw[gray] (na-\i) -- (na-\j);
\fi
}
\foreach \i [count=\j] in {1,...,6}
{
\node (nb-\j) [dot] at (60*\j:\Rb) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw[gray] (nb-\i) -- (nb-\j);
\else
\foreach \j in {\i,...,6}
\draw[gray] (nb-\i) -- (nb-\j);
\fi
}
\foreach \i [count=\j] in {1,...,6}
{
\node (nc-\j) [dot] at (60*\j:\Rc) {};
}
\foreach \i in {1,...,6}
{
\ifnum\i=1
\foreach \j in {2,...,6}
\draw[gray] (nc-\i) -- (nc-\j);
\else
\foreach \j in {\i,...,6}
\draw[gray] (nc-\i) -- (nc-\j);
\fi
}
\foreach \i in {1,2,4,5} {
\draw[red] (na-3) -- (nc-\i);
}
\end{tikzpicture}
\end{document}
答案3
有了regular polygon
形状,就可以使用更紧凑的代码:
\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}[
hexagon/.style={
regular polygon,
regular polygon sides=6,
draw,
minimum size=#1
}
]
\foreach \i/\dim in {a/6cm,b/3cm,c/1.5cm}{
\node[hexagon=\dim,clip] (\i) {};
\foreach \j/\list in {1/{3,4,5},2/{4,5,6},3/{5,6},4/{6}}{
\foreach \k in \list
\draw[thin, gray] (\i.corner \j)--(\i.corner \k);
}
\foreach \j in {1,2,...,6}
\fill ([shift={(60*\j+180:\pgflinewidth)}]\i.corner \j) circle (1pt);
}
\foreach \i in {1,2,4,5}
\draw[red] (a.corner 3)--(c.corner \i);
\node also [label=left:$v_1$, label=right:$v_2$] (a);
\end{tikzpicture}
\end{document}
答案4
这里有两个带有graphs
库的解决方案。
这很简单,只需在彼此的顶部绘制三组六边形,并且每组都是完全连接的(→
K_n
)。绘制连接六边形路径上节点的边
black
。由于这是一个simple
图形,因此这些边不会被绘制两次。但是,边缘仍然绘制在其他边缘之上。如果节点未填充,则看起来不太好。
此解决方案可确保不会有边绘制在另一个边之上。
仅对最内六边形绘制所有边。对于每个节点,仅添加通向下一个外六边形的三条边。
我擅自根据级别更改了点的样式(更小、更薄)。
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{graphs.standard, quotes, ext.misc}
\tikzset{
dots/.style={fill, draw, circle, inner sep=+.2em, thick},
graphs/every graph/.append style={
nodes=dots, empty nodes, edges=gray, simple,
clockwise, phase=180, radius=6cm, n=6}}
\begin{document}
\begin{tikzpicture}
\foreach \i in {0, ..., 2}
\graph[simple, name=\i, radius/.expanded=\pgfkeysvalueof{/tikz/graphs/radius}/2^\i]
{subgraph K_n, subgraph C_n[edges=black]};
\graph[use existing nodes]{
0 1, 0 4, 0 4["$v_2$" right],
0 1["$v_1$" left] --[red, very thick] {2 2, 2 3, 2 5, 2 6}
};
\end{tikzpicture}
\begin{tikzpicture}[
dots/.append style={fill=none, inner sep=+.2em/1.3^\i, line width=.6pt/1.3^\i}]
\newcommand*\maxIter{6}
\graph[simple, V={0,...,5}]{
\foreach[count=\j from -1] \i in {0, ..., \maxIter} {
{[name=\i, radius/.expanded=\pgfkeysvalueof{/tikz/graphs/radius}/2^\i,
/utils/TeX/ifnum={\i=\maxIter}{parse={subgraph K_n, subgraph C_n[edges=black]}}
{parse={subgraph C_n[edges=black]}}]},
{[/utils/TeX/ifnum={\i>0}{parse={
\foreach[evaluate={\p=int(Mod(\k-1,6)); % Previous and Next
\n=int(Mod(\k+1,6));}]\k in {0, ..., 5}{
\i\space\k -- {\j\space\p, \j\space\k, \j\space\n}}}}{}]}}};
\graph[use existing nodes]{
0 0, 0 3, 0 3["$v_2$" right],
0 0["$v_1$" left] --[red, very thick] {2 1, 2 2, 2 4, 2 5}
};
\end{tikzpicture}
\end{document}