The previous answer is fine, but you can get Matlab to do more work for you (because the cylinder results of the individual x,y,z components you need to do a bit to do matrix multiplication for rotation). To have the center of the base of the cylinder at [x0 y0 z0] scaled to [xf yf xf] (use xf=yf if you don't want to use an elliptical cylinder), use:
[xyz] = cylinder; h=mesh(x*xf+x0,y*yf+y0,z*zf+z0)
If you also want to rotate it so that it is not aligned along the z axis, use rotate . For example, to rotate around the x-axis 90 degrees, so it aligns along the y axis, use:
rotate(h,[1 0 0],90)
Ramashalanka
source share