Matlab基本函数-cylinder函数

1、cylinder函数:绘制三维圆柱图

2、用法说明:

(1)[x,y,z]=cylinder 函数返回一半径和高度都为1的圆柱体x,y,z轴的坐标值,圆柱体沿其周长有20个等距分布的点

(2)[x,y,z]=cylinder(r) 函数一个半径为r、高度为1的圆柱体的x,y,z轴的坐标值,圆柱体沿其周长有20个等距分布的点

(3)[x,y,z]=cylinder(r,n) 函数一个半径为r、高度为1的圆柱体的x,y,z轴的坐标值,圆柱体沿其周长有n个等距分布的点

(4)cylinder(...) 函数只绘制圆柱,没有任何的输出参量。其他参量及结果同上

3、实例

3.1、[x,y,z]=cylinder 函数

>> [x,y,x] = cylinder

x =

  Columns 1 through 17

     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

  Columns 18 through 21

     0     0     0     0
     1     1     1     1


y =

  Columns 1 through 10

         0    0.3090    0.5878    0.8090    0.9511    1.0000    0.9511    0.8090    0.5878    0.3090
         0    0.3090    0.5878    0.8090    0.9511    1.0000    0.9511    0.8090    0.5878    0.3090

  Columns 11 through 20

    0.0000   -0.3090   -0.5878   -0.8090   -0.9511   -1.0000   -0.9511   -0.8090   -0.5878   -0.3090
    0.0000   -0.3090   -0.5878   -0.8090   -0.9511   -1.0000   -0.9511   -0.8090   -0.5878   -0.3090

  Column 21

         0
         0


x =

  Columns 1 through 17

     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

  Columns 18 through 21

     0     0     0     0
     1     1     1     1
3.2、[x,y,z]=cylinder(r)函数

>> [x,y,z]=cylinder(5)

x =

  Columns 1 through 10

    5.0000    4.7553    4.0451    2.9389    1.5451    0.0000   -1.5451   -2.9389   -4.0451   -4.7553
    5.0000    4.7553    4.0451    2.9389    1.5451    0.0000   -1.5451   -2.9389   -4.0451   -4.7553

  Columns 11 through 20

   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451   -0.0000    1.5451    2.9389    4.0451    4.7553
   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451   -0.0000    1.5451    2.9389    4.0451    4.7553

  Column 21

    5.0000
    5.0000


y =

  Columns 1 through 10

         0    1.5451    2.9389    4.0451    4.7553    5.0000    4.7553    4.0451    2.9389    1.5451
         0    1.5451    2.9389    4.0451    4.7553    5.0000    4.7553    4.0451    2.9389    1.5451

  Columns 11 through 20

    0.0000   -1.5451   -2.9389   -4.0451   -4.7553   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451
    0.0000   -1.5451   -2.9389   -4.0451   -4.7553   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451

  Column 21

         0
         0


z =

  Columns 1 through 17

     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

  Columns 18 through 21

     0     0     0     0
     1     1     1     1>> [x,y,z]=cylinder(5)

x =

  Columns 1 through 10

    5.0000    4.7553    4.0451    2.9389    1.5451    0.0000   -1.5451   -2.9389   -4.0451   -4.7553
    5.0000    4.7553    4.0451    2.9389    1.5451    0.0000   -1.5451   -2.9389   -4.0451   -4.7553

  Columns 11 through 20

   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451   -0.0000    1.5451    2.9389    4.0451    4.7553
   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451   -0.0000    1.5451    2.9389    4.0451    4.7553

  Column 21

    5.0000
    5.0000


y =

  Columns 1 through 10

         0    1.5451    2.9389    4.0451    4.7553    5.0000    4.7553    4.0451    2.9389    1.5451
         0    1.5451    2.9389    4.0451    4.7553    5.0000    4.7553    4.0451    2.9389    1.5451

  Columns 11 through 20

    0.0000   -1.5451   -2.9389   -4.0451   -4.7553   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451
    0.0000   -1.5451   -2.9389   -4.0451   -4.7553   -5.0000   -4.7553   -4.0451   -2.9389   -1.5451

  Column 21

         0
         0


z =

  Columns 1 through 17

     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1     1

  Columns 18 through 21

     0     0     0     0
     1     1     1     1
3.3、[x,y,z]=cylinder(r,n) 函数

>> [x,y,z]=cylinder(5,10)

x =

  Columns 1 through 10

    5.0000    4.0451    1.5451   -1.5451   -4.0451   -5.0000   -4.0451   -1.5451    1.5451    4.0451
    5.0000    4.0451    1.5451   -1.5451   -4.0451   -5.0000   -4.0451   -1.5451    1.5451    4.0451

  Column 11

    5.0000
    5.0000


y =

  Columns 1 through 10

         0    2.9389    4.7553    4.7553    2.9389    0.0000   -2.9389   -4.7553   -4.7553   -2.9389
         0    2.9389    4.7553    4.7553    2.9389    0.0000   -2.9389   -4.7553   -4.7553   -2.9389

  Column 11

         0
         0


z =

     0     0     0     0     0     0     0     0     0     0     0
     1     1     1     1     1     1     1     1     1     1     1
3.4、cylinder(...) 函数

>> cylinder(5)
绘制的圆柱图




### Matlab 中 `cylinder` 函数的使用方法 #### 创建基本圆柱体 `cylinder` 函数用于创建单位高度的标准圆柱体。可以通过指定半径向量来自定义圆柱形状。默认情况下,该函数会将圆周划分为20个等分点。 ```matlab [X,Y,Z] = cylinder; surf(X,Y,Z); axis equal ``` 上述代码展示了如何生成并显示一个简单的单位高圆柱体[^4]。 #### 自定义圆柱的高度和底面半径 通过传递参数给 `cylinder` 可以改变其几何属性: - 半径:可以是一个单一数值或一系列数值组成的数组; - 高度:可通过后续缩放操作调整; 例如,要创建底部半径为6、顶部逐渐缩小至零的锥形物体,并将其细分为更多部分以获得更光滑表面的效果如下所示: ```matlab r = linspace(6, 0, 50); % 定义从大到小变化的半径序列 [X,Y,Z] = cylinder(r, 80); % 增加第二个参数控制细分程度 h = surf(X,Y,Z); set(h,'EdgeColor','none'); % 移除网格线以便更好地观察形态 lighting gouraud; light; material shiny; camlight('headlamp'); view(-37.5,30) colormap cool colorbar title({'Cone Shape Created Using Cylinder Function'; 'with Varying Radius and Increased Resolution'}) xlabel('X Axis') ylabel('Y Axis') zlabel('Z Axis') grid on box on axis tight vis3d ``` 这段脚本不仅实现了自定义尺寸的圆锥建模,还应用了一系列可视化增强措施使最终效果更加美观。 #### 控制圆柱的方向和平移变换 除了修改大小外,还可以利用旋转矩阵以及平移向量对所得模型实施空间转换。比如让之前建立好的对象沿某个特定方向移动一定距离: ```matlab % 平移到新位置 (dx, dy, dz) T = makehgtform('translate', [dx dy dz]); newXYZ = T * [reshape([X(:), Y(:), Z(:)]', [], 3) ones(size(Z(:)), 1)]'; X_new = reshape(newXYZ(:, 1), size(X)); Y_new = reshape(newXYZ(:, 2), size(Y)); Z_new = reshape(newXYZ(:, 3), size(Z)); figure; surf(X_new, Y_new, Z_new); axis equal ``` 这里引入了齐次坐标系下的仿射变换概念,使得复杂的空间位姿调整变得简单易行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值