Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab: how to plot a text in 3D

Tags:

matlab

text(x,y,z,'text') works in 3D space however it is not 3D. Is there a way to plot a simple 3D text in matlab, something as simple as this: the text

I do not need shadowing or rendering, only to be able to add 3rd dimension to the text.

like image 888
C graphics Avatar asked Mar 23 '12 16:03

C graphics


People also ask

How do you plot a 3D plot in Matlab?

plot3( X , Y , Z ) plots coordinates in 3-D space. To plot a set of coordinates connected by line segments, specify X , Y , and Z as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X , Y , or Z as a matrix and the others as vectors.

What is 3D visualization Matlab?

3D visualization elements allow MATLAB to deal with 3D graphics. - Surface and Mesh Plots - It includes plot matrices, visualize functions, color maps. - View Control - Used to control camera viewpoint, rotation, zooming, and aspect ratio and set axis limits. - Lighting - Used for adding and controlling scene lighting.

Can we have multiple 3D plots in Matlab?

7. Can we have multiple 3d plots in MATLAB? Explanation: The plot3() function is a pre-defined function in MATLAB. So, it will allow the use to generate multiple 3d plots.

What is 2D plotting in Matlab?

2D Plots in Matlab is a feature that enables a user to create the two-dimensional graph for any dependent variable as a function of a depending variable. A plot can present the data in continuous, discrete, surface or volume form. The default standard function for 2D graph plotting is plot() function.


1 Answers

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. 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:

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:

enter image description here

like image 93
gnovice Avatar answered Sep 26 '22 08:09

gnovice