Creating a cylinder with axis centered differently

2019-01-19 02:40发布

I know Matlab has a function called cylinder to create the points for a cylinder when number of points along the circumference, and the radius length. What if I don't want a unit cylinder, and also don't want it to center at the default axis (for example along z-axis)? What would be the easiest approach to create such a cylinder? Thanks in advance.

2条回答
神经病院院长
2楼-- · 2019-01-19 03:25

The previous answer is fine, but you can get matlab to do more of the work for you (because the results of cylinder separate x,y,z components you need to work a little to do the matrix multiplication for the rotation). To have the center of base of the cylinder at [x0 y0 z0], scaled by [xf yf xf] (use xf=yf unless you want an elliptic cylinder), use:

[x y z] = cylinder;
h=mesh(x*xf+x0,y*yf+y0,z*zf+z0)

If you also want to rotate it so it isn't aligned along the z-axis, use rotate. For example, to rotate about the x-axis by 90 degrees, so it's aligned along the y-axis, use:

rotate(h,[1 0 0],90)
查看更多
萌系小妹纸
3楼-- · 2019-01-19 03:38

Multiply the points by your favourite combination of a scaling matrix, a translation matrix, and a rotation matrix.

查看更多
登录 后发表回答