Drawing rectangle triangles with labels only in its sizes

An attempt with MetaPost, in LuaLaTeX.

Given a real x (supposed to be greater than 0 and lower than 2), it uses the Pythagorean subtraction (built in MetaPost) to compute the length of the other side adjacent to the angle.

\documentclass[border=2bp]{standalone}
\usepackage{luamplib}
    \mplibtextextlabel{enable}
    \mplibsetformat{metafun}
\begin{document}
    \begin{mplibcode}
        numeric u; u = 2.5cm;
        beginfig(1);
            x = 1; y = 2 +-+ x; % Pythagorean subtraction
            pair A, B, C; A = origin; B = (u*y, 0); C = (0, u*x);
            label.bot("$\sqrt{4-x^2}$", .5[A,B]);
            label.lft("$x$", .5[A,C]);
            label.urt("$2$", .5[B,C]);
            draw ((1, 0) -- (1, 1) -- (0, 1)) scaled 2mm; % mark right angle
            path angle_mark; 
            angle_mark = anglebetween(B--A, B--C, "\alpha"); % angle \alpha
            fill B -- angle_mark -- cycle withcolor .8white;
            draw A -- B -- C -- cycle;
            draw angle_mark; 
        endfig;
    \end{mplibcode}
\end{document}

Output with x = 1:

enter image description here

With x = 0.5:

enter image description here

With x = 1.5:

enter image description here


With tkz-euclide:

\documentclass[border=5mm]{standalone}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\begin{tikzpicture}[scale=.8]
\tkzInit[xmax=5,ymax=3] %\tkzClip[space=.5]
\tkzDefPoint(0,0){A} \tkzDefPoint(4,0){B}
\tkzDrawTriangle[pythagore](A,B)
\tkzGetPoint{C}
\tkzMarkRightAngle(A,B,C)
\tkzDrawPoints(A,B,C)
\tkzLabelPoints[below](A,B)
\tkzLabelPoints[above](C)
\tkzLabelSegment[below,font=\footnotesize](A,B){$\sqrt{4 - x^2}$}
\tkzLabelSegment[above,font=\footnotesize](A,C){$2$}
\tkzLabelSegment[right,font=\footnotesize](B,C){$x$}
\tkzMarkAngle[fill= blue!40,size=1.4cm,opacity=.5](B,A,C)
\tkzLabelAngle[pos=0.8](B,A,C){$\alpha$}
\end{tikzpicture}
\end{document}

enter image description here


Here is a TikZ version:

\documentclass[border=5mm,tikz]{standalone}
\usepackage{mwe}
\usepackage{tikz}
\begin{document}

  \begin{tikzpicture}[scale=2]
    \draw(0,0)--node[below]{$\sqrt{4-x^2}$} (1.7,0)
              --node[above]{$2$}(0,1)
              --node[left]{$x$}(0,0);
    \draw[very thin,<->](1.4,0) arc [start angle=180,end angle=150, radius=0.3];
    \node at (1.3,0.1){$\alpha$};
  \end{tikzpicture}

\end{document}

output

Tags:

Tikz Pgf