1
$\begingroup$

I am interested in drawing a labelled dashed line through points p1 and p2 with Graphics3D. The code doing this job is the following:

p1 = {0, 0, 0};
p2 = {0, 1, 0};
Graphics3D[{Text[Style["DUMA", 30], (p1 + p2)/2], {Dashed, Line[{p1, p2}]}}, Boxed -> False]

This code provides the following output:

enter image description here

However, when I rotate the output image (highlighted in orange box in the above figure) by 90 degrees clockwise, I receive the following result:

enter image description here

Could you please help me how to modify my code to rotate the label simultaneously with the output image. The result that I expect is as follows:

enter image description here

$\endgroup$
2
  • $\begingroup$ Related. $\endgroup$ Nov 6, 2021 at 20:44
  • $\begingroup$ @RohitNamjoshi OK, but what is the answer to this question? $\endgroup$
    – TobiR
    Nov 6, 2021 at 20:52

1 Answer 1

4
$\begingroup$

Edit

p1 = {0, 0, 0}; p2 = {0, 1, 0};
label = Rotate[Text[Style["DUMA", 100]], π/2];
vtc = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
center = Mean[{p1, p2}]; dir = .1 Normalize[p2 - p1]; normal = {1, 1, 
  1}; conormal = .05 Normalize@Cross[dir, normal]; frame = {conormal, 
  dir}; coords = {{center + {-1, -1} . frame, 
   center + {1, -1} . frame, center + {1, 1} . frame, 
   center + {-1, 1} . frame}}; Graphics3D[{{Dashed, Line[{p1, p2} ], 
   Red, Point[p2]}, {Texture[label], EdgeForm[Cyan], 
   Polygon[coords, VertexTextureCoordinates -> {vtc}]}}, 
 Boxed -> False, Lighting -> {{"Ambient", White}}]

enter image description here

Original

p1 = {0, 0, 0};
p2 = {0, 1, 0};
label = Text[Style["DUMA", 100]];
vtc = RotateLeft[{{0, 0}, {0, 1}, {1, 1}, {1, 0}}, 1];
center = Mean[{p1, p2}];
dir = .1 Normalize[p2 - p1];
normal = .1 Normalize@{1, -1, 1};
conormal = Cross[dir, normal];
coords = {{center + {-1, -1} . {dir, normal}, 
    center + {1, -1} . {dir, normal}, center + {1, 1} . {dir, normal},
     center + {-1, 1} . {dir, normal}}};
Graphics3D[{Dashed, 
  Line[{p1, p2}], {Texture[label], EdgeForm[Cyan], 
   Polygon[coords, VertexTextureCoordinates -> {vtc}]}}, 
 Boxed -> False, Lighting -> {{"Ambient", White}}]

enter image description here

$\endgroup$
6
  • $\begingroup$ p1 = {0, 0, 0}; p2 = {0, 1, 0}; label = Text[Style["DUMA", 100]]; vtc = RotateLeft[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, 1]; center = Mean[{p1, p2}]; dir = .1 Normalize[p2 - p1]; normal = .1 Normalize@{1, -1, 1}; conormal = .05 Normalize@Cross[dir, normal]; frame = {conormal, dir}; coords = {{center + {-1, -1} . frame, center + {1, -1} . frame, center + {1, 1} . frame, center + {-1, 1} . frame}}; Graphics3D[{Dashed, Line[{p1, p2}], {Texture[label], EdgeForm[Cyan], Polygon[coords, VertexTextureCoordinates -> {vtc}]}}, Boxed -> False, Lighting -> {{"Ambient", White}}] $\endgroup$
    – cvgmt
    Nov 7, 2021 at 4:07
  • $\begingroup$ It is nice, thanks. The commands you posted below your answer provide "Duma" rotated in a strange way which is unreadable without changing the orientation of our head. ;) Can you give a solution which rotates the text by 180 degrees counterclockwise in this particular case and in general case, such that one can read the text without rotating her head? $\endgroup$
    – TobiR
    Nov 7, 2021 at 11:43
  • $\begingroup$ @TobiR set vtc = RotateLeft[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, 3]; instead of vtc = RotateLeft[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, 1]; $\endgroup$
    – cvgmt
    Nov 7, 2021 at 11:53
  • $\begingroup$ @cvgmnt After replacing the row you mentioned, I still can get line oritentations where "AMUD" (with "inverted" D) is shown instead of "DUMA". $\endgroup$
    – TobiR
    Nov 7, 2021 at 11:57
  • $\begingroup$ @TobiR See the updated. $\endgroup$
    – cvgmt
    Nov 7, 2021 at 12:14

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.