我到目前为止的代码如下,
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.fractals}
\begin{document}
\begin{tikzpicture}[font=\footnotesize, decoration=Koch curve type 1]
%%%%%%%%%%%%%%% Shape 1
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
%%%%%%%%%%%%%%%
\draw (A) rectangle (C);
\node at (1.5,1.5) {$S_1$};
%%%%%%%%%%%%%%% Shape 2
\begin{scope}[xshift=5cm]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
%%%%%%%%%%%%%%%
\draw decorate{ (D) -- (C) -- (B) -- (A) -- cycle};
\node at (1.5,1.5) {$S_2$};
\end{scope}
%%%%%%%%%%%%%%% Shape 3
\begin{scope}[xshift=11cm]
\coordinate (A) at (0,0);
\coordinate (B) at (3,0);
\coordinate (C) at (3,3);
\coordinate (D) at (0,3);
%%%%%%%%%%%%%%%
\draw decorate{ decorate{ (D) -- (C) -- (B) -- (A) -- cycle} };
\node at (1.5,1.5) {$S_3$};
\end{scope}
%%%%%%%%%%%%%%%
\end{tikzpicture}
\end{document}
我无法正确显示第三张图片。
规则:后续项是通过替换中间将前一个雪花模型中形成的新正方形的每个外边的三分之一,乘以 1/3 大小的正方形。
显然,我必须摆弄 Koch 曲线定义,但我对库的了解非常有限。任何帮助都非常感谢。
答案1
也许这不是最优雅的答案,但它可能是有用的。
\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{decorations.fractals}
% Creates a "_|-|_" looking shape defined by the start position, the start angle and the length of every segment of the path
\newcommand{\decoratededge}[3]{
\draw #1 -- ++ (90+#2:#3) decorate{--++ (180+#2:#3) --++ (90+#2:#3) --++ (0+#2:#3)} --++ (90+#2:#3);
}
\begin{document}
% Draws the manually defined 5 segment path
\begin{tikzpicture}
\decoratededge{(0,0)}{0}{1/3}
\end{tikzpicture}
% Draws the manually defined 5 segment path with a decoration of the 3 middle segments
\begin{tikzpicture}[font=\footnotesize, decoration=Koch curve type 1]
\decoratededge{(0,0)}{0}{1/3}
\end{tikzpicture}
% Draws the complete figure
\begin{tikzpicture}[font=\footnotesize, decoration=Koch curve type 1]
\decoratededge{(0,0)}{0}{1/3}
\decoratededge{(0,1)}{-90}{1/3}
\decoratededge{(1,1)}{-180}{1/3}
\decoratededge{(1,0)}{-270}{1/3}
\end{tikzpicture}
\end{document}
结果: