Example of MATLAB 3D graphics drawing method + rendering

3D graphics rendering

Two-dimensional graphics provide the plot function. Similarly, three-dimensional graphics also have their own function plot3, which can draw three-dimensional curves in a three-dimensional space. The function call format is as follows: plot(x,y,z, options) x,y,
z It is a vector with the same dimension, and stores the values ​​of the three coordinates respectively. The meaning of the option is the same as that of the plot function option .

Use plot3 to draw three-dimensional curves
>>clear all;
>>t=0:pi/50:10*pi;
>>plot3(sin(t),cos(t),t)
>>grid on 
>>axis square

insert image description here

Matlab provides a function to draw a three-dimensional surface mesh map, and the calling format is: mesh(x,y,z,c)
x,y,z,c respectively form the x,y and z vectors of the three-dimensional curve; c is the color matrix, indicating Color range values ​​at different heights z.
The meshgrid function is a representation function of the plane grid coordinate matrix, and the calling format is as follows:
[X,Y]=meshgrid(x,y)
[X,Y]=meshgrid(x)
[X,Y,Z]=meshgrid(x, y,z)

Use the meshgrid function to create a matrix.
>>[X,Y]=meshgird(1:3,10:14>>X=
>         1         2         3 
>         1         2         3
>         1         2         3
>         1         2         3
>         1         2         3
>>Y=
>          10      10      10
>          11       11      11
>          12       12      12
>          13       13      13 
>          14       14      14
Use the meshgrid function to draw a matrix to generate a surface graph.
>>[X,Y]=meshgrid(-2:.2:2,-2:.2:2);
>>Z=X.*exp(-X.^2-Y.^2);
>>surf(X,Y,Z)

insert image description here

Regarding the drawing of 3D graphics, commonly used commands:

surf(x,y,z) % draw 3D surface graphics
surc(x,y,z) % draw 3D surface graphics with contour lines
surfl(x,y,z) % draw 3D surface graphics with shadows
coutour (x,y,z) % Contour graphics

Example 1: Plotting z = − x 2 + y 2 z=-\sqrt{x^2+y^2}z=x2+y2 wire diagrams and surfaces.

>>clear all;
>>x=-9:0.5:9;
>>y=x;
>[x,y]=meshgrid(x,y);      %坐标网格函数
>>z=-sqrt(x.^2+y.^2);    %函数表达式
>>z=-z.*z;
>>surf(x,y,z);          %三维曲面图,如图1-1
>>pause;                
>>mesh(x,y,z)          %三维曲面图,如图1-2

insert image description here

Example 2: Draw a 3D curve using meshz

>>clear all;
>>x=-3:.125:3;
>>[X,Y]=meshgrid(x);
>>Z=peaks(X,Y);
>>meshz(X,Y,Z)

insert image description here

Guess you like

Origin blog.csdn.net/AII_IIA/article/details/107739952