作業五 b94611040 廖婉婷
5-1-1
以下為繪製上下手臂外形之函式:
參考講義上連桿之linkshape函式
joint處修正為僅畫外圓
function arm(A,B,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,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;
以下為繪製手掌外形之函式:
參考之前講義linkshape函式
手指的部份另外繪出
故手指長度需為其中一項input
function draw_palm(A,B,d,f)
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 = 30; %假設上手臂,下手臂,手掌長為30cm,25cm,15cm
L2 = 25;
L3 = 15;
theta1 = 45; %假設手臂,手掌間角度之值
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;
%由於function draw_palm是將手掌/手指長度分別採用繪出
%故需另外計算手指長度
%此處假設手指長約等於整個手掌的一半
draw_palm(palm(1,:), palm(2,:), 8,finger);
%繪出整個手掌

<圖>以自己尺寸輸入之手臂圖
5-1-2
此題是將上一小題之主繪圖指令置於function body中:
function body(L1,L2,L3,theta1,theta2,theta3)
axis equal;
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);
%呼叫前一小題function arm繪出手臂
finger =L3/2;
draw_palm(palm(1,:), palm(2,:), 8,finger);
%呼掉函式繪出手掌
%繪出整支手臂之function結束
5-1-3
axis([0 100 -50 50]);
body(30,25,15,90,-45,-30);

<圖>由給定長度,角度繪出之手臂位置
5-1-4
for i = 1:6, % 動畫重複六次
for k = 1:1:10,
clf; %清除畫面,繼續指令
theta1i = -90 + 1.5*k;
%theta1i在-90~-75度間分十等分運動 因此每次動1.5度
theta2i = -45 + k;
%theta2i在-45~-35度間分十等分運動 因此每次動1度
theta3i = -30 + 4*k;
%theta3i在-30~10度間分十等分運動 因此每次動4度
body(30, 25, 15, theta1i, theta2i, theta3i);
%分別繪出每一等份之手臂位置
pause(0.2);
end;
end;
1 則留言:
good job!
張貼留言