Three-dimensional image
We can call the mesh(x,y,z)
command to generate a three-dimensional image.
Let's look at the function:
code:
>> [x,y] = meshgrid(-2*pi:0.1:2*pi);
>> z = cos(x).*sin(y);
>> mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z')
Image:
mesh
is plot
an extension in three dimensions, another function:
,
We take the same interval:
>> [x,y] = meshgrid(-2:0.1:2);
>> z = y.*exp(-x.^2-y.^2);
>> mesh(x,y,z)
Now we draw an image showing gradient colors, with the following command:
surf
surfc
surfl
Just modify the last sentence:
>> surf(x,y,z)
Image:
The color of the image surface is proportional to the height. If you use the surfc
command, it will leave a projection under the image:
call the surfl
command ( l
representing this is a lighted surface), which shows us the surface of the three-dimensional lighted object. A three-dimensional image without lines, the image can also be grayscale or color:
>> surfl(x,y,z);
>> shading interp
>> colormap(gray)
The shadow in the image can be set to the following modes:
flat
: Color each grid with the same color and hide the grid linesfacted
: Show grid linesinterp
: The color interpolation method is used for coloring, so it is very smooth.
Next, we
draw a cylindrical-like image:
>> t = [0:pi/10:2*pi];
>> [x,y,z] = cylinder(1+sin(t));
>> surf(x,y,z);
>> axis square
Modify the shading
options to flat
:
Use faceted
shading:
>> [x,y,z] = cylinder(1+cos(t));
>> surf(x,y,z);
>> axis square
>> shading faceted
Use interp
:
>> [x,y,z] = cylinder(1+cos(t));
>> surf(x,y,z);
>> axis square
>> shading interp