TiKZ 在绘制高比例因子的递归几何图形时放弃,最终以半心半意的曲线结束

TiKZ 在绘制高比例因子的递归几何图形时放弃,最终以半心半意的曲线结束

我正在尝试策划一场风车三角形(参见风车平铺)递归到其自身,以得到大致如下所示的内容:

以递归方式绘制的风车三角形

这是使用以下代码生成的:

\begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale=5]
        \coordinate [label=above: $A_{0}$] (A_0) at (0,1);
        \coordinate [label=below: $B_{0}$] (B_0) at (0,0);
        \coordinate [label=right: $C_{0}$] (C_0) at (2,0);
        \draw (A_0) -- (B_0) -- (C_0) -- (A_0);

        \coordinate [label=above: $A_{1}$]
        (A_1) at ($(A_0)!(B_0)!(C_0)$);
        \coordinate [label=below: $C_{1}$]
        (C_1) at ($(B_0)!0.5!(C_0)$);
        \coordinate [label=above: $H_{0}$]
        (H_0) at ($(A_0)!(C_1)!(C_0)$);
        \coordinate [label=left: $B_{1}$]
        (B_1) at ($(A_1)!(C_1)!(B_0)$);
        \coordinate [label=above: $A_{2}$]
        (A_2) at ($(A_1)!(B_1)!(C_1)$);
        \coordinate [label=below: $C_{2}$]
        (C_2) at ($(B_1)!0.5!(C_1)$);
        \coordinate [label=above: $H_{1}$]
        (H_1) at ($(A_1)!(C_2)!(C_1)$);
        \coordinate [label=left: $B_{2}$]
        (B_2) at ($(A_2)!(C_2)!(B_1)$);

        \coordinate (A_3) at ($(A_2)!(B_2)!(C_2)$);
        \coordinate (C_3) at ($(B_2)! 0.5 !(C_2)$);
        \coordinate (H_2) at ($(A_2)!(C_3)!(C_2)$);
        \coordinate (B_3) at ($(A_3)!(C_3)!(B_2)$);
        \coordinate (A_4) at ($(A_3)!(B_3)!(C_3)$);
        \coordinate (C_4) at ($(B_3)! 0.5 !(C_3)$);
        \coordinate (H_3) at ($(A_3)!(C_4)!(C_3)$);
        \coordinate (B_4) at ($(A_4)!(C_4)!(B_3)$);
        \coordinate (A_5) at ($(A_4)!(B_4)!(C_4)$);
        \coordinate (C_5) at ($(B_4)! 0.5 !(C_4)$);
        \coordinate (H_4) at ($(A_4)!(C_5)!(C_4)$);
        \coordinate (B_5) at ($(A_5)!(C_5)!(B_4)$);
        \coordinate (A_6) at ($(A_5)!(B_5)!(C_5)$);
        \coordinate (C_6) at ($(B_5)! 0.5 !(C_5)$);
        \coordinate (H_5) at ($(A_5)!(C_6)!(C_5)$);
        \coordinate (B_6) at ($(A_6)!(C_6)!(B_5)$);
        \coordinate (A_7) at ($(A_6)!(B_6)!(C_6)$);
        \coordinate (C_7) at ($(B_6)! 0.5 !(C_6)$);
        \coordinate (H_6) at ($(A_6)!(C_7)!(C_6)$);
        \coordinate (B_7) at ($(A_7)!(C_7)!(B_6)$);
        \coordinate (A_8) at ($(A_7)!(B_7)!(C_7)$);
        \coordinate (C_8) at ($(B_7)! 0.5 !(C_7)$);
        \coordinate (H_7) at ($(A_7)!(C_8)!(C_7)$);
        \coordinate (B_8) at ($(A_8)!(C_8)!(B_7)$);
        \coordinate (A_9) at ($(A_8)!(B_8)!(C_8)$);
        \coordinate (C_9) at ($(B_8)! 0.5 !(C_8)$);
        \coordinate (H_8) at ($(A_8)!(C_9)!(C_8)$);
        \coordinate (B_9) at ($(A_9)!(C_9)!(B_8)$);

        \draw (A_1) -- (B_0);
        \draw (C_1) -- (H_0);
        \draw (B_1) -- (C_1);
        \draw (A_1) -- (C_1);
        \draw (A_2) -- (B_1);
        \draw (C_2) -- (H_1);
        \draw (B_2) -- (C_2);
        \draw (A_2) -- (C_2);
        \draw (A_3) -- (B_2);
        \draw (C_3) -- (H_2);
        \draw (B_3) -- (C_3);
        \draw (A_3) -- (C_3);
        \draw (A_4) -- (B_3);
        \draw (C_4) -- (H_3);
        \draw (B_4) -- (C_4);
        \draw (A_4) -- (C_4);
        \draw (A_5) -- (B_4);
        \draw (C_5) -- (H_4);
        \draw (B_5) -- (C_5);
        \draw (A_5) -- (C_5);
        \draw (A_6) -- (B_5);
        \draw (C_6) -- (H_5);
        \draw (B_6) -- (C_6);
        \draw (A_6) -- (C_6);
        \draw (A_7) -- (B_6);
        \draw (C_7) -- (H_6);
        \draw (B_7) -- (C_7);
        \draw (A_7) -- (C_7);
        \draw (A_8) -- (B_7);
        \draw (C_8) -- (H_7);
        \draw (B_8) -- (C_8);
        \draw (A_8) -- (C_8);
        \draw (A_9) -- (B_8);
        \draw (C_9) -- (H_8);
        \draw (B_9) -- (C_9);
        \draw (A_9) -- (C_9);

    \end{tikzpicture}
    \label{pinwheel-triangle-infinite}
