I'm trying to draw a right triangle with sqares over its sides to illustrate Pythagoras' theorem. Here's my code
\begin{tikzpicture}[scale=4]
\coordinate[label=200:$A$] (A) at (0,0) ;
\coordinate[label=120:$B$] (B) at (0,1) ;
\coordinate[label=right:$C$] (C) at (1,0) ;
\draw (A) -- (B) -- (C) -- (A) ;
\draw (A) rectangle (0.08,0.08);
\draw[rotate=90] (A) let
\p1=(B),
\p2=(A),
\n1={veclen(\x2-\x1,\y2-\y1)}
in
rectangle (\n1,\n1);
\draw[rotate=270] (A) let
\p1=(C),
\p2=(A),
\n3={veclen(\x2-\x1,\y2-\y1)}
in
rectangle (\n3,\n3);
\draw[rotate=45] (C) let
\p2=(B),
\p1=(C),
\n2={veclen(\x2-\x1,\y2-\y1)}
in
rectangle (\n2,\n2);
\end{tikzpicture}
As far as I can see I'm doing nothing wrong. But the picture I get is the following:
Now there are more elegant solutions to this problem, for instance here; but I want to know why my code doesn't do what it is expected.
Thanks in advance!


(A)and end in coordinate((A) + (-\n1,\n1)).BandC,. Other two edges can be calculated by($(B)!\n3!90:(C)$)for coordinate perpendicular to coordinate(C)and($(C)!\n3!90:(B)$)(not tested, but should work). For details see 13.5.3 The Syntax of Partway Modifiers in TikZ manual. – Zarko Feb 29 '16 at 02:21