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.
2 Answers
$\begingroup$
$\endgroup$
5
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}]}]
-
$\begingroup$ Why do you prefer to use
Epilog
instead ofText
orInset
in the first argument ofGraphics
? $\endgroup$– JohuCommented Aug 29, 2018 at 1:15 -
$\begingroup$ You can use whatever you want. This is just what I chose in this instance. $\endgroup$– ktmCommented Aug 29, 2018 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$ Commented Aug 29, 2018 at 1:16
-
$\begingroup$ It's a function definition. Plug values into the function. Like
plotTriangle[2,2]
$\endgroup$– ktmCommented Aug 29, 2018 at 1:17 -
$\begingroup$ Sorry I missed plotTriangle[4,5]. $\endgroup$ Commented Aug 29, 2018 at 1:19
$\begingroup$
$\endgroup$
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]}, ∞]
Graphics
,Line
andText
. 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$b=.3;Graphics[SSSTriangle[1,b,Sqrt[1-b^2] ]]
? $\endgroup$