5
$\begingroup$

I can make some basic diagrams in Mathematica (stolen from their pages, for example see the below:

 LaminaData["FilledIsoscelesTriangle", "Diagram"]

However, I'm trying to make a simple, set of labelled diagrams, similar to this one, with certain angles marked, etc. Is there a tutorial anywhere that explains how to do this please?

enter image description here

$\endgroup$
4
  • $\begingroup$ Hi, welcome to Mathematica.SE, please consider taking the tour so you learn the basic of the site. Once you gain enough reputation by making good questions you will be able to vote up and down both questions and answers. When you see good ones, please vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – rhermans
    Oct 19, 2014 at 12:38
  • $\begingroup$ You may want to look into AASTriangle and all the *Trainglefamily of functions. $\endgroup$
    – rhermans
    Oct 19, 2014 at 12:39
  • $\begingroup$ Thanks rhermans. However, I don't see any options on how to label angles or sides in AASTriangle, is there another reference I am missing? $\endgroup$
    – Randy
    Oct 19, 2014 at 12:54
  • $\begingroup$ Related: How to position text labels automatically to not overlap other graphics elements? $\endgroup$
    – Michael E2
    Oct 19, 2014 at 18:15

2 Answers 2

9
$\begingroup$

For simple graphics just build them step-by-step from graphics primitives.

Graphics[{
   (* triangle *)
  Line[{{0, 0}, {0, 1}, {1, 0}, {0, 0}}],
  (* right angle symbol *)
  Line[{{0, 0.1}, {0.1, 0.1}, {0.1, 0}}],
  (* angle symbol *)
  Circle[{1, 0}, 0.2, {127.5 Degree, 187.5 Degree}],
  (* labels *)
  Rotate[
   Text[Style["opposite side (= y)", 20],
    {-0.1, 0.5}], 90 Degree],
  Text[Style["adjacent side (= x)", 20],
   {0.5, -0.1}],
  Text[Style["hypotenuse (= z)", 20],
   {0.6, 0.5}, {-1, 0}],
  Text[Style["θ", 20], {0.75, 0.08}]
  }]

enter image description here

$\endgroup$
5
$\begingroup$

@BobHanlon answer is an amazing replication. I post this to illustrate customizability:

trn[a_, s_] := 
 Module[{tr = AASTriangle[Pi/2, a, s], sd, s1, s2, s3, txt, ang, dis},
  sd = {s1, s2, s3} = 
    SortBy[Subsets[tr[[1]], {2}], N[EuclideanDistance @@ #] &];
  ang = First@Cases[tr[[1]], {_?(#1 != 0 &), 0}];
  dis = 0.2 {#, #} &@(EuclideanDistance @@ s1);
  txt = MapThread[{Black, 
      Text[Style[#1, 20], Total@#2/2, #3]} &, {{"adjacent side (= x)",
       Rotate["opposite side (=y)", Pi/2], 
      Rotate["hypotenuse (=z)", -a]}, 
     sd, {{0, 2}, {2, 0}, {-0.4, -0.4}}}];
  Graphics[{White, EdgeForm[Black], tr, 
    Rectangle[{0, 0}, dis], {Black, 
     Circle[ang, dis, {Pi, Pi - a}]}, {Black, 
     Text[Style["\[Theta]", 
       20], (1.2 dis {Cos[Pi - a/2], Sin[Pi - a/2]} + ang)]}, txt}]
  ]

Note of angle

Manipulate[trn[an, 2], {an, Pi/3.9, Pi/3}]

enter image description here

$\endgroup$
3
  • $\begingroup$ FYI, Text has a 4th argument that specifies direction (so that Rotate might be avoided). $\endgroup$
    – Michael E2
    Oct 19, 2014 at 19:48
  • $\begingroup$ @MichaelE2 thank you...always learning...had never used it, guess I didn't look at documentation closely enough $\endgroup$
    – ubpdqn
    Oct 19, 2014 at 23:20
  • $\begingroup$ You're welcome. I used it here to make text follow a parametric curve. $\endgroup$
    – Michael E2
    Oct 19, 2014 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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