一、三维绘图
1.曲线图
plot3(X1,Y1,Z1,...):以默认线性属性绘制三维点集(X1,Y1,Z1)确定的曲线
plot3(X1,Y1,Z1,LineSpec):以参数LineSpec确定的线性属性绘制三维点集
plot3(X1,Y1,Z1,'PropertyName',PropertyValue,...):根据指定的属性绘制三维曲线
theta = 0:0.01*pi:2*pi;
x = sin(theta);
y = cos(theta);
z = cos(4*theta);
plot3(x,y,z,'LineWidth',2);
hold on;
theta = 0:0.02*pi:2*pi;
x = sin(theta);
y = cos(theta);
z = cos(4*theta);
plot3(x,y,z,'rd','MarkerSize',10,'LineWidth',2);
2.网格图
绘制函数z=f(x,y)的三维网格图的过程:
确定自变量x和y的取值范围和取值间隔
利用meshgrid函数生成“格点”矩阵
计算自变量采样“格点”上的函数值:Z = f(x,y)
matlab中提供了mesh函数用于实现绘制网格图:
mesh(X,Y,Z):绘制三维网格图,颜色与曲面的高度相匹配
mesh(Z):系统默认颜色与网格区域的情况下绘制数据Z的网格图
mesh(...,C,'PropertyName',PropertyValue):对指定的颜色C,指定的属性值,画出三维图形
meshc(...):用于画网格图与基本的等值线图
meshz(...):用于绘制包含零平面的网格图
h = mesh(...):返回图形对象句柄属性值向量h
[X,Y] = meshgrid(-3:.5:3);
Z = 2 * X.^2-3 * Y.^2;
subplot(2,2,1)
plot3(X,Y,Z)
title('plot3')
subplot(2,2,2)
mesh(X,Y,Z)
title('mesh')
subplot(2,2,3)
meshc(X,Y,Z)
title('meshc')
subplot(2,2,4)
meshz(X,Y,Z)
title('meshz')
set(gcf,'Color','w');
3.曲面图
表示三维空间内数据的变化规律。函数有surf、surfc和surfl
surf(X,Y,Z):绘制三维的彩色曲面图。
surf(X,Y,Z,C):图形的颜色采用参数C,同样可以添加属性值
[x,y] = meshgrid(-3:1/8:3);
z = peaks(x,y);
subplot(2,2,1);surf(z);
title('surf(z)绘制形式');
subplot(2,2,2);surf(x,y,z);
title('surf(x,y,z)绘图形式');
subplot(2,2,3);surfl(x,y,z);
title('surfl(x,y,z)绘图形式');
subplot(2,2,4);surfc(x,y,z);
title('surfc(x,y,z)绘图形式');
4.光照模型
光照是利用方向官员照亮物体的技术,这项技术能使