通过曲线的旋转生成3D图

时间:2011-03-06 03:21:54

标签: matlab

我正在尝试旋转2D曲线以生成3D曲面图。

我尝试过使用

[X,Z,Y] = cylinder(u);
surf(X,Y,Z), axis square
然而,这会围绕错误的轴旋转我的曲线。我该如何改变轴?

非常感谢。

1 个答案:

答案 0 :(得分:4)

要旋转圆柱轴,只需更改X,Y和Z的顺序。

[X,Y,Z] = cylinder(u);

surf(X,Y,Z) %# rotation around Z
surf(Z,X,Y) %# rotation around X
surf(Y,Z,X) %# rotation around Y

修改

要更改曲线的旋转轴,必须计算曲面。例如,要围绕y轴旋转y = sin(alpha) alpha = 0:0.1:pi,您可以编写

r = 0:0.1:pi;
z = sin(r);
theta = 0:pi/20:2*pi;
xx = bsxfun(@times,r',cos(theta));
yy = bsxfun(@times,r',sin(theta));
zz = repmat(z',1,length(theta));
dfig,surf(xx,yy,zz)
axis equal

enter image description here