Matlab:如何在3D中绘制文本

Matlab:如何在3D中绘制文本

问题描述:

text(x,y,z,'text')在3D空间中工作,但它不是3D。有没有办法在matlab中绘制一个简单的3D文本,像这样简单: the textMatlab:如何在3D中绘制文本

我不需要阴影或渲染,只是为了能够在文本中添加第三维。

没有办法使用文本来做到这一点。你将不得不有图片的文字和texture map二维图像到3-D surface。默认情况下,图形被在轴使用的正投影呈现,所以创建透视如你在你的图像具有高于你就必须要么:

  1. 人工由上收缩表面的一侧的长度创建它该图像被纹理映射。
  2. Adjust the view projection of the axes

下面是一些示例代码来说明上述情况。我将建立一个简单的文本图像开始:

hFigure = figure('Color', 'w', ...  %# Create a figure window 
       'MenuBar', 'none', ... 
       'ToolBar', 'none'); 
hText = uicontrol('Parent', hFigure, ... %# Create a text object 
        'Style', 'text', ... 
        'String', 'PHOTOSHOP', ... 
        'BackgroundColor', 'w', ... 
        'ForegroundColor', 'r', ... 
        'FontSize', 50, ... 
        'FontWeight', 'bold'); 
set([hText hFigure], 'Pos', get(hText, 'Extent')); %# Adjust the sizes of the 
                %# text and figure 
imageData = getframe(hFigure); %# Save the figure as an image frame 
delete(hFigure); 
textImage = imageData.cdata; %# Get the RGB image of the text 

现在,我们有我们想要的文本的图像,这里是你如何能在3 d表面纹理贴图,并调整视图投影:

surf([0 1; 0 1], [1 0; 1 0], [1 1; 0 0], ... 
    'FaceColor', 'texturemap', 'CData', textImage); 
set(gca, 'Projection', 'perspective', 'CameraViewAngle', 45, ... 
    'CameraPosition', [0.5 -1 0.5], 'Visible', 'off'); 

而这里的结果图像:

enter image description here

+0

谢谢你,它是我一直在寻找 – 2012-03-23 18:44:15

+0

哇,很好的解决方案.... – ConfusinglyCuriousTheThird 2016-12-29 18:37:27