2007年5月23日 星期三

機動學第四次作業

題目一:

function raotate_triangle(lenth)
%轉動三角形:
%設轉動前邊長為lenth的三角形,
%以其中一個頂為原點,
%其中一邊為x軸正向
%則三頂點座標為(0,0) (lenth 0) (lenth*cos60°,lenth*sin60°)


l=lenth;
m=l*cosd(60);
n=l*sind(60);
triangle = [0 0;l 0;m n;0 0];
t = plot(triangle(:,1),triangle(:,2));
axis([-1.1*l 2.2*l -1.1*l 2.1*l]); %設定畫面長度,配合三角形大小而改變
axis equal;

for i = 1:36
axis([-1.1*l 2.2*l -1.1*l 2.1*l])
rotate(t,[0 0 1],10,[0 0 0]);
pause(0.03);
end

for i = 1:36
axis([-1.1*l 2.2*l -1.1*l 2.1*l])
rotate(t,[0 0 1],10,[m n 0]);
pause(0.03);
end

for i = 1:36
axis([-1.1*l 2.2*l -1.1*l 2.1*l])
rotate(t,[0 0 1],10,[l 0 0]);
pause(0.03);
end


我學號後兩碼為05,
故設定三角形邊長為5+10=15,
因此程式執行結果如下:

>> for i=1:5,
raotate_triangle(15)
end





第二題:

利用講議的linkshape()來繪製連桿外形,
再以下列的程式,
執行繪製連桿繞一圈時,
分別在不同的位置。
其中以每轉40°畫一次圖,
綠色線表示彈簧。

>> for t=0:40:360
a=10*cosd(t);
b=10*sind(t);
linkshape([0,0],[a,b],4);
line([15,a],[0,b],'color','g');
end




第三題:


跟據題意,
第一桿長為10㎝,
第二桿長為5㎝,
第三桿長為10㎝,
第四桿長為5㎝。

則起始位置為:

>> linkshape([10 0 ],[0 0],2);
>> linkshape ([0 0],[3 4],3 );
>> linkshape([3 4],[13 4],1.5);
>> linkshape([13 4],[10 0],2);




而每30°作一次回轉,
該路徑圖為:

>> for i=0:30:360
linkshape([10 0 ],[0 0],2);
linkshape ([0 0],[5*cosd(i) 5*sind(i)],3 );
linkshape([5*cosd(i) 5*sind(i)],[5*cosd(i)+10 5*sind(i) ],1.5);
linkshape([10 0],[5*cosd(i)+10 5*sind(i)],2);
end

沒有留言: