声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 4303|回复: 7

[编程技巧] 构造旋转体

[复制链接]
发表于 2005-7-12 21:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  1. % 构造旋转体
  2. % 圆柱
  3. subplot(221);
  4. t=ones(1,40)*5;
  5. [x,y,z]=cylinder(t);
  6. c=ones(size(z));
  7. surf(x,y,z,c)
  8. shading faceted
  9. title('圆柱')
  10. axis off

  11. % 圆锥
  12. subplot(222);
  13. t=0:.1:2;
  14. [x,y,z]=cylinder(fliplr(t));
  15. c=ones(size(z));
  16. surf(x,y,z,c)
  17. shading faceted
  18. title('圆椎')
  19. axis off

  20. % 椭球
  21. subplot(223)
  22. t=linspace(0,pi,100);
  23. [x,y,z]=cylinder(sin(t)/4);
  24. c=ones(size(z));
  25. mesh(x,y,z,c)
  26. shading faceted
  27. title('椭球')
  28. set(gca,'position',[0.13 0 0.327023 0.44])
  29. axis off

  30. % 一般旋转体
  31. subplot(224)
  32. t=linspace(0,pi,100);
  33. [x,y,z]=cylinder(2+cos(t).^2);
  34. c=ones(size(z));
  35. mesh(x,y,z,c)
  36. shading faceted
  37. title('一般旋转体')
  38. set(gca,'position',[0.56 0 0.327023 0.44])
  39. axis off
复制代码

回复
分享到:

使用道具 举报

 楼主| 发表于 2005-7-12 21:14 | 显示全部楼层

抖动的蜂窝

  1. t=[1:10000];
  2. tr=randn(size(t));
  3. r=cos(t).*cos(t*6)+cos(t*9).*cos(tr*9);
  4. x=r.*cos(t+pi/2);
  5. y=r.*sin(t+pi/2);
  6. H=plot(x,y);
  7. k=1;
  8. xlabel('Please press "space" key and stop this program!',...
  9.   'fontsize',12,'color','r');
  10. set(gcf,'doublebuffer','on');
  11. d=0;
  12. while k
  13.    s=get(gcf,'currentkey');
  14.    if strcmp(s,'space');
  15.        clc;k=0;
  16.    end
  17.    t=t+cos(d+1)*10;
  18.    r=0.2*sin(t)+sin(3*t).*sin(5*t)+1.9*sin(7*t).*sin(9*t);
  19.    x=r.*cos(t);
  20.    y=r.*sin(t);
  21.    set(H,'xdata',x,'ydata',y);
  22.    pause(0.1);
  23. end
  24. figure(gcf);
复制代码

发表于 2010-10-24 12:13 | 显示全部楼层

点评

首帖理当鼓励加威望, 但觉得少些什麽 :)  发表于 2010-10-24 15:17
发表于 2010-10-26 16:17 | 显示全部楼层
顶一下,最好再能做个动画的

点评

可以的  发表于 2010-10-26 16:45
发表于 2010-10-27 07:05 | 显示全部楼层
发表于 2010-10-27 10:05 | 显示全部楼层
回复 happy 的帖子

好,有时间去学习下
发表于 2010-10-28 21:22 | 显示全部楼层
yanhaoguo 发表于 2010-10-27 10:05
回复 happy 的帖子

好,有时间去学习下

改出来后分享一下,
发表于 2010-10-29 21:31 | 显示全部楼层
献上旋绕动画一个:曲线xy=1绕z轴旋转一周
figure;
view(3);
axis([-3,3,-3,3,0,3]);
axis off
hold all;
plot3([0,0],[0,0],[-3,3],'k')
plot3([-3,3],[0,0],[0,0],'k')
plot3([0,0],[-3,3],[0,0],'k')
ax=[3,2.7,2.7;0,.2,-.2;0,0,0];
fill3(ax(1,:),ax(2,:),ax(3,:),'k')
ax=[0,.2,-.2;0,0,0;3,2.7,2.7];
fill3(ax(1,:),ax(2,:),ax(3,:),'k')
ax=[0,.2,-.2;3,2.7,2.7;0,0,0];
fill3(ax(1,:),ax(2,:),ax(3,:),'k')%绘制坐标系
t=1/2:.001:2;
for theta=0:pi/100:2*pi
z=t;x=sin(theta)*1./t;y=cos(theta)*1./t;
line(x,y,z,'color',rand(1,3));
pause(.005)
end

通过效果图可以看出,line绘制的是曲线图,而mesh绘制的才是曲面图,
不知有没有高手可以奉献一个曲面的动画?或者是mesh就不能产生这种类型的动画?

评分

1

查看全部评分

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-19 12:58 , Processed in 0.068462 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表