MATLAB圆柱和球绘制

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

  • cylinder用来绘制圆柱图。
  • r 为圆的半径,n为在圆上等间距取的点数。当r 为向量时,返回一层一层的圆柱,使总的高度为1。
  • 当r 中元素数量足够多时,不同半径的圆柱累积起来就变成了连续光滑的边缘。
  • n的默认值是20,当n比较大时,就是我们理想的圆柱,当n很小时,每一层就不是圆,而是正n边形。
  • 返回的图形z范围是[0,1]。我们可以对z进行伸缩变换得到想要的高度。

实例

t = linspace(0,2*pi,100);
r = abs(sin(t)) + 0.5;
subplot(1,3,1)
[x1,y1,z1] = cylinder(r,20);
surf(x1,y1,z1);
title('sylinder(r,20)');

subplot(1,3,2)
[x2,y2,z2] = cylinder(r,4);
surf(x2,y2,z2);
title('sylinder(r,4)')

subplot(1,3,3)
z3 = z1*2*pi;
surf(x1,y1,z3);
title('伸缩变换')

在这里插入图片描述

sphere

sphere(n)

直接绘制由 n × n × n n×n×n 个面组成的球。

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

返回由 n × n × n n×n×n 个面组成的球的坐标。

实例

figure

subplot(1,2,1)
sphere(6);
title('sphere(6)')

subplot(1,2,2)
[x4,y4,z4] = sphere(20);
surf(x4,y4,z4)
title('sphere(20)')

在这里插入图片描述