0

I would like to draw a line between two points and place a label "label" at its center, above the line. It would be also useful if this label remain parallel to the line when rotating the figure. What I have tried is the following:

MeshRegion[{{0, 0, 0}, {0, 0, 1}}, {Line[{1, 2}]}, 
 MeshCellLabel -> {1 -> Placed["label", "Above"]}]

but the directive "Above" does not seem to work. The command

MeshRegion[{{0, 0, 0}, {0, 0, 1}}, Line[{1, 2}], 
 MeshCellLabel -> {1 -> Placed["label", "Centroid"]}]

results in an undesired arrangement perpendicular to the line:

enter image description here

Furthermore, the absolute position retains while rotating the figure.

TobiR
  • 254
  • 1
  • 6

1 Answers1

3

You may use "Rotate" on the text like e.g.:

p1 = {0, -1};
p2 = {-1, 1};
Graphics[{
  Line[{p1, p2}],
  Rotate[Text["Label", (p1 + p2)/2 - 0.02 (p1 - p2)], 
   ArcTan @@ (p1 - p2), (p1 + p2)/2]
  }]

enter image description here

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • 1
    Thanks, but I need to use Graphics3D. – TobiR Nov 06 '21 at 09:09
  • Does "https://mathematica.stackexchange.com/questions/131798/placing-text-in-3d-not-facing-viewer" help? Or "https://pages.uoregon.edu/noeckel/computernotes/Mathematica/label3D.html" – Daniel Huber Nov 06 '21 at 09:29