% Set up cylindrical coords. r = linspace(0,1,20); theta = linspace(0,2*pi,20); z = linspace(0,1,20); % Hold theta fixed to get a half-plane. [r2,z2] = meshgrid(r,z); [x,y,z] = pol2cart(pi,r2,z2); figure(1) surf(x,y,z), axis([-1 1 -1 1 0 1]), pause, hold on % Hold r fixed to get a cylinder [theta2,z2] = meshgrid(theta,z); [x,y,z] = pol2cart(theta2,1,z2); s = surface(x,y,z); mesh(x,y,z), alpha(0.5), title('Cylindrical Coordinates'), pause, hold off % Set up spherical coords. phi = linspace(0,2*pi,20); theta=linspace(-pi/2,pi/2,20); r=linspace(0,1,20); % Hold theta fixed to get a cone. [phi2,r2] = meshgrid(phi,r); [x,y,z] = sph2cart(phi2,pi/4,r2); figure(1) surf(x,y,z), pause, hold on; % Hold phi fixed to get a half-plane. [theta2,r2] = meshgrid(theta,r); [x,y,z] = sph2cart(pi,theta2,r2); surf(x,y,z), pause, % Hold r fixed to get a sphere. [theta2,phi2] = meshgrid(theta,phi); [x,y,z] = sph2cart(phi2,theta2,1); s = surface(x,y,z); mesh(x,y,z), alpha(0.5), title('Spherical Coordinates')