You are on page 1of 4

Mecanismo de 4 barras

Codigo Matlab
clear all
%% DATOS DE ENTRADA
r1=30;
r2=35;
r3=38;
r4=20;
w1=5;
a1=0;
n=1;
%% Posicion
for T=0:11:360
t1=T*pi/180;
A=-r1*cos(t1)+r4;
B=-r1*sin(t1);
C=(A^2+B^2+r2^2-r3^2)/(2*r2);
D=(r2^2-A^2-B^2-r3^2)/(2*r3);
t2=2*atan((B+(A^2+B^2-C^2)^(1/2))/(A+C));
t3=2*atan((B+(A^2+B^2-D^2)^(1/2))/(A+D));
w2=(r1*sin(t1)*w1)/(r3*sin(t3)-r2*sin(t2));
w3=(-r1*cos(t1)*w1)/(r2*cos(t2)-r3*cos(t3));
a2=(r2*cos(t2)*w2^2r3*cos(t3)*w3^2+r1*cos(t1)*w1^2+r1*sin(t1)*a1)/(r3*sin(t3)-r2*sin(t2));
a3=(r1*sin(t1)*w2^2-r1*cos(t1)*a1+r2*sin(t2)*w2^2r3*sin(t3)*w3^2)/(r2*cos(t2)-r3*cos(t3));
xp=r1*cos(t1)+r2*cos(pi/3+t2);
yp=r1*sin(t1)+r2*sin(pi/3+t2);
vxp=-r1*sin(t1)*w1-r2*sin(pi/3+t2)*w2;
vyp=r1*cos(t1)*w1+r2*cos(pi/3+t2)*w2;
axp=-r1*cos(t1)*w1^2+(-r1*sin(t1)*a1)-r2*cos(pi/3+t2)*w2^2+(r2*sin(pi/3+t2)*a2);
ayp=-r1*sin(t1)*w1^2+(r1*cos(t1)*a1)r2*sin(pi/3+t2)*w2^2+(r2*cos(pi/3+t2)*a2);
xr1=r1*cos(t1);
yr1=r1*sin(t1);
sol(n,:)=[xp yp xr1 yr1 vxp vyp axp ayp];
n=n+1;
end
figure (1)
hold on
plot(sol(:,1),sol(:,2),'--r','linewidth',0.5);
plot(sol(:,5),sol(:,6),sol(:,7),sol(:,8),'linewidth',0.5);
grid on
hold on
quiver(sol(:,1),sol(:,2),sol(:,5),sol(:,6),'r','linewidth',1),axis square
quiver(sol(:,5),sol(:,6),sol(:,7),sol(:,8),'g','linewidth',1),axis square
figure (2)
hold on
plot(sol(:,1),sol(:,2),'linewidth',0.5);
grid on
hold on
quiver(sol(:,1),sol(:,2),sol(:,3),sol(:,4),'r','linewidth',1),axis square
figure (3)

Cristian Marcelo Sejuro Mendoza

Pgina 1

hold on
plot(sol(:,5),sol(:,6),'linewidth',0.5);
grid on
hold on
quiver(sol(:,1),sol(:,2),sol(:,3),sol(:,4),'r','linewidth',1),axis square
figure (4)
hold on
plot(sol(:,7),sol(:,8),'linewidth',0.5);
grid on
hold on
quiver(sol(:,1),sol(:,2),sol(:,3),sol(:,4),'r','linewidth',1),axis square
%% Figura
fig=figure(1);
x=[20 0 30 46.8625 -4.9961 20 -4.9961 46.8625];
y=[0 0 30 45.0273 0.4391 0 0.4391 45.0273 ];
h1=plot(x,y,'linewidth',2);
axis([-70 70 -60 70])
hold off
% Botones de comandos
uicontrol('pos',[5 5 50 21],'string','Done','fontsize',10, ...
'callback','close(gcbf)');
uicontrol('pos',[60 5 50 20],'string','Pause','fontsize',10, ...
'callback','pause');
uicontrol('pos',[115 5 50 20],'string','Slower','fontsize',10, ...
'callback','set(gcbf,''userdata'',sqrt(0.5)*get(gcbf,''userdata''))');
uicontrol('pos',[170 5 50 20],'string','Faster','fontsize',10, ...
'callback','set(gcbf,''userdata'',sqrt(2.0)*get(gcbf,''userdata''))');
uicontrol('pos',[225 5 50 20],'string','Resume','fontsize',10, ...
'callback','resume');
t = 0;
dt = 1;
set(fig,'userdata',dt)
while ishandle(fig)
dt = get(fig,'userdata');
t = t + dt;
T=t*pi/180;
A=-r1*cos(T)+r4;
B=-r1*sin(T);
C=(A^2+B^2+r2^2-r3^2)/(2*r2);
D=(r2^2-A^2-B^2-r3^2)/(2*r3);
t2=2*atan((B+(A^2+B^2-C^2)^(1/2))/(A+C));
t3=2*atan((B+(A^2+B^2-D^2)^(1/2))/(A+D));
x(3)=r1*cos(T);
y(3)=r1*sin(T);
x(4)=r1*cos(T)+r2*cos(t2+(pi/3));
y(4)=r1*sin(T)+r2*sin(t2+(pi/3));
x(5)=r4+r3*cos(t3);
y(5)=r3*sin(t3);
x(7)=r4+r3*cos(t3);
y(7)=r3*sin(t3);
x(8)=r1*cos(T);
y(8)=r1*sin(T);
set(h1,'XData',x)
set(h1,'YData',y)
drawnow
end

Cristian Marcelo Sejuro Mendoza

Pgina 2

Figura 1:

60

40

20

-20

-40

-60

-60

-40

-20

20

40

60

Animacin de la grfica en la cual se ve el desplazamiento del punto P y la velocidad en las distintas


posiciones de P.

Figura 2:

100
80
60
40
20
0
-20
-40
-60
-80
-100

Cristian Marcelo Sejuro Mendoza

-50

50

100

Pgina 3

Figura 3:
400

300

200

100

-100

-200

-300
-400

-300

-200

-100

100

200

300

Figura 4:
En esta grafica podemos ver la aceleracin del sistema.
5

1.5

x 10

0.5

-0.5

-1

-1.5

-2
-1.5

-1

-0.5

0.5

1.5

2.5
5

x 10

Cristian Marcelo Sejuro Mendoza

Pgina 4

You might also like