Skip to main content
added 91 characters in body
Source Link
padre
  • 273
  • 1
  • 8

hello (edited and clarified) 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"with small random data between 1 and 20 on onetwo of the sides, can be the two legs or the hypotenuse and a leg and the typemissing side with an "x". In addition, add to the resulting figures a typical square that indicates that the triangleit is rectanglea right triangle.

 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

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

hello (edited and clarified) Could you help me improve this code to generate at least 10 "slightly larger" right triangles, but with small random data between 1 and 20 on two of the sides, can be the two legs or the hypotenuse and a leg and the missing side with an "x". In addition, add to the resulting figures a typical square that indicates that it is a right triangle.

 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

Source Link
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