这是我尝试用来为毕达哥拉斯定理的证明制作动画的代码:
\documentclass[tikz]{standalone}
\begin{document}
\foreach \t in {0,0.2,...,1}{%
\begin{tikzpicture}[rounded corners = 0.3pt,opacity=0.5]
\newcommand\lc{10cm};
\newcommand\anga{37};
\coordinate (A) at (0,0);
\coordinate (B) at (\lc,0);
\coordinate (C) at (\lc,\lc);
\coordinate (D) at (0,\lc);
\coordinate (E) at
({\lc*cos(\anga)*cos(\anga)},{\lc*cos(\anga)*sin(\anga)});
\coordinate (F) at
({\lc-\lc*cos(\anga)*sin(\anga)},{\lc*cos(\anga)*cos(\anga)});
\coordinate (G) at
({\lc-\lc*cos(\anga)*cos(\anga)},{\lc-\lc*cos(\anga)*sin(\anga)});
\coordinate (H) at
({\lc*cos(\anga)*sin(\anga)},{\lc-\lc*cos(\anga)*cos(\anga)});
\filldraw[very thick,black,fill=blue!50!white,draw=black] (A) --
(B) -- (E) -- cycle;
\filldraw[very thick,black,fill=orange,draw=black] (B) -- (C) --
(F) -- cycle;
\begin{scope}[yshift=-\lc*\t]
\filldraw[very thick,black,fill=green!50!white,draw=black]
(C) -- (D) -- (G) -- cycle;
\end{scope}
\filldraw[very thick,black,fill=red!50!white,draw=black] (D) --
(A) -- (H) -- cycle;
\filldraw[very thick,black,fill=yellow,draw=black] (E) -- (F) --
(G) -- (H) -- cycle;
\end{tikzpicture}
}
\end{document}
问题是:绿色三角形没有向下移动...我尝试使用“++()”将变换应用于三角形的每个点(甚至是“循环”),有时,但并非总是,三角形会消失......
我哪里做错了 ?
谢谢你的帮助。
答案1
不在定义的坐标shift
内起作用。scope
您可以指定要修改的每个坐标上的偏移量(并删除环境scope
)
\filldraw[very thick,black,fill=green!50!white,draw=black] ([yshift=-\lc*\t]C) -- ([yshift=-\lc*\t]D) -- ([yshift=-\lc*\t]G) -- cycle;
或者不使用定义的坐标
\begin{scope}[yshift=-\lc*\t]
\filldraw[very thick,black,fill=green!50!white,draw=black] (\lc,\lc) -- (0,\lc) -- ({\lc-\lc*cos(\anga)*cos(\anga)},{\lc-\lc*cos(\anga)*sin(\anga)}) -- cycle;
\end{scope}