\end{figure}

我想放大细节,以更大的放大倍数欣赏风车平铺的结构。因此,我使用了独立格式,以便以更大的比例生成三角形的副本。我使用了以下代码:

\documentclass[11pt]{standalone}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
% The coordinate math engine in tikz has an error that makes it inaccurate at
% calculating extremely fine coordinates. This redefinition fixes the problem:
% https://tex.stackexchange.com/questions/256333/256377
% use the Mark Wibrow's correction
\makeatletter
\def\pgfpointnormalised#1{%
  \pgf@process{#1}%
  \pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
  \let\pgf@tmp=\pgfmathresult%
  \pgfmathcos@{\pgf@tmp}\pgf@x=\pgfmathresult pt\relax%
  \pgfmathsin@{\pgf@tmp}\pgf@y=\pgfmathresult pt\relax%
}

\begin{document}
\begin{figure}[h]
    \centering
    \begin{tikzpicture}[rotate=90, scale=30]
        \coordinate [label=above: $A_{0}$] (A_0) at (0,1);
        \coordinate [label=below: $B_{0}$] (B_0) at (0,0);
        \coordinate [label=right: $C_{0}$] (C_0) at (2,0);
        \draw (A_0) -- (B_0) -- (C_0) -- (A_0);
        \coordinate [label=above: $A_{1}$]
        (A_1) at ($(A_0)!(B_0)!(C_0)$);
        \coordinate [label=below: $C_{1}$]
        (C_1) at ($(B_0)!0.5!(C_0)$);
        \coordinate [label=above: $H_{0}$]
        (H_0) at ($(A_0)!(C_1)!(C_0)$);
        \coordinate [label=left: $B_{1}$]
        (B_1) at ($(A_1)!(C_1)!(B_0)$);
        \coordinate [label=above: $A_{2}$]
        (A_2) at ($(A_1)!(B_1)!(C_1)$);
        \coordinate [label=below: $C_{2}$]
        (C_2) at ($(B_1)!0.5!(C_1)$);
        \coordinate [label=above: $H_{1}$]
        (H_1) at ($(A_1)!(C_2)!(C_1)$);
        \coordinate [label=left: $B_{2}$]
        (B_2) at ($(A_2)!(C_2)!(B_1)$);
        \coordinate (A_3) at ($(A_2)!(B_2)!(C_2)$);
        \coordinate (C_3) at ($(B_2)! 0.5 !(C_2)$);
        \coordinate (H_2) at ($(A_2)!(C_3)!(C_2)$);
        \coordinate (B_3) at ($(A_3)!(C_3)!(B_2)$);
        \coordinate (A_4) at ($(A_3)!(B_3)!(C_3)$);
        \coordinate (C_4) at ($(B_3)! 0.5 !(C_3)$);
        \coordinate (H_3) at ($(A_3)!(C_4)!(C_3)$);
        \coordinate (B_4) at ($(A_4)!(C_4)!(B_3)$);
        \coordinate (A_5) at ($(A_4)!(B_4)!(C_4)$);
        \coordinate (C_5) at ($(B_4)! 0.5 !(C_4)$);
        \coordinate (H_4) at ($(A_4)!(C_5)!(C_4)$);
        \coordinate (B_5) at ($(A_5)!(C_5)!(B_4)$);
        \coordinate (A_6) at ($(A_5)!(B_5)!(C_5)$);
        \coordinate (C_6) at ($(B_5)! 0.5 !(C_5)$);
        \coordinate (H_5) at ($(A_5)!(C_6)!(C_5)$);
        \coordinate (B_6) at ($(A_6)!(C_6)!(B_5)$);
        \coordinate (A_7) at ($(A_6)!(B_6)!(C_6)$);
        \coordinate (C_7) at ($(B_6)! 0.5 !(C_6)$);
        \coordinate (H_6) at ($(A_6)!(C_7)!(C_6)$);
        \coordinate (B_7) at ($(A_7)!(C_7)!(B_6)$);
        \coordinate (A_8) at ($(A_7)!(B_7)!(C_7)$);
        \coordinate (C_8) at ($(B_7)! 0.5 !(C_7)$);
        \coordinate (H_7) at ($(A_7)!(C_8)!(C_7)$);
        \coordinate (B_8) at ($(A_8)!(C_8)!(B_7)$);
        \coordinate (A_9) at ($(A_8)!(B_8)!(C_8)$);
        \coordinate (C_9) at ($(B_8)! 0.5 !(C_8)$);
        \coordinate (H_8) at ($(A_8)!(C_9)!(C_8)$);
        \coordinate (B_9) at ($(A_9)!(C_9)!(B_8)$);
        \draw[thin] (A_1) -- (B_0);
        \draw[thin] (C_1) -- (H_0);
        \draw[thin] (B_1) -- (C_1);
        \draw[thin] (A_1) -- (C_1);
        \draw[thin] (A_2) -- (B_1);
        \draw[thin] (C_2) -- (H_1);
        \draw[thin] (B_2) -- (C_2);
        \draw[thin] (A_2) -- (C_2);
        \draw[thin] (A_3) -- (B_2);
        \draw[thin] (C_3) -- (H_2);
        \draw[thin] (B_3) -- (C_3);
        \draw[thin] (A_3) -- (C_3);
        \draw[thin] (A_4) -- (B_3);
        \draw[thin] (C_4) -- (H_3);
        \draw[thin] (B_4) -- (C_4);
        \draw[thin] (A_4) -- (C_4);
        \draw[thin] (A_5) -- (B_4);
        \draw[thin] (C_5) -- (H_4);
        \draw[thin] (B_5) -- (C_5);
        \draw[thin] (A_5) -- (C_5);
        \draw[thin] (A_6) -- (B_5);
        \draw[thin] (C_6) -- (H_5);
        \draw[thin] (B_6) -- (C_6);
        \draw[thin] (A_6) -- (C_6);
        \draw[thin] (A_7) -- (B_6);
        \draw[thin] (C_7) -- (H_6);
        \draw[thin] (B_7) -- (C_7);
        \draw[thin] (A_7) -- (C_7);
        \draw[thin] (A_8) -- (B_7);
        \draw[thin] (C_8) -- (H_7);
        \draw[thin] (B_8) -- (C_8);
        \draw[thin] (A_8) -- (C_8);
        \draw[thin] (A_9) -- (B_8);
        \draw[thin] (C_9) -- (H_8);
        \draw[thin] (B_9) -- (C_9);
        \draw[thin] (A_9) -- (C_9);
    \end{tikzpicture}
