3
$\begingroup$

I created a graphic to obtain a triangle with three vertices.

The code is as follows:

a = {4, 2, 1}; b = {1, 0, 1}; c = {1, 2, 0};

Graphics3D[{
Text[Style["A", Large, Bold, Red], {4.28, 2.09, 1.05}],
Text[Style["B", Large, Bold, Red], {0.86, -0.25, 1.08}],
Text[Style["C", Large, Bold, Red], {0.81, 2.18, -0.15}],
Blue,
PointSize[.05], Point[a], Point[b], Point[c],
Black,
Line[{a, b, c, a}]
}]

enter image description here

You may notice that I put the texts as I wanted, but I managed through the following procedure below from other software.

enter image description here

If I could be objective. What are the steps to achieve this result through the Mathematica?

$\endgroup$
3
  • 1
    $\begingroup$ related 2d case: label all vertices in polygon plot $\endgroup$
    – Kuba
    Commented Aug 26, 2016 at 17:29
  • 1
    $\begingroup$ p.s. Thx for an accept, though it is a good habit to hold on with it a day or two to not discourage others. You can use gray triangles to upvote answers you find useful. $\endgroup$
    – Kuba
    Commented Aug 26, 2016 at 18:32
  • $\begingroup$ You resolved my problem. Then that´s right.. $\endgroup$
    – LCarvalho
    Commented Aug 26, 2016 at 19:34

1 Answer 1

4
$\begingroup$
r=.3;

Graphics3D[{
  MapThread[
    With[{w = Normalize[Normalize[#2 - #1] + Normalize[#3 - #1]]},
       Text[Style[#4, Large, Bold, Black], #1 - r w]
    ] &, 
    N @ {{a, b, c}, {b, c, a}, {c, a, b}, {"A", "B", "C"}}
  ],
  Blue, PointSize[.05], Point[a], Point[b], Point[c], Black, 
  Line[{a, b, c, a}]},
 BoxRatios -> Automatic, Axes -> True]

enter image description here

Let's create something more general:

LabeledPolygon[
   labels_List, r_, p : Polygon[pts_List, ___]
] /;  Length[labels] == Length[pts] := {
  MapThread[
     With[{w = Normalize[Normalize[#2 - #1] + Normalize[#3 - #1]]},
        Text[Style[#4, Large, Bold, Black], #1 - r w]
     ] &, 
     N @ Append[NestList[RotateLeft, pts, Length[pts] - 1], labels]
  ], 
  p
}

and now:

Graphics3D[{
  Blue, PointSize[.05], Point[{a, b, c}],
  FaceForm[None], EdgeForm[Black], 
  LabeledPolygon[{"A", "B", "C"}, .3, Polygon[{a, b, c}]]
}]

works the same.

$\endgroup$

Your Answer

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

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