Example: Pythagorean triangle with the squares of its sides and labels

Published 2014-05-19 | Author: Alex Chan

We would like to to draw the squares of the sides of a Pythagorean triangle.

The width and height of the triangle are put into constants, so we can change them later if we need to. Loading them once and computing everything else on the fly, it makes it easier to change things around later

We label our coordinates so that the name matches the label which gets printed, otherwise we might get horribly confused.

Two of the rectangles (the ones matching the horizontal and vertical edges) are easy to draw. The square corresponding to the hypotenuse is a bit more difficult, but we can use a little plane geometry. We can find another edge of the square by rotating the original triangle through 90 degrees, and then translating appropriately. We can use the same method to find the two extra coordinates of the hypotenuse square in TikZ.

This example was written by Alex Chan answering a question on TeX.SE.

Download as: [PDF] [TEX]

Pythagorean triangle with the squares of its sides and labels

Do you have a question regarding this example, TikZ or LaTeX in general? Just ask in the LaTeX Forum.
Oder frag auf Deutsch auf TeXwelt.de. En français: TeXnique.fr.

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}
\begin{tikzpicture}
  \coordinate [label={below right:$A$}] (A) at (0, 0);
  \coordinate [label={above right:$B$}] (B) at (0, \pythagheight);
  \coordinate [label={below left:$C$}] (C) at (-\pythagwidth, 0);

  \coordinate (D1) at (-\pythagheight, \pythagheight + \pythagwidth);
  \coordinate (D2) at (-\pythagheight - \pythagwidth, \pythagwidth);

  \draw [very thick] (A) -- (C) -- (B) -- (A);

  \newcommand{\ranglesize}{0.3cm}
  \draw (A) -- ++ (0, \ranglesize) -- ++ (-\ranglesize, 0) -- ++ (0, -\ranglesize);

  \draw [dashed] (A) -- node [below] {$b$} ++ (-\pythagwidth, 0)
            -- node [right] {$b$} ++ (0, -\pythagwidth)
            -- node [above] {$b$} ++ (\pythagwidth, 0)
            -- node [left]  {$b$} ++ (0, \pythagwidth);

  \draw [dashed] (A) -- node [right] {$c$} ++ (0, \pythagheight)
            -- node [below] {$c$} ++ (\pythagheight, 0)
            -- node [left]  {$c$} ++ (0, -\pythagheight)
            -- node [above] {$c$} ++ (-\pythagheight, 0);

  \draw [dashed] (C) -- node [above left]  {$a$} (B)
                     -- node [below left]  {$a$} (D1)
                     -- node [below right] {$a$} (D2)
                     -- node [above right] {$a$} (C);
\end{tikzpicture}
\end{document}

Comments

Adding comments is currently not enabled.