MATLAB技术论坛
• 博客等级：
• 博客积分：0
• 博客访问：590,608
• 关注人气：489
• 获赠金笔：0支
• 赠出金笔：0支
• 荣誉徽章：

【原创】利用MATLAB绘制管状几何体

(2011-07-31 11:01:45)

教育

【原创】利用MATLAB绘制管状几何体

【例1】绘制扭结
1. % Example1：扭结
2. n = 100;
3. r = 0.75;
4. q = floor(n/3);
5. t = (0:n)/n;
6. a = 2; b = 3; c = 1.5;
7. q1=2; q2=4;
8. f0 = sin(q1*pi*t) + a*sin(q2*pi*t) - ...
9.     b*cos(4*pi*t)/2 + c*sin(6*pi*t);
10. f0 = [ f0(1:n) f0(1:n) ];
11. x = f0(1:n+1);
12. y = f0(q+1:q+n+1);
13. z = f0(2*q+1:2*q+n+1);
14. figure(1)
15. TubeLike(x,y,z,r)
17. light
18. lighting gouraud
19. view(2)
20. axis equal off
21. axis vis3d

【例2】绘制双鱼
1. % Example2：双鱼
2. t = linspace(0,2*pi,50);
3. x = sin(t);
4. y = cos(t);
5. z = cos(t/2);
6. r = sin(t);
7. figure(2)
8. TubeLike(x,y,z,r)

【例3】绘制田螺
1. % Example3：田螺
2. t = linspace(0,7*pi,200);
3. x = t.*cos(t)*0.1;
4. y = t.*sin(t)*0.1;
5. z = [1:numel(t)]*0.01;
6. r = sqrt([0:numel(t)-1]*0.004);
7. figure(3)
8. TubeLike(x,y,z,r)
9. view(-44,-52)
10. axis equal off

【例4】绘制风车(或章鱼)
1. % Example4：风车(或章鱼)
2. x0 = linspace(0,2*pi,60)';
3. y0 = sin(x0);
4. t = 0:pi/4:7*pi/4;
5. x = x0*cos(t)+y0*sin(t);
6. y = -x0*sin(t)+y0*cos(t);
7. z = zeros(size(x0));
8. figure(4)
9. hold on
10. for i = 1:numel(t)
11.     [X,Y,Z] = TubeLike(x(:,i),y(:,i),z,0.5);
12.     surf(X,Y,Z,'FaceColor',rand(1,3),'LineStyle','none');
13. end
14. hold off
15. view(3)
16. axis equal off
17. light

0