Skip to main content
1 of 2
padre
  • 273
  • 1
  • 8

generate right triangles of different measures with an unknown data

Could you help me improve this code to generate at least 10 "slightly larger" right triangles, but instead of all the results that find an "x" on one of the sides and the type square that indicates that the triangle is rectangle.

 triangle[a_?NumericQ,b_?NumericQ,c_?NumericQ]:=
 Block[{x,y,pt,sqr},
 sqr=#.#&;
  pt[a1_,b1_,c1_]:=
  Reduce[sqr[{x,y}]==b1^2&&sqr[{x,y}-{a1,0}]==c1^2&&y>0,{x,y}];
 {(Polygon[{{0,0},{a,0},{x,y}}]),
  Text[Style[Framed[a,Background-> LightYellow],11],{a/2,0}],
  Text[Style[Framed[b,Background-> LightYellow],11],{x/2,y/2}],
  Text[Style[Framed[c,Background-> LightYellow],11], 
     {(a+x)/2,y/2}]}/.ToRules[pt[a,b,c]]]

  g[{s1_,s2_,s3_}]:=
  Graphics[{EdgeForm[Thick],FaceForm[None],triangle[s1,s2,s3]},
          ImagePadding->20,ImageSize->{200,200}]


  GraphicsGrid[{
  {g[{2, 1, Sqrt[5]}], g[{1, 2, Sqrt[5]}],
  g[{Sqrt[5], 1, 2}], g[{Sqrt[5], 2, 1}]},
  {g[{2, 2, Sqrt[8]}], g[{Sqrt[8], 2, 2}],
  g[{2, Sqrt[8], 2}],
  g[{Sqrt[2], Sqrt[2], 2}]}}]

  out put 

enter image description here desired execution

enter image description here

padre
  • 273
  • 1
  • 8