Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've made this checking the old questions and the TikZ manual and I want to draw the squares of the sides of my Pythagorean triangle.

So far I have

\documentclass{article}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[scale=1.25]%,cap=round,>=latex]

\coordinate [label=left:$C$] (A) at (-1.5cm,-1.cm);
\coordinate [label=right:$A$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);
\draw (A) -- node[above] {$a$} (B) -- node[right] {$c$} (C) -- node[below] {$b$} (A);

\draw (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);

\end{tikzpicture}

\end{document}

which produces

output

share|improve this question
    
Can you explain better what you mean by squares on the sides? Maybe make a sketch such that we can see what you talking about. –  collegeskier Mar 22 at 0:17
    
Also see this animated version... –  Werner Mar 22 at 2:09
3  
You sure you want squares? ;) math.stackexchange.com/a/676075/30160 –  Christian Mar 22 at 10:46

7 Answers 7

up vote 14 down vote accepted

First things first: let's make the width and height of the triangle into constants, so that we can change them later if we need to. These are the values that you used, but by loading them once and computing everything else on the fly, it makes it easier to change things around later:

\newcommand{\pythagwidth}{3cm}
\newcommand{\pythagheight}{2cm}

Next, relabel your coordinates so that the name matches the label which gets printed, otherwise we'll get horribly confused.

\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);

Two of the rectangles (the ones matching the horizontal and vertical edges) are easy to draw, if a little verbose:

\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);

These changes get us most of the way:

enter image description here

and then we need to draw the square corresponding to the hypotenuse. Computing the hypotenuse itself seems excessive (read: I’m tired and can’t remember how to do it now :P). Instead, we can use a little plane geometry:

enter image description here

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:

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

and then drawing this square is simple:

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

So putting this all together, we have:

\documentclass{article}

\usepackage{tikz}

\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}

which produces

enter image description here

share|improve this answer
    
You've read my mind! Excellent, thanks! –  user48419 Mar 22 at 1:08

A more simplified version than the original one; the idea here is simply to use

($ (<name1>) ! {sin(90)} ! 90:(<name2>) $)

to find a point in the perpendicular from <name1> to the line segment joining <name1> and <name2>; the distacence between the new point and <name1> is the same as the one between <name1> and <name2>:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[scale=1.25]
\coordinate [label=left:$A$] (A) at (-1.5cm,-1.cm);
\coordinate [label=below right:$C$] (C) at (1.5cm,-1.0cm);
\coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);

\draw 
  (A) -- 
  node[above] {$c$} (B) -- 
  node[right] {$b$} (C) -- 
  node[below] {$a$} 
  (A);
\draw 
  (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);

\coordinate (aux1) at
  ($ (A) ! {sin(90)} ! 90:(B) $);
\coordinate (aux2) at
  ($ (aux1) ! {sin(90)} ! 90:(A) $);

\coordinate (aux3) at
  ($ (A) ! {sin(90)} ! -90:(C) $);
\coordinate (aux4) at
  ($ (aux3) ! {sin(90)} ! -90:(A) $);

\coordinate (aux5) at
  ($ (C) ! {sin(90)} ! -90:(B) $);
\coordinate (aux6) at
  ($ (aux5) ! {sin(90)} ! -90:(C) $);

\draw[ultra thick,green,text=black]
  (A) -- 
  (aux1) node[midway,auto,swap] {$c$} -- 
  (aux2) node[midway,auto,swap] {$c$} -- 
  (B) node[midway,auto,swap] {$c$};
\draw[ultra thick,green,text=black]
  (A) -- 
  (aux3) node[midway,auto] {$a$} -- 
  (aux4) node[midway,auto] {$a$}  -- 
  (C) node[midway,auto] {$a$};
\draw[ultra thick,green,text=black]
  (C) -- 
  (aux5) node[midway,auto] {$b$} -- 
  (aux6) node[midway,auto] {$b$} -- 
  (B) node[midway,auto] {$b$};
\end{tikzpicture}

\end{document}

