2012-03-23 132 views
5

text(x,y,z,'text')在3D空間中工作,但它不是3D。有沒有辦法在matlab中繪製一個簡單的3D文本,像這樣簡單: the textMatlab:如何在3D中繪製文本

我不需要陰影或渲染,只是爲了能夠在文本中添加第三維。

回答

6

沒有辦法使用文本來做到這一點。你將不得不有圖片的文字和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