怎么用Matlab的"cylinder function"创建一个旋转面?

How to use the "cylinder function" of Matlab to create a surface of revolution?

我一直在尝试使用 MatLab 开发一个绘制旋转曲面的 GUIDE 程序,但我只是得到了错误的答案。

这是我尝试过的:

b = str2double(get(handles.editB, 'string'));
Incremento = str2double(get(handles.editIncrement, 'string'));
x = a:Incremento:b;
y = a:Incremento:b;

helperFunction = get(handles.editFunction, 'string' );
myFunction = eval(helperFunction);
[X,Y,Z] = cylinder(myFunction);
surf(Y,X,Z);
title('Surface of Revolution'); 

此外,我不得不提到前面的代码绘制了一个函数的旋转曲面,就好像该函数是反函数一样。例如:我想尝试绘制 x^2 的旋转曲面,然后程序将输出 sqrt(x) 的旋转曲面。

我认为你得到的答案是正确的,但你对这个功能的期望是错误的。根据 MA​​TLAB 文档:

[X,Y,Z] = cylinder(r) returns the x-, y-, and z-coordinates of a cylinder using r to define a profile curve. cylinder treats each element in r as a radius at equally spaced heights along the unit height of the cylinder. The cylinder has 20 equally spaced points around its circumference.

换句话说,该函数将向量r的第一个和最后一个元素分别视为高度为0和1的圆柱体半径,其他元素为该区间内等间距高度的圆柱体半径.下图可以更好地解释这一点: