MATLAB绘制三维图形

平面网格数据的生成

利用矩阵运算生成

1
2
3
4
x = 2:6;
y = (3:8)';
X = ones(size(y))*x;
Y = y*ones(size(x));

利用meshgrid函数生成

[X, Y] = meshgrid(x, y);

其中,参数x、y为向量,存储网格点坐标的X、Y为矩阵。

1
2
3
4
5
6
x = 2:6;
y = (3:8)';
[X, Y] = meshgrid(x, y);
Z = randn(size(X));
plot3(X, Y, Z)
grid on

绘制三维曲面的函数

mesh(x, y, z, c)用于绘制三维网格图

surf(x, y, z, c)用于绘制三维曲面图

其中,x、y是网格坐标矩阵,z是网格点上的高度矩阵,c用于指定在不同高度下的曲面颜色。

mesh(z, c)

surf(z, c)

当x、y省略时,z矩阵的第2维下标当作x轴坐标,z矩阵的第1维下标当作y轴坐标。

1
2
3
t = 1:5;
z = [0.5*t; 2*t; 3*t];
mesh(z);

meshc带等高线的三维网格曲面函数

meshz带底座的三维网格曲面函数

surfc带等高线的曲面函数

surfl带光照效果的曲面函数

标准三维曲面

sphere

[x, y, z] = sphere(n)

cylinder

[x, y, z] = cylinder(R, n)

参数n决定曲面的圆滑程度,默认为20。

Author

preccrep

Posted on

2020-07-29

Updated on

2020-07-29

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.
You need to set client_id and slot_id to show this AD unit. Please set it in _config.yml.