MATLAB graphics drawing-three-dimensional image

Three-dimensional image

We can call the mesh(x,y,z)command to generate a three-dimensional image.
Let's look at the function:
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:
Image drawn by mesh (x, y, z) command
meshis plotan extension in three dimensions, another function:

Function 2,
We take the same interval:

>> [x,y] = meshgrid(-2:0.1:2);
>> z = y.*exp(-x.^2-y.^2);
>> mesh(x,y,z)

Another function
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:
surf command
The color of the image surface is proportional to the height. If you use the surfccommand, it will leave a projection under the image:
surfc projection
call the surflcommand ( lrepresenting 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)

surfl
The shadow in the image can be set to the following modes:

  • flat: Color each grid with the same color and hide the grid lines
  • facted: Show grid lines
  • interp: 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

Cylinder 1
Modify the shadingoptions to flat:
Cylinder 2

Use facetedshading:

>> [x,y,z] = cylinder(1+cos(t));
>> surf(x,y,z);
>> axis square
>> shading faceted

1
Use interp:

>> [x,y,z] = cylinder(1+cos(t));
>> surf(x,y,z);
>> axis square
>> shading interp

2

Published 84 original articles · won 18 · views 5805

Guess you like

Origin blog.csdn.net/qq_44486550/article/details/105300786