JC2102
JC2102

Reputation: 55

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

I have been trying to develop a GUIDE program with MatLab that plots a surface of revolution but I just got wrong answers.

Here's what I tried:

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'); 

In addition I have to mention that the previous code plots surfaces of revolution of a function as if the function were the inverse function. For example: I wanna try to plot the surface of revolution of x^2 then the program would output the surface of revolution of sqrt(x).

Upvotes: 1

Views: 332

Answers (1)

saastn
saastn

Reputation: 6015

I think the answers you get are correct, but your expectations of this function are wrong. According to MATLAB documents:

[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.

In other words, this function considers the first and last elements of the vector r as cylinder radii at heights 0 and 1, respectively, and the other elements as cylinder radii at equally spaced heights in this interval. The following figure may explain this better:

enter image description here

Upvotes: 1

Related Questions