3

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?

LCarvalho
  • 9,233
  • 4
  • 40
  • 96

1 Answers1

4
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.

Kuba
  • 136,707
  • 13
  • 279
  • 740