I'm trying to draw a right angled triangle with hypotenuse length 1,opposite length b and adjacent length c in Mathematica. How do I do this? I'm trying to draw an isosceles triangle showing length 1 for hypotenuse and side a and side b for other sides.

  • $\begingroup$ So a 45,45,90 triangle, and you want the hypotenuse labeled "1", one side labeled "b", and one side labeled "c"? Is this what you're after? $\endgroup$ – user6014 Aug 29 '18 at 1:05
  • $\begingroup$ That is what I want. Please $\endgroup$ – Matthew Reading Aug 29 '18 at 1:07
  • $\begingroup$ Perhaps you want to look up Graphics, Line and Text. Using just these three commands you can draw all kinds of illustrations and add labels. If you already have something, just share it with us and we can help you more easily. $\endgroup$ – Johu Aug 29 '18 at 1:11
  • 1
    $\begingroup$ SSSTriangle generates lengths 3 4 5 but not 1,a, and b. $\endgroup$ – Matthew Reading Aug 29 '18 at 1:13
  • $\begingroup$ b=.3;Graphics[SSSTriangle[1,b,Sqrt[1-b^2] ]]? $\endgroup$ – kglr Aug 29 '18 at 1:17

Here's a suggestion for a function which takes arbitrary x and y lengths, and plots a right triangle with those values. Adjust the styling/options as desired.

plotTriangle[x_, y_] := 
 Graphics[{Red, Thick, 
   Line /@ {{{0, 0}, {x, 0}}, {{0, 0}, {0, y}}, {{x, 0}, {0, y}}}}, 
  Axes -> True, 
  Epilog -> {Inset[Style["a", 20, Red], {x/2, 0 + y/15}], 
    Inset[Style["b", 20, Red], {x/15, y/2}],
    Inset[Style["1", 20, Red], {x/2 + x/15, y/2 + y/15}]}]

enter image description here

  • $\begingroup$ Why do you prefer to use Epilog instead of Text or Inset in the first argument of Graphics? $\endgroup$ – Johu Aug 29 '18 at 1:15
  • $\begingroup$ You can use whatever you want. This is just what I chose in this instance. $\endgroup$ – user6014 Aug 29 '18 at 1:15
  • $\begingroup$ I tried the code you suggested and pressed shift enter and the graph didn't show. How do I get the graph to show? $\endgroup$ – Matthew Reading Aug 29 '18 at 1:16
  • $\begingroup$ It's a function definition. Plug values into the function. Like plotTriangle[2,2] $\endgroup$ – user6014 Aug 29 '18 at 1:17
  • $\begingroup$ Sorry I missed plotTriangle[4,5]. $\endgroup$ – Matthew Reading Aug 29 '18 at 1:19

You can also post-process the diagram produced by LaminaData["Filled345Triangle" , "BoundaryDiagram"] to get a diagram labeled as desired:

text = {"b", "c", 1};
i = 1; Replace[LaminaData["Filled345Triangle" , "BoundaryDiagram"] , 
 {p : Polygon[{{0, 0}, __}] :> {LightBlue, p}, Text[_, p_] :> Text[text[[i++]], p]}, ∞]

enter image description here


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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