简体   繁体   English

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

[英]Matlab: how to plot a text in 3D

text(x,y,z,'text') works in 3D space however it is not 3D. text(x,y,z,'text')在3D空间中工作,但不是3D。 Is there a way to plot a simple 3D text in matlab, something as simple as this: 有没有一种方法可以在matlab中绘制简单的3D文本,就像这样简单: 文本

I do not need shadowing or rendering, only to be able to add 3rd dimension to the text. 我不需要阴影或渲染,只是为了能够向文本添加第3维。

There is no way to do this using text. 无法使用文本执行此操作。 You would have to have an image of the text and texture map the 2-D image onto a 3-D surface . 您将必须具有文本图像纹理,将2-D图像映射3-D表面上 By default graphics are rendered in the axes using an orthographic projection, so to create perspective as you have in your image above you would have to either: 默认情况下,图形是使用正交投影在轴上渲染的,因此,要像上面的图像一样创建透视图,您必须:

  1. Artificially create it by shrinking the length of one side of the surface on which the image is texture-mapped. 通过缩小图像被纹理映射的表面一侧的长度来人工创建图像。
  2. Adjust the view projection of the axes . 调整轴的视图投影

Here is some sample code to illustrate the above. 这是一些示例代码来说明上述内容。 I'll start by creating a sample text image: 我将从创建示例文本图像开始:

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

Now that we have an image of the text we want, here is how you can texture map it on a 3-D surface and adjust the view projection: 现在我们有了所需文本的图像,下面是在3D表面上对其进行纹理映射和调整视图投影的方法:

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');

And here's the resulting image: 这是结果图像:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM