Create a cylinder with an axis in the center

I know that Matlab has a function called a cylinder for creating points for a cylinder when the number of points along a circle and the length of the radius. What should I do if I do not want a single cylinder and also do not want it to be centered on the default axis (for example, along the z axis)? What would be the easiest way to create such a cylinder? Thanks in advance.

+6
geometry matlab
source share
2 answers

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) 
+11
source share

Multiply points with your favorite scalable matrix combination transformation matrix and rotation matrix .

+5
source share

All Articles