MATLAB: How Do I Perform a Surface of Revolution of a 2D Plot that is not a Function

cylinderMATLABparametricrevolutionvolume

If I have a 2D plot that is defined by two separate functions, such that the resulting plot is not a function, how do I create a surface of revolution of the plot by rotating that curve around the x-axis? For example, consider the plot generated by executing the following:
x = -1:.01:1;
plot(x,acos(x)+4)
grid on
hold on
plot(x,-acos(x)+4)

Best Answer

The function "cylinder" can generate a surface based on a profile by rotating that profile around the x-axis and then aligning the resulting surface with the z- axis:
However, the cylinder function treats the profile that is being passed into it as having monotonically increasing x-values; i.e. that the profile is a function. Thus, when you are trying to rotate a curve that is like a sideways parabola (which is not a function) it will not produce the desired result.
In order to visualize this surface, as well as get the X,Y,and Z coordinates of what the resulting surface would be, you need to parameterize the function in terms of two new variables, "t" and a "theta". This allows you to define an "R(t,x)" that one can use to generate the desired Y and Z values for the resulting surface of revolution.
In this example, you define a "t" to go between 0 and 4. This is because in this curve, the x-values go from -1 to 1 and back to -1. This accounts for a total "distance" traveled of 4. You then define your "x" values in terms of "t". R(t,x) in this case will be "acos(x) + 4" for "t" values less than 2 and will be "-acos(x) + 4" for values of "t" greater than 2.
Once you have your x(t) and R(t,x) defined all that is left is to define the Y and Z coordinates of the surface revolution. This is done by defining a new variable "theta" that goes in between 0 and 2*pi. At every x value, there is a corresponding R(t,x) value that represents the curve at that point in 2D space. When we rotate that around in 3D space, we have Y and Z values that are defined as follows (given to us by basic trigonometry):
Y = R(t,x) * cos(theta)
Z = R(t,x) * sin(theta).
Thus, you have a way to get your X,Y, and Z coordinates. From there, you can use the "surf" function to visualize the surface, or simply use the them for other sorts of processing.
Please see the attached script for more details.