2/16/07

9.2 旋轉的風扇

會旋轉的風扇是葉片的變換而已,這是一個明顯的機動學例子,也可以看出它是一個純轉動的狀況。為製造出葉片的數目,必須先作出一個葉片的形狀,然後令其轉動數次,以求得整個葉片的座標。

x=[1 2 1 -3 -1]';y=[1 7 10 11.5 1]';%propeller shape
x0=x;y0=y;
for i=1:6,
theta=60*i;
xy=trans4([x0,y0],theta,5);
x=[x; xy(:,1)];y=[y;xy(:,2)];
end;

第一行是單片葉片的外圍形狀座標點,可由同學自行決定。然後利用這些座標旋轉6次,每次轉動60度,成為一圈所需的葉片座標。特別注意的是各座標均為行矩陣,故累加時亦必須轉成行矩陣才能相加。其餘的程序與前面各例的手法大致相同。只是這個函數有個速度參數v,可以決定該葉片的轉動速度。

程式內容


此程式呼叫一小程式circ(r),是以原點出發,以某一輸入半徑r繪圓的函數。其傳回之參數為該圓之握把h。主程式中共呼叫circ三次,第一次h0為風扇輪轂之外圈,為黑色之厚圓。第二次為葉片之內輪h1,第三次為葉輪之外圓h2,後兩者均可以隨葉片迴轉。

function demo_mot8(v)
%demo_mot8.m
%Moving propeller
%Example: demo_mot8(10)
%Author:DSFon, BIME,NTU. Date:Jan. 24, 2007
clf;
x=[1 2 1 -3 -1]';y=[1 7 10 11.5 1]';%propeller shape
x0=x;y0=y;
for i=1:6,
theta=60*i;
xy=trans4([x0,y0],theta,5);
x=[x; xy(:,1)];y=[y;xy(:,2)];
end;
delt=pi/30; %delaying time for display
axis([-15 15 -15 15]);
axis image;axis off;
h0=circ(13);set(h0,'linewidth',8,'color','k');
h1=circ(1); %the inner circle, r1
h2=circ(12.2); %The outside circle, r2
h11=line(x,y,'erasemode','xor','color','r','linewidth',5);
x1=get(h1,'xdata');y1=get(h1,'ydata'); % (x1,y1)for inner circle
x2=get(h2,'xdata');y2=get(h2,'ydata'); % (x2,y2)for outer circle
x11=get(h11,'xdata');y11=get(h11,'ydata');%(x11,y11)for propeller
set(h1,'EraseMode','xor','color','r','linewidth',3,'linestyle',':')
set(h2,'EraseMode','xor','color','b','linewidth',5,'linestyle','-.')
title('Press Ctl-C to stop');
theta1=0;s1=v*delt;
while 1,
drawnow;
pause(0.01);
theta1=theta1+s1;
z1=trans4([x1',y1'],theta1,5);
set(h1,'xdata',z1(:,1),'ydata',z1(:,2)); % inner circle
z2=trans4([x2',y2'],theta1,5);
set(h2,'xdata',z2(:,1),'ydata',z2(:,2)); % Outer circle
z11=trans4([x11',y11'],theta1,5);
set(h11,'xdata',z11(:,1),'ydata',z11(:,2)); % propeller
if theta1>2*pi,theta1=theta1-2*pi;s1=-s1;end;
end
function h=circ(r)
th=linspace(0,2*pi,50);
h=line(r*cos(th),r*sin(th));

執行後,其迴轉情況如下面之映像:

No comments:

Post a Comment