创建轴中心不同的圆柱体 [英] Creating a cylinder with axis centered differently

查看:20
本文介绍了创建轴中心不同的圆柱体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Matlab 有一个称为圆柱体的函数,当沿圆周的点数和半径长度时,它可以为圆柱体创建点.如果我不想要一个单位圆柱体,也不希望它以默认轴为中心(例如沿 z 轴)怎么办?创建这样一个圆柱体的最简单方法是什么?提前致谢.

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.

推荐答案

前面的答案很好,但是你可以让matlab为你做更多的工作(因为圆柱体的结果分开x,y,z 组件,您需要使用 little 来进行矩阵乘法以进行旋转).要使圆柱体的底部中心位于 [x0 y0 z0],按 [xf yf xf] 缩放(使用 xf=yf 除非你想要一个椭圆柱),使用:

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)

如果您还想旋转它使其不沿 z 轴对齐,请使用 rotate.例如,要围绕 x 轴 旋转 90 度,使其沿 y 轴对齐,请使用:

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)

这篇关于创建轴中心不同的圆柱体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