1

This is a code I try to use to animate a proof of Pythagoras theorem :

\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 ({\lccos(\anga)cos(\anga)},{\lccos(\anga)sin(\anga)}); \coordinate (F) at ({\lc-\lccos(\anga)sin(\anga)},{\lccos(\anga)cos(\anga)}); \coordinate (G) at ({\lc-\lccos(\anga)cos(\anga)},{\lc-\lccos(\anga)sin(\anga)}); \coordinate (H) at ({\lccos(\anga)sin(\anga)},{\lc-\lccos(\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}

Problem is : the green triangle is not shifted down... I tried applying the transformation to each point of the triangle with "++()" (even to the "cycle"), sometimes, but not always, the triangle simply disappear...

Where did I go wrong ?

Thanks for any help.

NBur
  • 4,326
  • 10
  • 27
  • What do you want to animate? You don't use the \t parameter. Try to comment the line \newcommand\anga{37}; and replace the \foreach… line by \foreach \anga in {45,40,...,20}{% – NBur Feb 22 '21 at 16:04
  • Did you try compiling simpler versions? Try with just the first triangle, then try with just the first two, and build up that way to see where the problem appears. – Colin McLarty Feb 22 '21 at 16:06
  • Sorry, wrong code. It is corrected now : the \t parameter is used in the drawing command of the green triangle (in the scope). – Nicolas FRANCOIS Feb 22 '21 at 16:07
  • @ColinMcLarty : I did that. There is no compilation problem. Just, the green triangle (see new code example) is not shifted. – Nicolas FRANCOIS Feb 22 '21 at 16:08
  • I understand it is not a compilation problem. But the point remains to isolate where the problem is. Do you get the same problem when you omit the last two triangles? If you do, then maybe you could eliminate them from the code you post here. Can you can eliminate one of the first two triangles and still get the same problem? – Colin McLarty Feb 22 '21 at 16:17
  • I've already notice this behaviour: shift doesn't act within scope on defined coordinates (for what I've tested). As a workaround, you can code \filldraw[very thick,black,fill=green!50!white,draw=black] ([yshift=-\lc*\t]C) -- ([yshift=-\lc*\t]D) -- ([yshift=-\lc*\t]G) -- cycle; (without the scope environment). – NBur Feb 22 '21 at 16:20
  • @NBur : it works !!! Thank you ;-) Now I need to find in the documentation why the previous code doesn't work :-( – Nicolas FRANCOIS Feb 22 '21 at 16:22
  • @NBur : Yup :-) – Nicolas FRANCOIS Feb 22 '21 at 17:00

1 Answers1

1

The shift doesn't act within scope on defined coordinates.

You can specify the offset on each coordinate to be modified (and remove the scope environment)

\filldraw[very thick,black,fill=green!50!white,draw=black] ([yshift=-\lc*\t]C) -- ([yshift=-\lc*\t]D) -- ([yshift=-\lc*\t]G) -- cycle;

or not use defined coordinates

\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}
NBur
  • 4,326
  • 10
  • 27