2007年4月18日 星期三

第四題

作業四 b94611021 張淳皓

4.1
以下為程式碼:

% 學號b94611021
%三角形邊長31
axis equal
AXIS([-55 55 -35 60])
length=21+10
x=[length/2 0 -1*length/2 length/2]
y=[0 (3)^(1/2)*length/2 0 0]

%將三角形存於handle "pic"
pic=line(x',y')

%利用迴圈及rotate指令處理動畫旋轉
for n=1:120
rotate(pic,[0 0 1],3,[length/2 0 0])
pause(0.003)
end
for n=1:120
rotate(pic,[0 0 1],3,[0 (3)^(1/2)*length/2 0])
pause(0.003)
end
for n=1:120
rotate(pic,[0 0 1],3,[-1*length/2 0 0])
pause(0.003)
end

4.2

以下為程式碼

%當連桿繞原點轉動
%設其另一端點為(x,y)
%彈簧為紅色粗線
clf
x=[0 10]
y=[0 0]
hold on
for n=1:12

m= x*cosd(30*n)-y*sind(30*n)
k= x*sind(30*n)+y*cosd(30*n)
linkshape([m(1) k(1)],[m(2) k(2)],4)
AXIS([-15 20 -15 15])
line([m(2) 15],[k(2) 0],'Color','r','LineWidth',2)
end

圖片

4.3

(1)繪出連桿位置
以下為程式:
%繪出連桿A(0,0);B(3,4);C(13,4);D(10,0)
%
a=[0 0]
b=[3 4]
c=[13 4]
d=[10 0]
linkshape(a,b,1)
linkshape(b,c,1.5)
linkshape(c,d,2)
linkshape(a,d,2)
圖片

(2)繪出移動圖示
以下為程式:

clf
hold on

a=[0 0]
b=[3 4]
c=[13 4]
d=[10 0]
linkshape(a,d,1)
for n=1:12
bx= b(1)*cosd(30*n)-b(2)*sind(30*n)
by= b(1)*sind(30*n)+b(2)*cosd(30*n)
cx=bx+10
cy=by
linkshape([10 0],[cx cy],1.5)
linkshape([bx by],[cx cy],2)
linkshape([0 0],[bx by],2)
pause(0.2)
end

圖片

新增的部份
程式為修改原four_link3而來 將程式中line函式轉為linkshape函式
function four_link3(theta2,r,mode)
% figure4.11 drawing program
%Inputs:
% theata2:links to display in link 2 degrees
% r:row matrix for link lengths={r1 r2 r3 r4]
% mode:+1/-1 for toggling position
% Example:
% four_link3([60],[4 2 4.2 2.6],1)
% Author: DSFon, BIME, NTU, Date:Feb 4,2007.
%

圖片">

1 則留言:

匿名 提到...

張淳皓救救我><

我昨天晚上去老師的講義區抓了dyad的function來用,

可是我發現我不管怎麼弄,

debug都會告訴我說dyad這個function有錯,

可是我找不到錯啊><。

主要就是錯在
if nargin<4,  
tdd=zeros(size(rho))  
if nargin==2,  
td=ones(size(rho))  
end
end
這幾行裡面

他說我missing variable or function

我現在只知道nargin是代表我輸入的變數有幾個,

剩下zeros跟ones我看不太懂,

不過這幾個functions都是matlab內建的所以我想應該也沒有少掉什麼function

然後變數我不是有給了嗎/ \

感覺上也不太可能少呀,

好奇怪 我弄了好久都還是卡在這邊,

除非我狠下心把上面那幾行刪掉,

不然真的跑不動!!

救我 ><。