P5-1-1
L1=30;
L2=23;
L3=12;
r1=L1/6;
r2=L1/12;
r3=L2/10;
arm1x=[ r1 r1*cosd(240)+r1 r1*cosd(210)+r1 0 r1*cosd(150)+r1 r1*cosd(120)+r1 r1 11*r2 11*r2+r2*cosd(60) 11*r2+r2*cosd(30) L1 11*r2 L1 11*r2+r2*cosd(-30) 11*r2+r2*cosd(-60) 11*r2 r1];
arm1y=[-r1 r1*sind(240) r1*sind(210) 0 r1*sind(150) r1*sind(120) r1 r2 r2*sind(60) r2*sind(30) 0 0 0 r2*sind(-30) r2*sind(-60) -r2 -r1];
arm2x=[10*r2 11*r2+r2*cosd(150) 11*r2+r2*cosd(120) 11*r2 L1+L2-3*r2 L1+L2-3*r2+r2*cosd(60) L1+L2-3*r2+r2*cosd(30) L1+L2-2*r2 L1+L2-3*r2+r2*cosd(-30) L1+L2-3*r2+r2*cosd(-60) L1+L2-3*r2 11*r2 11*r2+r2*cosd(240) 11*r2+r2*cosd(210) 10*r2];
arm2y=[0 r2*sind(150) r2*sind(120) r2 r2 r2*sind(60) r2*sind(30) 0 r2*sind(-30) r2*sind(-60) -r2 -r2 r2*sind(240) r2*sind(210) 0 ];
palmx=[L1+L2-2*r2 L1+L2-r2 L1+L2+L3-2*r2 L1+L2-r2 L1+L2-2*r2];
palmy=[0 r3 0 -r3 0 ];
line(arm1x,arm1y);
line(arm2x,arm2y,'color','r');
line(palmx,palmy,'color','k');
axis equal;
P5-1-2
function body(L1,L2,L3,theta1,theta2,theta3);
%function body(L1,L2,L3,theta1,theta2,theta3)
%輸入:
% L1:上臂長,L2:下臂長,L3:手掌長
% theta1為上手臂之水平角度(順時針),theta2為下手臂對上手臂的角度(逆時針),theta3為手掌對下手臂之夾角
arm1x=[ r1 r1*cosd(240)+r1 r1*cosd(210)+r1 0 r1*cosd(150)+r1 r1*cosd(120)+r1 r1 11*r2 11*r2+r2*cosd(60) 11*r2+r2*cosd(30) L1 11*r2 L1 11*r2+r2*cosd(-30) 11*r2+r2*cosd(-60) 11*r2 r1];
arm1y=[-r1 r1*sind(240) r1*sind(210) 0 r1*sind(150) r1*sind(120) r1 r2 r2*sind(60) r2*sind(30) 0 0 0 r2*sind(-30) r2*sind(-60) -r2 -r1];
arm2x=[10*r2 11*r2+r2*cosd(150) 11*r2+r2*cosd(120) 11*r2 L1+L2-3*r2 L1+L2-3*r2+r2*cosd(60) L1+L2-3*r2+r2*cosd(30) L1+L2-2*r2 L1+L2-3*r2+r2*cosd(-30) L1+L2-3*r2+r2*cosd(-60) L1+L2-3*r2 11*r2 11*r2+r2*cosd(240) 11*r2+r2*cosd(210) 10*r2];
arm2y=[0 r2*sind(150) r2*sind(120) r2 r2 r2*sind(60) r2*sind(30) 0 r2*sind(-30) r2*sind(-60) -r2 -r2 r2*sind(240) r2*sind(210) 0 ];
palmx=[L1+L2-2*r2 L1+L2-r2 L1+L2+L3-2*r2 L1+L2-r2 L1+L2-2*r2];
palmy=[0 r3 0 -r3 0 ];
line(arm1x,arm1y);
line(arm2x,arm2y,'color','r');
line(palmx,palmy,'color','k');
axis equal
clf
x1=(arm1x-r1)*cosd(-theta1)-arm1y*sind(-theta1);
y1=(arm1x-r1)*sind(-theta1)+arm1y*cosd(-theta1);
%將上臂連桿以座標原點順時針旋轉
theta2=180+theta1-theta2;
x2=x1(12)+(arm2x-11*r2)*cosd(-theta2)-arm2y*sind(-theta2);
y2=y1(12)+(arm2x-11*r2)*sind(-theta2)+arm2y*cosd(-theta2);
%將上、下臂以手肘為旋轉點,下臂逆時針旋轉
theta3=180+theta2-theta3;
x3=x2(8)+(palmx-L1-L2+2*r2)*cosd(-theta3)-palmy*sind(-theta3);
y3=y2(8)+(palmx-L1-L2+2*r2)*sind(-theta3)+palmy*cosd(-theta3);
%手掌以手腕為旋轉點,逆時針旋轉
line(x2,y2,'color','r');
line(x3,y3,'color','k');
axis equal;
axis([-30 30 -30 30]);
P5-1-3
body(30,23,12,90,-45,-30);
P5-1-4
L1=30;
L2=23;
L3=12;
r1=L1/6;
r2=L1/12;
r3=L2/10;
arm1x=[ r1 r1*cosd(240)+r1 r1*cosd(210)+r1 0 r1*cosd(150)+r1 r1*cosd(120)+r1 r1 11*r2 11*r2+r2*cosd(60) 11*r2+r2*cosd(30) L1 11*r2 L1 11*r2+r2*cosd(-30) 11*r2+r2*cosd(-60) 11*r2 r1];
arm1y=[-r1 r1*sind(240) r1*sind(210) 0 r1*sind(150) r1*sind(120) r1 r2 r2*sind(60) r2*sind(30) 0 0 0 r2*sind(-30) r2*sind(-60) -r2 -r1];
arm2x=[10*r2 11*r2+r2*cosd(150) 11*r2+r2*cosd(120) 11*r2 L1+L2-3*r2 L1+L2-3*r2+r2*cosd(60) L1+L2-3*r2+r2*cosd(30) L1+L2-2*r2 L1+L2-3*r2+r2*cosd(-30) L1+L2-3*r2+r2*cosd(-60) L1+L2-3*r2 11*r2 11*r2+r2*cosd(240) 11*r2+r2*cosd(210) 10*r2];
arm2y=[0 r2*sind(150) r2*sind(120) r2 r2 r2*sind(60) r2*sind(30) 0 r2*sind(-30) r2*sind(-60) -r2 -r2 r2*sind(240) r2*sind(210) 0 ];
palmx=[L1+L2-2*r2 L1+L2-r2 L1+L2+L3-2*r2 L1+L2-r2 L1+L2-2*r2];
palmy=[0 r3 0 -r3 0 ];
line(arm1x,arm1y);
line(arm2x,arm2y,'color','r');
line(palmx,palmy,'color','k');
axis equal;
clf
theta1=linspace(-90,-75,10);
theta2=linspace(-45,-35,10);
theta3=linspace(-30,-10,10);
for n=1:10;
x1=(arm1x-r1)*cosd(-theta1(n))-arm1y*sind(-theta1(n));
y1=(arm1x-r1)*sind(-theta1(n))+arm1y*cosd(-theta1(n));
theta2(n)=180+theta1(n)-theta2(n);
x2=x1(12)+(arm2x-11*r2)*cosd(-theta2(n))-arm2y*sind(-theta2(n));
y2=y1(12)+(arm2x-11*r2)*sind(-theta2(n))+arm2y*cosd(-theta2(n));
theta3(n)=180+theta2(n)-theta3(n);
x3=x2(8)+(palmx-L1-L2+2*r2)*cosd(-theta3(n))-palmy*sind(-theta3(n));
y3=y2(8)+(palmx-L1-L2+2*r2)*sind(-theta3(n))+palmy*cosd(-theta3(n));
line(x1,y1);
line(x2,y2,'color','r');
line(x3,y3,'color','k');
axis equal;
axis([-30 30 -30 30]);
pause(1);
clf;
end;
手臂連桿的轉動
2007年4月10日 星期二
第五週作業
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言