How do I rotate a text object in a 3D plot to appear to be painted on the wall?

9 views (last 30 days)
I'm trying to rotate the text "Spiral" to appear as if it was painted on the X-Z wall of the following 3D plot
t = 0:pi/50:10*pi;
plot_handle = plot3(t,cos(t),sin(t));
grid('on')
box('on')
text_handle = text(15,1,0,'Spiral','FontSize',32,'HorizontalAlignment','center','VerticalAlignment','middle');
line([15 15],[1 1],[-1 1],'Color','r','LineWidth',2,'LineStyle','--')
ax = gca;
[az,el] = view;
xlabel('X axis')
ylabel('Y axis')
zlabel('Z axis')
xlim([0 10*pi])
ylim([-1 1])
zlim([-1 1])
After reading the documentation for the "rotate" function (https://www.mathworks.com/help/matlab/ref/rotate.html), I figured I need to rotate the text by "az" degrees around the dashed red line. However, the following does not result in my expected behavior. What am I doing wrong?
% Rotate text around dashed grey axis
rotate(text_handle,[15 1 -1],az,[15 1 1])

Answers (1)

Walter Roberson
Walter Roberson on 28 May 2022
Use computer vision toolbox to draw the text into an array. Use warp() to texture map the array as a surface. It will now rotate with the view() or with rotate()
If you parent the surface returned from warp() to a hgtransform group, then you can manipulate position and rotation independently from other objects in the axes.
  3 Comments
Walter Roberson
Walter Roberson on 29 May 2022
https://www.mathworks.com/help/vision/ref/inserttext.html
https://www.mathworks.com/help/images/ref/warp.html
Walter Roberson
Walter Roberson on 29 May 2022
You might want to take the surface returned by warp() and apply AlphaData to it in order to make the background of the label box transparent.

Sign in to comment.

Tags

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!