\end{figure}
\end{document}

然而,由于 TiKZ 的坐标数学引擎存在某种浮点计算问题,似乎错误正在累积并破坏了图表。我没有得到一个漂亮的风车图,而是得到了一些半心半意的曲线。

丑陋、糟糕的曲线

请注意,即使我申请Mark Wibrow 的修复,问题没有解决。看来这个问题是受缩放比例影响的。上图是以 30 的比例绘制的。如果我增加到 50,情况就更糟了。

感谢您的时间和考虑。我很乐意找到解决这个问题的方法。

PS:我了解我的代码使用了多次坐标计算。如果有某种方法可以优化它(也许是循环?)以减少坐标计算,那也很好。

答案1

这里的基本思想是不使用坐标投影,而是简单地通过插值获取点,然后使用递归和变换厌恶. 其结果是代码更短:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc}
\pgfmathparse{1/sqrt(5)}\let\k=\pgfmathresult
\pgfmathparse{asin(\k)}\let\b=\pgfmathresult
\newcommand\pinwheel[2][]{\begin{scope}[#1]\PinWheel{0}{#2}\end{scope}}
\def\PinWheel#1#2{%
\pgfmathparse{int(#1)}\let\pw=\pgfmathresult%
\pgfmathparse{sqrt(1/(\pw + 1)}\let\sc=\pgfmathresult
\path 
  (0, 1) coordinate (A) node [scale=\sc, anchor=270-\b*\pw] {$A_\pw$}
  (0, 0) coordinate (B) node [scale=\sc, anchor= 45-\b*\pw] {$B_\pw$}
  (2, 0) coordinate (C) node [scale=\sc, anchor=180-\b*\pw] {$C_\pw$};
\draw (A) -- (B) -- (C) -- cycle;
\ifnum\pw<#2
\path
  ($(A)!0.2!(C)$) coordinate (P) ($(B)!0.5!(P)$) coordinate (Q)
  ($(P)!0.5!(C)$) coordinate (R) ($(B)!0.5!(C)$) coordinate (S);
\draw (B) -- (Q) (S) -- (R) node [scale=\sc, anchor=225-\b*\pw] {$H_\pw$};
\begin{scope}[shift=(Q), scale=\k, rotate=-\b]
  \PinWheel{\pw+1}{#2}
\end{scope}
\fi}
\begin{document}
\begin{tikzpicture}[line join=round]
\pinwheel[scale=3]{3}
\end{tikzpicture}
\end{document}

在此处输入图片描述

但是,如果你想要一幅漂亮的图画,可以大致使用相同的原则:

\documentclass[varwidth,border=5]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\pgfmathparse{1/sqrt(5)}\let\k=\pgfmathresult
\pgfmathparse{acos(\k)}\let\a=\pgfmathresult
\pgfmathparse{asin(\k)}\let\b=\pgfmathresult
\newcount\pinwheelorder
\def\pinwheel#1{%
\begin{scope}
\pgfmathsetcount\pinwheelorder{#1}%
\edef\order{\the\pinwheelorder}
\path
  ($(0,1)!0.2!(2,0)$) coordinate (P-\order)
  ($(0,0)!0.5!(P-\order)$)   coordinate (Q-\order)
  ($(P-\order)!0.5!(2,0)$)   coordinate (R-\order);
\begin{scope}[shift=(P-\order), scale=\k, xscale=-1, rotate=-\a]
  \path [every triangle/.try, triangle 1/.try] (0,0) -- (0,1) -- (2,0) -- cycle;
  \ifnum\pinwheelorder>0
    \pinwheel{\pinwheelorder-1}
  \fi
\end{scope}
\begin{scope}[shift=(Q-\order), scale=\k, xscale=-1, rotate=270-\a] 
  \path [every triangle/.try, triangle 2/.try] (0,0) -- (0,1) -- (2,0) -- cycle; 
  \ifnum\pinwheelorder>0
    \pinwheel{\pinwheelorder-1}
  \fi
\end{scope}
\begin{scope}[shift=(Q-\order), scale=\k, rotate=-\b]
  \path [every triangle/.try, triangle 3/.try] (0,0) -- (0,1) -- (2,0) -- cycle;
  \ifnum\pinwheelorder>0
    \pinwheel{\pinwheelorder-1}
  \fi
\end{scope}
\begin{scope}[shift=(R-\order), scale=\k, rotate=180-\b]
  \path [every triangle/.try, triangle 4/.try] (0,0) -- (0,1) -- (2,0) -- cycle;
  \ifnum\pinwheelorder>0
    \pinwheel{\pinwheelorder-1}
  \fi
\end{scope}
\begin{scope}[shift=(R-\order), scale=\k, xscale=-1, rotate=270-\a]
  \path [every triangle/.try, triangle 5/.try] (0,0) -- (0,1) -- (2,0) -- cycle;
  \ifnum\pinwheelorder>0
    \pinwheel{\pinwheelorder-1}
  \fi
\end{scope}
\end{scope}
}
\tikzset{
  every triangle/.style={draw=white, thick, line join=round},
  triangle 1/.style={fill=red},
  triangle 2/.style={fill=orange},
  triangle 3/.style={fill=yellow},
  triangle 4/.style={fill=purple},
  triangle 5/.style={fill=pink}}
\begin{document}
\tikz[scale=5]{\pinwheel{0}}
\tikz[scale=5]{\pinwheel{1}}
\tikz[scale=5]{\pinwheel{2}}
\tikz[scale=5]{\pinwheel{3}}
\end{document}

在此处输入图片描述

答案2

scale我的建议是:只有在绝对必要时才使用选项 或 。在您的代码中,该scale选项仅用于定义A_0B_0C_0

\documentclass[11pt]{standalone}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
% The coordinate math engine in tikz has an error that makes it inaccurate at
% calculating extremely fine coordinates. This redefinition fixes the problem:
% https://tex.stackexchange.com/questions/256333/256377
% use the Mark Wibrow's correction
\makeatletter
\def\pgfpointnormalised#1{%
  \pgf@process{#1}%
  \pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
  \let\pgf@tmp=\pgfmathresult%
  \pgfmathcos@{\pgf@tmp}\pgf@x=\pgfmathresult pt\relax%
  \pgfmathsin@{\pgf@tmp}\pgf@y=\pgfmathresult pt\relax%
}
\makeatother

\begin{document}
\begin{tikzpicture}[rotate=90]
  \begin{scope}[scale=30]
    \coordinate [label=above: $A_{0}$] (A_0) at (0,1);
    \coordinate [label=below: $B_{0}$] (B_0) at (0,0);
    \coordinate [label=right: $C_{0}$] (C_0) at (2,0);
  \end{scope}
  \draw (A_0) -- (B_0) -- (C_0) -- (A_0);
  \coordinate [label=above: $A_{1}$]
  (A_1) at ($(A_0)!(B_0)!(C_0)$);
  \coordinate [label=below: $C_{1}$]
  (C_1) at ($(B_0)!0.5!(C_0)$);
  \coordinate [label=above: $H_{0}$]
  (H_0) at ($(A_0)!(C_1)!(C_0)$);
  \coordinate [label=left: $B_{1}$]
  (B_1) at ($(A_1)!(C_1)!(B_0)$);
  \coordinate [label=above: $A_{2}$]
  (A_2) at ($(A_1)!(B_1)!(C_1)$);
  \coordinate [label=below: $C_{2}$]
  (C_2) at ($(B_1)!0.5!(C_1)$);
  \coordinate [label=above: $H_{1}$]
  (H_1) at ($(A_1)!(C_2)!(C_1)$);
  \coordinate [label=left: $B_{2}$]
  (B_2) at ($(A_2)!(C_2)!(B_1)$);
  \coordinate (A_3) at ($(A_2)!(B_2)!(C_2)$);
  \coordinate (C_3) at ($(B_2)! 0.5 !(C_2)$);
  \coordinate (H_2) at ($(A_2)!(C_3)!(C_2)$);
  \coordinate (B_3) at ($(A_3)!(C_3)!(B_2)$);
  \coordinate (A_4) at ($(A_3)!(B_3)!(C_3)$);
  \coordinate (C_4) at ($(B_3)! 0.5 !(C_3)$);
  \coordinate (H_3) at ($(A_3)!(C_4)!(C_3)$);
  \coordinate (B_4) at ($(A_4)!(C_4)!(B_3)$);
  \coordinate (A_5) at ($(A_4)!(B_4)!(C_4)$);
  \coordinate (C_5) at ($(B_4)! 0.5 !(C_4)$);
  \coordinate (H_4) at ($(A_4)!(C_5)!(C_4)$);
  \coordinate (B_5) at ($(A_5)!(C_5)!(B_4)$);
  \coordinate (A_6) at ($(A_5)!(B_5)!(C_5)$);
  \coordinate (C_6) at ($(B_5)! 0.5 !(C_5)$);
  \coordinate (H_5) at ($(A_5)!(C_6)!(C_5)$);
  \coordinate (B_6) at ($(A_6)!(C_6)!(B_5)$);
  \coordinate (A_7) at ($(A_6)!(B_6)!(C_6)$);
  \coordinate (C_7) at ($(B_6)! 0.5 !(C_6)$);
  \coordinate (H_6) at ($(A_6)!(C_7)!(C_6)$);
  \coordinate (B_7) at ($(A_7)!(C_7)!(B_6)$);
  \coordinate (A_8) at ($(A_7)!(B_7)!(C_7)$);
  \coordinate (C_8) at ($(B_7)! 0.5 !(C_7)$);
  \coordinate (H_7) at ($(A_7)!(C_8)!(C_7)$);
  \coordinate (B_8) at ($(A_8)!(C_8)!(B_7)$);
  \coordinate (A_9) at ($(A_8)!(B_8)!(C_8)$);
  \coordinate (C_9) at ($(B_8)! 0.5 !(C_8)$);
  \coordinate (H_8) at ($(A_8)!(C_9)!(C_8)$);
  \coordinate (B_9) at ($(A_9)!(C_9)!(B_8)$);
  \draw[thin] (A_1) -- (B_0);
  \draw[thin] (C_1) -- (H_0);
  \draw[thin] (B_1) -- (C_1);
  \draw[thin] (A_1) -- (C_1);
  \draw[thin] (A_2) -- (B_1);
  \draw[thin] (C_2) -- (H_1);
  \draw[thin] (B_2) -- (C_2);
  \draw[thin] (A_2) -- (C_2);
  \draw[thin] (A_3) -- (B_2);
  \draw[thin] (C_3) -- (H_2);
  \draw[thin] (B_3) -- (C_3);
  \draw[thin] (A_3) -- (C_3);
  \draw[thin] (A_4) -- (B_3);
  \draw[thin] (C_4) -- (H_3);
  \draw[thin] (B_4) -- (C_4);
  \draw[thin] (A_4) -- (C_4);
  \draw[thin] (A_5) -- (B_4);
  \draw[thin] (C_5) -- (H_4);
  \draw[thin] (B_5) -- (C_5);
  \draw[thin] (A_5) -- (C_5);
  \draw[thin] (A_6) -- (B_5);
  \draw[thin] (C_6) -- (H_5);
  \draw[thin] (B_6) -- (C_6);
  \draw[thin] (A_6) -- (C_6);
  \draw[thin] (A_7) -- (B_6);
  \draw[thin] (C_7) -- (H_6);
  \draw[thin] (B_7) -- (C_7);
  \draw[thin] (A_7) -- (C_7);
  \draw[thin] (A_8) -- (B_7);
  \draw[thin] (C_8) -- (H_7);
  \draw[thin] (B_8) -- (C_8);
  \draw[thin] (A_8) -- (C_8);
  \draw[thin] (A_9) -- (B_8);
  \draw[thin] (C_9) -- (H_8);
  \draw[thin] (B_9) -- (C_9);
  \draw[thin] (A_9) -- (C_9);
\end{tikzpicture}
\end{document}

在此处输入图片描述

这里有一个缩短代码的解决方案\foreach(结果与上面的相同,除了标签):

\documentclass[11pt,tikz]{standalone}
\usetikzlibrary{calc}
% The coordinate math engine in tikz has an error that makes it inaccurate at
% calculating extremely fine coordinates. This redefinition fixes the problem:
% https://tex.stackexchange.com/questions/256333/256377
% use the Mark Wibrow's correction
\makeatletter
\def\pgfpointnormalised#1{%
  \pgf@process{#1}%
  \pgfmathatantwo{\the\pgf@y}{\the\pgf@x}%
  \let\pgf@tmp=\pgfmathresult%
  \pgfmathcos@{\pgf@tmp}\pgf@x=\pgfmathresult pt\relax%
  \pgfmathsin@{\pgf@tmp}\pgf@y=\pgfmathresult pt\relax%
}
\makeatother

\begin{document}
\begin{tikzpicture}[rotate=90,line join=round]
  \begin{scope}[scale=30]
    \coordinate [label=above: $A_{0}$] (A-0) at (0,1);
    \coordinate [label=below: $B_{0}$] (B-0) at (0,0);
    \coordinate [label=right: $C_{0}$] (C-0) at (2,0);
  \end{scope}
  \draw (A-0) -- (B-0) -- (C-0) -- (A-0);

  \foreach \lev in {1,...,9}{
    \pgfmathsetmacro{\plev}{int(\lev-1)}
    \coordinate (A-\lev) at ($(A-\plev)!(B-\plev)!(C-\plev)$);
    \coordinate (C-\lev) at ($(B-\plev)!.5!(C-\plev)$);
    \coordinate (H-\plev) at ($(A-\plev)!(C-\lev)!(C-\plev)$);
    \coordinate (B-\lev) at ($(A-\lev)!(C-\lev)!(B-\plev)$);
    \draw[thin] (A-\lev) -- (B-\plev);
    \draw[thin] (C-\lev) -- (H-\plev);
    \draw[thin] (A-\lev) -- (B-\lev) -- (C-\lev) -- cycle;
  }
\end{tikzpicture}
\end{document}

相关内容