2007年6月16日 星期六

作業五

B94611003

作業五
以人體為例,其手臂的動作可以視為三支桿,分別由上手臂,下手臂及手掌等三部份組成。其連結點分別為BCD,上手臂長為L1,下手臂長為L2,手掌長為L3,分別為三連桿,其連結點均屬旋轉結。

一.
  1. 試分別以一線畫繪出上手臂,下手臂及手掌的外形,令其座標組合名稱分別為arm1, arm2, palm,各組合之起點與終點分別為其連結點(注意:每人所做的應該不同,請勿抄襲)。
  2. 寫 出一程式函數function body(L1,L2,L3,theta1,theta2,theta3),令其繪出整個手臂的外型。其對應角度除第一個上手臂之水平角度為theta1 外,theta2為下手臂對上手臂的角度,theta3為手掌對下手臂之夾角,後二者反時針方向為正,順時針方向為負。其連桿連結角度關係如圖二。試就所 撰寫之程式結構作一說明。
  3. 試量自己的手臂尺寸作為輸入,當theta1=90度,theta2=-45度,theta3=-30度時,其位置如何。
  4. 設theta1角度在-90度與-75度間變動,theta2在-45度至-35度間變動,而theta3則在-30度至-10度間變動。試將其變動區間分為十等分,模擬其動畫,並在部落格中顯示其動作

製作繪製手臂外型的函式:
function arm(A,B,e)
e=abs(e);
AB=(B(1)+j*B(2))-(A(1)+j*A(2));
D=abs(AB);th=angle(AB);
t=linspace(pi/2,2.5*pi,20);
Cout=max(d/2,0.2)*exp(j*t');Cin=Cout/2;
if d>0,
P=[Cout;Cout(1:10);D+Cout(11:20);D+Cout;D+Cout(20);Cout(1)];
else
P=[Cin;0;D;D+Cin];
end;
xx=real(P);yy=imag(P);
x=xx*cos(th)-yy*sin(th)+A(1);
y=xx*sin(th)+yy*cos(th)+A(2);
line(x,y);
axis equal;
function draw_palm(A,B,c,d)
d=abs(d);
AB=(B(1)+j*B(2))-(A(1)+j*A(2));
D=abs(AB);th=angle(AB);
t=linspace(pi/2,2.5*pi,17);
Cout=max(d/2,0.2)*exp(j*t');Cin=Cout/2;
if d>0,
P=[Cout;Cout(1:9);
D+Cout(9);D+Cout(9)+f;D+Cout(9);D+Cout(9:11);
D+Cout(11);D+Cout(11)+f;D+Cout(11);D+Cout(11:13);
D+Cout(13);D+Cout(13)+f;D+Cout(13);D+Cout(13:15);
D+Cout(15);D+Cout(15)+f;D+Cout(15);D+Cout(15:17);
D+Cout(17);D+Cout(17)+f;D+Cout(17);
D+Cout;D+Cout(9);D+Cout(17);Cout(1)];
else
P=[Cin;0;D;D+Cin];
end;
xx=real(P);yy=imag(P);
x=xx*cos(th)-yy*sin(th)+A(1);
y=xx*sin(th)+yy*cos(th)+A(2);
line(x,y);
axis equal;


axis([0 100 -50 50]);
axis equal;
L1 = 25;
L2 = 23;
L3 = 10;
theta1 = 55;
theta2 = 235;
theta3 = 200;
a = L1*cosd(theta1);
b = -L1*sind(theta1);
c = a+L2*cosd(theta2-theta1-180);
d = b+L2*sind(theta2-theta1-180);
theta4 = theta3+theta2-theta1-360;
e = c+L3*cosd(theta4)/2;
f = d+L3*sind(theta4)/2;
arm1 = [0 0;a b];
arm2 = [a b;c d];
palm = [c d;e f];
arm(arm1(1,:), arm1(2,:), 7);
arm(arm2(1,:), arm2(2,:), 5);
finger =L3/2;
draw_palm(palm(1,:), palm(2,:), 8,finger);
繪製完成

二.

設出手指每個關節的函數意義
程式如下:
function hand(a,b,c)
clf
axis equal
for n=0:6
palm=[0 0;6 0;6 0.5;0 0.5;0 0]
patch(palm(:,1),palm(:,2),'k')

first=[6 0;
6+a*cosd(15*n) a*sind(-15*n);
6+a*cosd(15*n)+0.5*cosd(15*n-90) a*sind(-15*n)-0.5*sind(-15*n-90);
6+a*cosd(15*n)+0.5*cosd(15*n-90)+a*cosd(15*n+180) a*sind(-15*n)-0.5*sind(-15*n-90)+a*sind(-15*n+180);
6+a*cosd(15*n)+0.5*cosd(15*n-90)+a*cosd(15*n+180)+0.5*cosd(15*n-270) a*sind(-15*n)-0.5*sind(-15*n- 90)+a*sind(-15*n+180)-0.5*sind(-15*n-270) ]

patch(first(:,1),first(:,2),'b')
pause(0.6)
second=[6+a*cosd(15*n) a*sind(-15*n);
6+a*cosd(15*n)+b*cosd(15*n*2) a*sind(-15*n)+b*sind(-15*n*2);
6+a*cosd(15*n)+b*cosd(15*n*2)+0.5*cosd(15*n*2-90) a*sind(-15*n)+b*sind(-15*n*2)-0.5*sind(15*n*2-90);
6+a*cosd(15*n)+b*cosd(15*n*2)+0.5*cosd(15*n*2-90)+b*cosd(15*n*2+180) a*sind(-15*n)+b*sind(-15*n*2)-0.5*sind(15*n*2-90)-b*sind(15*n*2+180);
6+a*cosd(15*n)+b*cosd(15*n*2)+0.5*cosd(15*n*2-90)+b*cosd(15*n*2+180)+0.5*cosd(15*n*2-270) a*sind(-15*n)+b*sind(-15*n*2)-0.5*sind(15*n*2-90)-b*sind(15*n*2+180)-0.5*sind(15*n*2-270)]
patch(second(:,1),second(:,2),'b')

third=[6+a*cosd(15*n)+b*cosd(15*n*2) a*sind(-15*n)+b*sind(-15*n*2);
6+a*cosd(15*n)+b*cosd(15*n*2)+c*cosd(15*n*3) a*sind(-15*n)+b*sind(-15*n*2)-c*sind(15*n*3);
6+a*cosd(15*n)+b*cosd(15*n*2)+c*cosd(15*n*3)+0.5*cosd(15*n*3-90) a*sind(-15*n)+b*sind(-15*n*2)-c*sind(15*n*3)-0.5*sind(15*n*3-90);
6+a*cosd(15*n)+b*cosd(15*n*2)+c*cosd(15*n*3)+0.5*cosd(15*n*3-90)+c*cosd(15*n*3+180) a*sind(-15*n)+b*sind(-15*n*2)-c*sind(15*n*3)-0.5*sind(15*n*3-90)-c*sind(15*n*3+180)]
patch(third(:,1),third(:,2),'b')

end

將手指的長度輸入function 即可得到答案
食指 2.5 1.5 0.8
中指 3 2 1
無名指 2.7 2 1
小指 2.2 1.3 0.6

沒有留言: