我想绘制希尔伯特曲线和勒贝格曲线的一阶。为了绘制希尔伯特曲线,我使用以下 tikZ 代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\pgfdeclarelindenmayersystem{Hilbert curve}{
\rule{L -> +RF-LFL-FR+}
\rule{R -> -LF+RFR+FL-}}
\begin{tabular}{cc}
\begin{tikzpicture}
\shadedraw [bottom color=white, top color=white, draw=black]
[l-system={Hilbert curve, axiom=L, order=4, step=8pt, angle=90}]
lindenmayer system;
\end{tikzpicture}
\end{tabular}
\end{document}
然后我尝试将第一批订单并排排列,得到了以下结果:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\pgfdeclarelindenmayersystem{Hilbert curve}{
\rule{L -> +RF-LFL-FR+}
\rule{R -> -LF+RFR+FL-}}
\begin{tabular}{cc}
\begin{tikzpicture}
\foreach \i in {1,...,4}{
\begin{scope}[xshift=2*\i cm,yshift=0cm,rotate=0]
\shadedraw [bottom color=white, top color=white, draw=black]
[l-system={Hilbert curve, axiom=L, order=\i, step=8pt, angle=90}]
lindenmayer system;
\end{scope}
}
\end{tikzpicture}
\end{tabular}
\end{document}
但它们的排列不太好。我怎样才能让它们具有相同的大小并且彼此之间的距离恒定?
我将不胜感激任何帮助!
答案1
这似乎可以解决问题:按其大小缩放每个,根据每个计算\i
根据数学计算,你的绘图尺寸为:
value of \i relative size formula
1 1 2^1 - 1
2 3 2^2 - 1
3 7 2^3 - 1
4 15 2^4 - 1
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\begin{document}
\pgfdeclarelindenmayersystem{Hilbert curve}{
\rule{L -> +RF-LFL-FR+}
\rule{R -> -LF+RFR+FL-}}
\begin{tikzpicture}[scale=10]
\foreach \i in {1,...,4}{
\begin{scope}[xshift=.5*\i cm,yshift=0cm,rotate=0, scale = 1/(2^(\i)-1)]
\shadedraw [bottom color=white, top color=white, draw=black]
[l-system={Hilbert curve, axiom=L, order=\i, step=8pt, angle=90}]
lindenmayer system;
\end{scope}
}
\end{tikzpicture}
\end{document}
干杯,
答案2
没有 Lindenmayer 系统,只有recursive
。
在这里编译:http://asymptote.ualberta.ca/
仅限静态版本!
你可以在以下位置找到它的动画(相似之处)你的问题。
path Hilbertcurve(pair A, pair B, int ite=1){
path[] g;
if (ite == 1){
g.push((A+(B-A)/4)--(xpart(A+(B-A)/4),ypart(A+3*(B-A)/4))--
(A+3*(B-A)/4)--(xpart(A+3*(B-A)/4),ypart(A+(B-A)/4)));
}
else {
g.push(rotate(-90,(A+(B-A)/4))*reverse(Hilbertcurve(A,(A+B)/2, ite-1)));
g.push(Hilbertcurve((A.x,ypart((A+B)/2)),(xpart((A+B)/2),B.y), ite-1));
g.push(Hilbertcurve((A+B)/2,B, ite-1));
g.push(rotate(90,(xpart(A+3*(B-A)/4),ypart(A+(B-A)/4)))*reverse(Hilbertcurve((xpart((A+B)/2),A.y),(B.x,ypart((A+B)/2)), ite-1)));
}
return operator --(... g);
}
unitsize(1cm);
draw(Hilbertcurve((0,0),(4,4),4));
shipout(bbox(2mm,invisible));