你可能会认为我没通过三角学,因为就我一生而言,我都无法弄清楚如何从同一点开始所有缩放的三角形。如果多边形有一个选项可以将基点从中心移动到左下角,那么在下面绘制就轻而易举了,但似乎没有这个选项。所以我尝试使用似乎是正确的三角公式来计算顶点偏离中心的偏移量,但它们没有起作用。
documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes.misc}
\begin{document}
\begin{figure}[!htb]
\resizebox{\linewidth}{!}{
\begin{tikzpicture}
\tikzstyle{every node}=[draw,thin]
\draw[help lines] (0,0) grid (4,4);
\foreach \a in {0,...,3}{
\node[scale={\a/sin(30)},regular polygon, regular polygon sides=3]
at ({(\a)*cos(30)}, {(\a)*sin(30)}) {};
}
\end{tikzpicture}
}
\caption{Triangular grid}
\end{figure}
\end{document}
答案1
使用变换和普通三角形(而不是节点)。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,...,6} {
\draw[scale=1/\i, rotate={60*(\i-1)}] (0,0) -- (1,0) -- ({cos(60)},{sin(60)}) -- cycle;
}
\end{tikzpicture}
\end{document}
答案2
可以使用regular polygons
(来自shapes.geometric
库)及其corner ...
锚点来绘制该图形。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,...,6}
\node[draw, regular polygon, regular polygon sides=3, minimum size=1cm/\i,
anchor=corner 2, shape border rotate={60*(\i-1)},
inner sep=0pt, outer sep=0pt] {};
\begin{scope}[xshift=2cm]
\foreach \i [evaluate=\i as \x using 100-7*\i] in {1,...,12}
\node[fill=blue!\x, regular polygon, regular polygon sides=4,
minimum size=1cm/\i, anchor=corner 3,
shape border rotate={90*(\i-1)}, inner sep=0pt,outer sep=0pt] {};
\end{scope}
\begin{scope}[xshift=4cm]
\foreach \i [evaluate=\i as \x using 10*\i]in {1,...,8}
\node[fill=red!\x, regular polygon, regular polygon sides=5,
minimum size=1cm/\i, anchor=corner 3,
shape border rotate={108*(\i-1)}, inner sep=0pt,outer sep=0pt] {};
\end{scope}
\end{tikzpicture}
\end{document}