enter image description here

This allows the definition of a command for the construction of the squares in the general case (for any three non-colinear points):

\PythTr[<options>]{<name1>}{<name2>}{<name3>}{<coord1>}{<coord2>}{<coord3>}

where <name1>,...,<name3> are the names for the vertices and <coor1>,...,<coor3> are the coordinates for the three vertices; the optional argument can be used to pass options to control how the squares are drawn. For example, the figure below was obtained symply with

\begin{tikzpicture}
\PythTr{A}{B}{C}{(-1.5cm,-1.cm)}{(1.5cm,-1.0cm)}{(1.5cm,1.0cm)}
\end{tikzpicture}\par\bigskip

\begin{tikzpicture}
\PythTr[Maroon,dashed]{L}{M}{N}{(2,-2)}{(4,2)}{(0,2)}
\end{tikzpicture}

The code:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\PythTr[7][ultra thick,green,text=black]{%
\coordinate [label=left:$#2$] (#2) at #5;
\coordinate [label=below right:$#4$] (#4) at #6;
\coordinate [label=above:$#3$] (#3) at #7;

\draw 
  (#2) -- 
  node[auto] {$\MakeLowercase{#4}$} (#3) -- 
  node[auto] {$\MakeLowercase{#3}$} (#4) -- 
  node[auto] {$\MakeLowercase{#2}$} 
  (#2);

\coordinate (aux1) at
  ($ (#2) ! {sin(90)} ! 90:(#3) $);
\coordinate (aux2) at
  ($ (aux1) ! {sin(90)} ! 90:(#2) $);

\coordinate (aux3) at
  ($ (#2) ! {sin(90)} ! -90:(#4) $);
\coordinate (aux4) at
  ($ (aux3) ! {sin(90)} ! -90:(#2) $);

\coordinate (aux5) at
  ($ (#4) ! {sin(90)} ! -90:(#3) $);
\coordinate (aux6) at
  ($ (aux5) ! {sin(90)} ! -90:(#4) $);

\begin{scope}[#1]
\draw
  (#2) -- 
  (aux1) node[midway,auto,swap] {$\MakeLowercase{#4}$} -- 
  (aux2) node[midway,auto,swap] {$\MakeLowercase{#4}$} -- 
  (#3) node[midway,auto,swap] {$\MakeLowercase{#4}$};
\draw
  (#2) -- 
  (aux3) node[midway,auto] {$\MakeLowercase{#2}$} -- 
  (aux4) node[midway,auto] {$\MakeLowercase{#2}$}  -- 
  (#4) node[midway,auto] {$\MakeLowercase{#2}$};
\draw
  (#4) -- 
  (aux5) node[midway,auto] {$\MakeLowercase{#3}$} -- 
  (aux6) node[midway,auto] {$\MakeLowercase{#3}$} -- 
  (#3) node[midway,auto] {$\MakeLowercase{#3}$};
\end{scope}
}

\begin{document}

\begin{tikzpicture}
\PythTr{A}{B}{C}{(-1.5cm,-1.cm)}{(1.5cm,-1.0cm)}{(1.5cm,1.0cm)}
\end{tikzpicture}\par\bigskip

\begin{tikzpicture}
\PythTr[Maroon,dashed]{L}{M}{N}{(2,-2)}{(4,2)}{(0,2)}
\end{tikzpicture}

\end{document}

enter image description here

In case the construction has to be restricted to just rectangle triangles, here's the corresponding version:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\usetikzlibrary{calc}

\newcommand\PythTri[7][ultra thick,green,text=black]{%
\coordinate [label=left:$#2$] (#2) at #5;
\coordinate [label=below right:$#4$] (#4) at #6;
\coordinate (aux) at ($ #5 ! 1 ! 90:#6 $);
\coordinate [label=above:$#3$] (#3) at ($ #5 !#7!(aux) $);

\draw 
  (#2) -- 
  node[auto] {$\MakeLowercase{#4}$} (#3) -- 
  node[auto] {$\MakeLowercase{#3}$} (#4) -- 
  node[auto] {$\MakeLowercase{#2}$} 
  (#2);

\coordinate (aux1) at
  ($ (#2) ! {sin(90)} ! 90:(#3) $);
\coordinate (aux2) at
  ($ (aux1) ! {sin(90)} ! 90:(#2) $);

\coordinate (aux3) at
  ($ (#2) ! {sin(90)} ! -90:(#4) $);
\coordinate (aux4) at
  ($ (aux3) ! {sin(90)} ! -90:(#2) $);

\coordinate (aux5) at
  ($ (#4) ! {sin(90)} ! -90:(#3) $);
\coordinate (aux6) at
  ($ (aux5) ! {sin(90)} ! -90:(#4) $);

\begin{scope}[#1]
\draw
  (#2) -- 
  (aux1) node[midway,auto,swap] {$\MakeLowercase{#4}$} -- 
  (aux2) node[midway,auto,swap] {$\MakeLowercase{#4}$} -- 
  (#3) node[midway,auto,swap] {$\MakeLowercase{#4}$};
\draw
  (#2) -- 
  (aux3) node[midway,auto] {$\MakeLowercase{#2}$} -- 
  (aux4) node[midway,auto] {$\MakeLowercase{#2}$}  -- 
  (#4) node[midway,auto] {$\MakeLowercase{#2}$};
\draw
  (#4) -- 
  (aux5) node[midway,auto] {$\MakeLowercase{#3}$} -- 
  (aux6) node[midway,auto] {$\MakeLowercase{#3}$} -- 
  (#3) node[midway,auto] {$\MakeLowercase{#3}$};
\end{scope}
}

\begin{document}

\begin{tikzpicture}[scale=0.75]
\PythTri{A}{B}{C}{(0,4)}{(2,0)}{3cm}
\end{tikzpicture}\par\bigskip

\begin{tikzpicture}[scale=0.75]
\PythTri[Maroon,dashed]{L}{M}{N}{(0,0)}{(4,0)}{3cm}
\end{tikzpicture}\par\bigskip

\end{document}

enter image description here

Now the command has the syntax

\PythTri[<options>]{<name1>}{<name2>}{<name3>}{<coord1>}{<coord2>}{<length>}

where <coord1> and <coord2> are the coordinates for one of the cathetus and the sixth mandatory argument is used now for the length of the other cathetus.

Initial version:

One option using the calc library:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}[scale=1.25]
  \coordinate [label=left:$C$] (A) at (-1.5cm,-1.cm);
  \coordinate [label=right:$A$] (C) at (1.5cm,-1.0cm);
  \coordinate [label=above:$B$] (B) at (1.5cm,1.0cm);

\draw 
  (A) -- 
  node[above] {$a$} (B) -- 
  node[right] {$c$} (C) -- 
  node[below] {$b$} 
  (A);
\draw 
  (1.25cm,-1.0cm) rectangle (1.5cm,-0.75cm);
\draw[ultra thick,green] 
  let \p1= ( $ (C)-(A) $ )
  in (A) -- 
  ++(-90:{veclen(\x1,\y1)}) --       
  ++(0:{veclen(\x1,\y1)}) --       
  ++(90:{veclen(\x1,\y1)});     
\draw[ultra thick,green] 
  let \p1= ( $ (B)-(C) $ )
  in (B) -- 
  ++(0:{veclen(\x1,\y1)}) --       
  ++(-90:{veclen(\x1,\y1)}) --       
  ++(180:{veclen(\x1,\y1)});     
\coordinate (aux1) at
  ($ (A) ! {sin(90)} ! 90:(B) $);
\coordinate (aux2) at
  ($ (aux1) ! {sin(90)} ! 90:(A) $);
\draw[ultra thick,green]
  (A) -- (aux1) -- (aux2) -- (B);
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer
1  
¡Gracias Gonzalo! Estaba pidiendo algo como lo que publicaste. Me ha sido de mucha ayuda. –  user48419 Mar 22 at 1:09
    
@user48419 ¡De nada! Me alegro que haya sido de ayuda. –  Gonzalo Medina Mar 22 at 1:10
    
@user48419 By the way, I updated my answer providing a simple macro to draw the whole construct. It might be of interest for you. –  Gonzalo Medina Mar 22 at 2:20

A MetaPost version. Most of the drawing is done by two macros, pythagorean_square which draws a square based on a vertex, and pythagorean_config which draws the triange and calls pythagorean_square for each vertex.

These macros can be used for any kind of triangle. To ensure that it is a rectangle triangle is left to the user. The apices can be given as arguments of pythagorean_config in any order, clockwise or counterclockwise: by making use of the turningnumber function of MetaPost, it is ensured that the squares are always exterior to the triangle.

I give a LuaLaTeX version of my MetaPost code, which makes use of the luamplib package, but needs of course to be typeset by LuaLaTeX, and a second version which can be used with all LaTeX dialects, using the gmp package and thus requiring to be typeset with the shell-escape option activated if the user doesn't want to be bothered with more than one compilation.

% Luamplib version
\documentclass[12pt]{article}
\usepackage{unicode-math}
\usepackage{luamplib}
  \mplibsetformat{metafun}
  \mplibtextextlabel{enable}
  \everymplib{verbatimtex \leavevmode etex; 
    % Right angle mark
    % From "Tutorial in MetaPost" by André Heck
    mark_size := 2mm;
    vardef mark_right_angle(expr endofa, common, endofb) =
      save tn; tn := turningnumber(common--endofa--endofb--cycle);
      draw ((1, 0)--(1,1)--(0,1))
      zscaled (mark_size * unitvector((1+tn)*endofa+(1-tn)*endofb-2*common))
        shifted (common*u) ;
    enddef;
    % Drawing of a Pythagorean square based on vertex [AB]
    vardef pythagorean_square(expr A, B, legend)(text drawing_options) =
      save D, E, v, my_square, my_center; 
      pair D, E, v, c, my_center; path my_square; clearxy; 
      z = B - A; 
      v = (-y, x);
      if t = 1:
        E = A - v;
        D = B - v;
      else:
        D = B + v;
        E = A + v;
      fi;
      my_square = B--D--E--A--cycle;
      my_center = center my_square;
      draw (B--D--E--A) scaled u drawing_options;
      freelabel(legend, u*0.5[A, E], u*(my_center reflectedabout (A, E)));
      freelabel(legend, u*0.5[E, D], u*(my_center reflectedabout (D, E)));
      freelabel(legend, u*0.5[D, B], u*(my_center reflectedabout (D, B)));
      freelabel(legend, u*0.5[A, B], u*(my_center reflectedabout (A, B)));
    enddef;
    % Drawing of the triangle and all its Pythagorean squares
    vardef pythagorean_config(expr A, B, C, c, a, b)(text drawing_options) =
      if angle(B-A) - angle(C-A) <> 0:
        t = turningnumber(A--B--C--cycle);
        pythagorean_square(A, B, c)(drawing_options);
        pythagorean_square(B, C, a)(drawing_options); 
        pythagorean_square(C, A, b)(drawing_options);
        draw (A--B--C--cycle) scaled u;
      fi;
    enddef;
    beginfig(0);}
  \everyendmplib{endfig;}

\begin{document}
\begin{center}
  \begin{mplibcode}
    u = 2.5cm;
    pair A, B, C; A = origin; B = (1, 0); C = (1,  1);
    label.llft("$A$", A*u); label.lrt("$B$", B*u); label.urt("$C$", C*u);
    pythagorean_config(A, B, C, "$c$", "$a$", "$b$")(dashed evenly);
    mark_right_angle(A, B, C);
  \end{mplibcode}
\end{center}

\bigskip
\begin{center}
  \begin{mplibcode}
    u := 1.75cm;
    pair A, B, C; A = origin; B = (0.5, 1.5); C = A + 1.5*(B-A) rotated -90;
    freelabel("$A$", A*u, u*0.5[B,C]); label.top("$B$", B*u); label.lrt("$C$", C*u);
    pythagorean_config(A, B, C, "$c$", "$a$", "$b$")(withcolor red);
    mark_right_angle(B, A, C);
  \end{mplibcode}
\end{center}
\end{document}

Pythagorean squares

% GMP version
\documentclass[12pt]{article}
\usepackage[latex, shellescape]{gmp}
\gmpoptions{everymp={%
  input latexmp; setupLaTeXMP(options="12pt", mode=rerun, textextlabel=enable); 
  % Right angle mark
  % From "Tutorial in MetaPost" by André Heck
  mark_size := 2mm;
  vardef mark_right_angle(expr endofa, common, endofb) =
    save tn; tn := turningnumber(common--endofa--endofb--cycle);
    draw ((1, 0)--(1,1)--(0,1))
      zscaled (mark_size * unitvector((1+tn)*endofa+(1-tn)*endofb-2*common))
    shifted (common*u) ;
  enddef;
  % Drawing of a Pythagorean square based on vertex [AB]
  vardef pythagorean_square(expr A, B, legend)(text drawing_options) =
    save D, E, v, my_square, my_center; pair D, E, v, c, my_center; path my_square; clearxy; 
    z = B - A; 
    v = (-y, x);
    if t = 1:
      E = A - v;
      D = B - v;
    else:
      D = B + v;
      E = A + v;
    fi;
    my_square = B--D--E--A--cycle;
    my_center = center my_square;
    draw (B--D--E--A) scaled u drawing_options;
    freelabel(legend, u*0.5[A, E], u*(my_center reflectedabout (A, E)));
    freelabel(legend, u*0.5[E, D], u*(my_center reflectedabout (D, E)));
    freelabel(legend, u*0.5[D, B], u*(my_center reflectedabout (D, B)));
    freelabel(legend, u*0.5[A, B], u*(my_center reflectedabout (A, B)));
  enddef;
  % Drawing of the triangle and all its Pythagorean squares
  vardef pythagorean_config(expr A, B, C, c, a, b)(text drawing_options) =
    if angle(B-A) - angle(C-A) <> 0:
      t := turningnumber(A--B--C--cycle);
      pythagorean_square(A, B, c)(drawing_options);
      pythagorean_square(B, C, a)(drawing_options); 
      pythagorean_square(C, A, b)(drawing_options);
      draw (A--B--C--cycle) scaled u;
    fi;
  enddef;}}


\begin{document}
\begin{center}
  \begin{mpost*}[mpmem = metafun]
    u := 2.5cm;
    pair A, B, C; A = origin; B = (1, 0); C = (1,  1);
    label.llft("$A$", A*u); label.lrt("$B$", B*u); label.urt("$C$", C*u);
    pythagorean_config(A, B, C, "$c$", "$a$", "$b$")(dashed evenly);
    mark_right_angle(A, B, C);
  \end{mpost*}
\end{center}

\bigskip
\begin{center}
  \begin{mpost*}[mpmem = metafun]
    u := 1.75cm;
    pair A, B, C; A = origin; B = (0.5, 1.5); C = A + 1.5*(B-A) rotated -90;
    freelabel("$A$", A*u, u*0.5[B,C]); label.top("$B$", B*u); label.lrt("$C$", C*u);
    pythagorean_config(A, B, C, "$c$", "$a$", "$b$")(withcolor red);
    mark_right_angle(B, A, C);
  \end{mpost*}
\end{center}
\end{document}
share|improve this answer
    
The labels don't match in either figure. –  Svend Tveskæg Mar 22 at 12:45
    
@SvendTveskæg Fixed! –  fpast Mar 22 at 13:25

Here's another option using the beautiful tkz-euclide package (the code is a variation of an example from the documentation):

\documentclass{article}
\usepackage{tkz-euclide}
\usetkzobj{all}

\begin{document}

\begin{tikzpicture}
\tkzInit
\tkzDefPoint(0,0){C}
\tkzDefPoint(4,0){A}
\tkzDefPoint(0,3){B}
\tkzDefSquare(B,A)\tkzGetPoints{E}{F}
\tkzDefSquare(A,C)\tkzGetPoints{G}{H}
\tkzDefSquare(C,B)\tkzGetPoints{I}{J}
\tkzFillPolygon[fill = red!50 ](A,C,G,H)
\tkzFillPolygon[fill = blue!50 ](C,B,I,J)
\tkzFillPolygon[fill = green!50](B,A,E,F)
\tkzFillPolygon[fill = orange,opacity=.5](A,B,C)
\tkzDrawPolygon[line width = 1pt](A,B,C)
\tkzDrawPolygon[line width = 1pt](A,C,G,H)
\tkzDrawPolygon[line width = 1pt](C,B,I,J)
\tkzDrawPolygon[line width = 1pt](B,A,E,F)
\tkzLabelSegment[auto](A,C){$a$}
\tkzLabelSegment[auto](C,G){$a$}
\tkzLabelSegment[auto](G,H){$a$}
\tkzLabelSegment[auto](H,A){$a$}
\tkzLabelSegment[auto](C,B){$b$}
\tkzLabelSegment[auto](B,I){$b$}
\tkzLabelSegment[auto](I,J){$b$}
\tkzLabelSegment[auto](J,C){$b$}
\tkzLabelSegment[auto](B,A){$c$}
\tkzLabelSegment[auto](F,B){$c$}
\tkzLabelSegment[auto](E,F){$c$}
\tkzLabelSegment[auto](A,E){$c$}
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

Needs only the values for the catheti of the triangle:

\documentclass[landscape]{article}
\usepackage{pstricks,geometry}

\newpsstyle{aStyle}{linecolor=red,fillstyle=solid,fillcolor=red!30}
\newpsstyle{bStyle}{linecolor=green,fillstyle=solid,fillcolor=green!30}
\newpsstyle{cStyle}{linecolor=blue,fillstyle=solid,fillcolor=blue!30}
\makeatletter
\def\psRTriangle{\pst@object{psRTriangle}}
\def\psRTriangle@i(#1,#2){%
  \addbefore@par{dimen=middle}%
  \begin@SpecialObj
  \pspolygon(0,0)(#1,0)(#1,#2)
  \end@SpecialObj  
  \psframe[style=aStyle](!#1 dup neg)
  \psframe[style=bStyle,origin={#1,0}](#2,#2)
  \rput{!#2 #1 atan}(0,0){%
    \psframe[style=cStyle](!#1 #2 Pyth dup)
    \psarc(!#1 #2 Pyth dup){0.5}{180}{270}\psdot(!#1 #2 Pyth 0.2 sub dup)
    \uput[90](!#1 #2 Pyth 2 div 0){c}\uput[180](!#1 #2 Pyth dup 2 div){c}}
  \psarc(#1,0){0.5}{90}{180}\psdot(!#1 0.2 sub 0.2)
  \psarcn(#1,0){0.5}{90}{0}\psdot(!#1 0.2 add 0.2)
  \psarc(!#1 #2 add #2){0.5}{180}{270}\psdot(!#1 #2 add 0.2 sub #2 0.2 sub)
  \psarc(0,0){0.5}{!#2 #1 atan}{!#2 #1 atan 90 add}\psdot(!#2 #1 atan rotate 0.2 0.2)
  \psarcn(0,0){0.5}{0}{-90}\psdot(0.2,-0.2)
  \psarc(!#1 dup neg){0.5}{90}{180}\psdot(!#1 0.2 sub dup neg)
  \uput[200](0,0){A}\uput[45](#1,#2){B}\uput[-45](#1,0){C}
  \uput[0](!#1 #2 2 div){a} \uput[-90](!#1 #2 2 div add 0){a}
  \uput[-90](!#1 2 div 0){b}\uput[0](!0 #1 2 div neg){b}}
\makeatother

\begin{document}

\begin{pspicture}(-2,-5)(14,7)
\psRTriangle(3,2)
\newpsstyle{cStyle}{fillstyle=solid,fillcolor=magenta!20!black!20}
\rput(7,0){\psRTriangle[fillstyle=solid,fillcolor=yellow](5,1.5)}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer

A PSTricks solution where all you have to do is choose the lengths of the catheti (the values of \lengthA and \lengthB, respectively):

\documentclass{article}

\usepackage{pst-eucl,pstricks-add}

% calculating frame size of pspicture
\usepackage{expl3}
\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
\newcommand*\maxHori{\calc{\lengthA+2*\lengthB}}
\newcommand*\maxVert{\calc{2*\lengthA+\lengthB}}

% labels
\def\Label[#1]#2#3{%
  \pcline[linestyle = none, offset = -8pt](#2)(#3)
  \ncput{$#1$}}

% length of the catheti
\def\lengthA{3 }
\def\lengthB{2 }


\begin{document}

\begin{pspicture}(\maxHori,\maxVert)
\psset{dimen = middel, fillstyle = solid}
  \pnodes%
    (!\lengthA \lengthB add \lengthA \lengthB add){A}%
    (\lengthB,\lengthA){B}%
    (!\lengthA \lengthB add \lengthA){C}%
    (\lengthB,0){a1}%
    (!\lengthA \lengthB add 0){a2}%
    (!\lengthA 2 \lengthB mul add \lengthA \lengthB add){b1}%
    (!\lengthA 2 \lengthB mul add \lengthA){b2}%
    (!0 2 \lengthA mul){c1}%
    (!\lengthA 2 \lengthA mul \lengthB add){c2}
  \psframe[fillcolor = red!70](a1)(C)
  \psframe[fillcolor = blue!70](C)(b1)
  \pspolygon[fillcolor = yellow!70](B)(c1)(c2)(A)
  \pspolygon[fillcolor = green!70](A)(C)(B)
  \pstRightAngle[RightAngleSize = 0.3, fillstyle = solid, fillcolor = green!70]{A}{C}{B}
  \uput[60](A){$A$}
  \uput[210](B){$B$}
  \uput[315](C){$C$}
  \Label[a]{a1}{B}
  \Label[a]{B}{C}
  \Label[a]{C}{a2}
  \Label[a]{a2}{a1}
  \Label[b]{C}{A}
  \Label[b]{A}{b1}
  \Label[b]{b1}{b2}
  \Label[b]{b2}{C}
  \Label[c]{B}{c1}
  \Label[c]{c1}{c2}
  \Label[c]{c2}{A}
  \Label[c]{A}{B}
\end{pspicture}

\end{document}

output2

share|improve this answer

Just for typing warm-up exercise with PSTricks.

\documentclass[pstricks]{standalone}
\usepackage{pst-eucl,pst-plot}

\def\S#1#2#3{% #1: semi-width, #2: label, #3: fillcolor
\begin{pspicture}[plotpoints=5](-#1,-#1)(#1,#1)
    \curvepnodes{0}{360}{#1 2 sqrt mul t 45 add PtoC}{#2}
    \pspolygon[fillstyle=solid,fillcolor=#3!50](#20)(#21)(#22)(#23)
    \psset{linestyle=none,offset=.1}
    \multido{\ix=0+1,\iy=1+1}{4}{\ncline{#2\ix}{#2\iy}\naput{$#2$}}
\end{pspicture}}

\begin{document}
\begin{pspicture}(-4,-5)(8,8)
    \pstGeonode[PosAngle={-135,-45,45},PointSymbol=none]{A}(4,0){C}(4,3){B}
    \pstRightAngle{A}{C}{B}
    \rput[tl](A){\S{2}{b}{red}}
    \rput[bl](C){\S{1.5}{a}{green}}
    \rput[br]{(B)}(B){\S{2.5}{c}{blue}}
\end{pspicture}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.