MATLAB: How to rotate the 2-dimensional plots to obtain 3-dimensional volumes

2 dimension3-dimensioncontoursMATLABrotatevolume

I have drawn a 2-dimensional plot. I would like to rotate the 2-dimensional contours around an axis of symmetry to produce 3-dimensional volumes. Is there any built-in function that can handle the transformation?

Best Answer

The ability to rotate 2-dimensional plots to obtain 3-dimensional volumes is not available in MATLAB.
To work around this issue, transform the plot from Cartesian coordinates into polar coordinates using the CART2POL function, and set the angle "theta" as a matrix containing regular samples around the full circle (between 0 to 2*pi) to obtain all data points in three-dimensions. Next, transform back to cartesian coordinates using the POL2CART function. Finally, use the SURF function to plot the 3-dimensional volumes.
Specifically, consider the situation where the 2-dimensional data is contained in the variables "x" and "y", which contain the X and Y location of the data points. Suppose you want to rotate the data around the the Y axis. First, convert the cartesian coordinates into polar coordinates:
x = randn(4,1);
y = randn(4,1);
[theta,rho,z] = cart2pol(x, zeros(size(x,1), size(x,2)), y);
Now rotate the data by setting up matrices with various "theta" values:
r = 9;
theta = repmat( linspace(0,2*pi,r)', 1, length(rho(:)) );
rho = repmat(rho(:).', r, 1);
z = repmat(z(:).', r, 1);
Finally, use the POL2CART function to convert back to cartesian coordinates and display using the SURF function:
[X,Y,Z] = pol2cart(theta,rho,z);
surf(X,Y,Z);