我有一组三个六边形的正多边形,这些正多边形是我使用 shapes tikz 包中的正多边形创建的。但是,这总是会创建底部有平面的多边形。如何以最少的代码更改获得底部的一个角:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\def\x{0}
\def\y{0}
\def\r{1.5}
\pgfmathsetmacro\dx{\r*(1+cos(60))}
\pgfmathsetmacro\dy{\r*sin(60)}
\pgfmathsetmacro\dAx{\r*cos(60)}
\pgfmathsetmacro\dAy{\r*sin(60)}
\pgfmathsetmacro\dBx{\r*cos(120)}
\pgfmathsetmacro\dBy{\r*sin(120)}
\pgfmathsetmacro\d{2*\r}
\def\xc{\x} %mittelpunkt des aktuellen hexagons
\def\yc{\y}
\node[draw, regular polygon, regular polygon sides=6,minimum size=\d cm]
at (\x,\y) {};
\node[circle, radius=0.15cm, label=A, fill=black] (A) at (\xc+\dAx,
\yc+\dAy) {};
\node[circle, radius=0.15cm, label=below:A, fill=black] (AA) at
(\xc+\dAx,\yc-\dAy) {};
\node[circle, radius=0.15cm, label=A, fill=black] at (\xc-\r,\yc) {};
\node[circle, radius=0.15cm, label=B, fill=gray] at (\xc+\dBx,\yc+\dBy) {};
\node[circle, radius=0.15cm, label=below:B, fill=gray] at (\xc+\dBx, \yc-\dBy) {};
\def\xc{\x+\dx}
\def\yc{\y+\dy}
\node[draw, regular polygon, regular polygon sides=6,minimum size=\d cm]
at (\x+\dx,\y+\dy) {};
\node[circle, radius=0.15cm, label=A, fill=black] (AAA) at (\xc+\dAx,\yc+\dAy) {};
\node[circle, radius=0.15cm, label=right:A, fill=black] (AAAA) at (\xc+\dAx,\yc-\dAy) {};
\node[circle, radius=0.15cm, label=right:B, fill=gray] (BB) at (\xc+\r,\yc) {};
\node[circle, radius=0.15cm, label=B, fill=gray] at (\xc+\dBx,\yc+\dBy) {};
\def\xc{\x+\dx}
\def\yc{\y-\dy}
\node[draw, regular polygon, regular polygon sides=6,minimum size=\d cm]
at (\x+\dx,\y-\dy) {};
\node[circle, radius=0.15cm, label=below:A, fill=black] at (\xc+\dAx,\yc-\dAy) {};
\node[circle, radius=0.15cm, label=right:B, fill=gray] (BBB)at (\xc+\r,\yc) {};
\node[circle, radius=0.15cm, label=B, fill=gray] (B) at (\xc+\dBx,\yc+\dBy) {};
\node[circle, radius=0.15cm, label=below:B, fill=gray] (BBBB)at (\xc+\dBx,\yc-\dBy) {};
\end{tikzpicture}
\end{document}
答案1
shape border rotate
是可以用来旋转的参数shape
。但在这种情况下,您还需要更改标签的放置位置。
不幸的是,这个答案会改变你所有的代码。它使用六边形角作为参考点,也作为anchors
它们一个接一个地放置。希望这对你有帮助。
第一个例子不是rotated
,第二个例子有 30 度旋转。
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[%
point/.style={circle, radius=0.15cm, fill=#1},
hex/.style={draw, regular polygon, regular polygon sides=6,minimum size=3 cm}]
\node[hex] (A) {};
\node[hex, anchor=corner 4] (B) at (A.corner 2) {};
\node[hex, anchor=corner 6] (C) at (A.corner 2) {};
\foreach \i/\j/\k in {
B/1/above, B/3/above, B/5/right,
C/3/above, C/5/below, A/5/below}
\node[point=black, label=\k:A] at (\i.corner \j) {};
\foreach \i/\j/\k in {
B/2/above, B/4/above, B/6/right,
C/2/above, C/4/below, A/4/below, A/6/right}
\node[point=gray, label=\k:B] at (\i.corner \j) {};
\end{tikzpicture}
\begin{tikzpicture}[%
point/.style={circle, radius=0.15cm, fill=#1},
hex/.style={draw, regular polygon, regular polygon sides=6,minimum size=3 cm, shape border rotate=30}]
\node[hex] (A) {};
\node[hex, anchor=corner 4] (B) at (A.corner 2) {};
\node[hex, anchor=corner 6] (C) at (A.corner 2) {};
\foreach \i/\j/\k in {
B/1/above, B/3/left, B/5/right,
C/3/below, C/5/below, A/5/below}
\node[point=black, label=\k:A] at (\i.corner \j) {};
\foreach \i/\j/\k in {
B/2/above, B/4/above, B/6/right,
C/2/above, C/4/below, A/4/below, A/6/right}
\node[point=gray, label=\k:B] at (\i.corner \j) {};
\end{tikzpicture}
\end{document}
答案2
好的,下面是使用 tikz 库的更紧凑的形式shapes.geometric
:
\documentclass[border=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
%
\begin{document}
%
\begin{tikzpicture}
\foreach \a in {30,150,270}{
\node[regular polygon, regular polygon sides=6, draw, minimum size=3cm, rotate=30] (\a) at (\a:{1.5cm+.2pt}) {};
\foreach \b/\c in {1/2,3/4,5/6}{
\fill (\a.corner \c) circle (2.5pt) node [above] {A};
\fill[gray] (\a.corner \b) circle (2.5pt) node[black, below] {B};
}
}
\end{tikzpicture}
%
\end{document}
答案3
这是您的图表的简化版本。
输出
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\tikzset{
poly/.style={draw, regular polygon, regular polygon sides=6, rotate=30, minimum size=\d cm},
style1/.style={circle, fill=gray, label={below:B}},
style2/.style={circle, fill=black, label={above:A}},
}
\begin{document}
\begin{tikzpicture}
\def\x{0}
\def\y{0}
\def\r{1.5}
\pgfmathsetmacro\dx{\r*cos(30)}
\pgfmathsetmacro\dy{\r*cos(30)}
\pgfmathsetmacro\d{2*\r}
\def\xc{\x+\dx}
\node[poly] (n1) at (\x,\y) {};
\node[poly] (n2) at (\xc*2,\y) {};
\node[poly] (n3) at (\xc,\y-\r*1.5) {};
% foreach for all three
\foreach \xx/\group in {1/{1,2,3},2/{1,2,3,4,5,6},3/{2,3,4,5}}{%
\foreach \x [evaluate=\x as \angle using int(90+(60*(\x-1)))] in \group {%%
\pgfmathsetmacro\switch{int(mod(\x, 2)) ? "style1" : "style2"} % choose style
\node[\switch] at (n\xx.corner \x) {};
}
}
\end{tikzpicture}
\end{document}
答案4
并且(主要是为了娱乐,但部分是为了比较)这里有一个元帖子+luamplib根据 A 点形成三角形、B 点形成六边形的观察来实现。
使用lualatex
(或者适配普通的 Metapost) 进行编译。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(1);
path A, B; labeloffset := 5; u := 1cm;
A := for t=0 upto 2: (0,-2u) rotated 120t -- endfor cycle;
B := for t=0 upto 5: (1.732u,0) rotated 60t -- endfor cycle;
draw for t=0 upto 5: point (t+1)/2 of A -- point t of B -- endfor cycle;
for t=0 upto 2: draw origin -- point t+1/2 of A; endfor
for t=0 upto 5:
fill fullcircle scaled 4 shifted point (t+1)/2 of A;
fill fullcircle scaled 4 shifted point t of B withcolor .5 white;
label.top("A", point (t+1)/2 of A);
label.bot("B", point t of B);
endfor
fill fullcircle scaled 4 withcolor .5 white;
label.bot("B", origin);
endfig;
\end{mplibcode}
\end{document}