平面四连杆机构 20190409
供实验数据
实验数据 3232 平面四杆机构
实验数据 1 8 1 8 平面四杆机构 成功
实验数据 1 8 2 7 平面四杆机构 1+8-2-7 成功
实验数据 1 7 8 2 平面四杆机构 1-7+8-2 成功
实验数据 1 7 2 8 平面四杆机构 1-7-2+8 成功
实验数据 2 7 8 1 平面四杆机构
主函数
function [The1,The3]= f(L,mode)
clc
clear
close all
% L=[ 2 7 8 1]
L=[ 2 7 6 10]
mode=1;
syms L1 L2 L3 L4 ;
syms the1 the3 ;
syms The1 The3 ;
A=2*L1*L3*sin(the1);
B=2*L3*(L1*cos(the1)-L4);
C=L2^2-L1^2-L3^2-L4^2+2*L1*L4*cos(the1);
D=(A.*A+B.*B-C.*C).^0.5;
mood1=(A+D)./(B-C);
mood2=(A-D)./(B-C);
the3_1=atan(mood1)*2;
the3_2=atan(mood2)*2;
L1=L(1) ;
L2=L(2) ;
L3=L(3) ;
L4=L(4) ;
L=[L1 L2 L3 L4];
y=ff(L);
y=y*mode
X=[0 cos(the1)*L1 L4+cos(the3)*L3 L4];
Y=[0 sin(the1)*L1 sin(the3)*L3 0];
for i=1:4
j=0:0.05:pi;
the1=j+(i-1)*pi;
if y(i)==0
the1=0;
the3=0;
else
if y(i)>0
the3=eval(the3_1);
else
the3=eval(the3_2);
end
end
if i==1
The1=the1;
The3=the3;
else
The1=[The1,the1];
The3=[The3,the3];
end
end
figure
plot(The1,The3)
figure
hold on;
t=[-20,20,-20,20]/2;
axis(t)
t=1:0.01:4*pi;
x=[0];
y=[0];
plot(cos(t)*L1,sin(t)*L1,'r');
plot(cos(t)*L3+L4,sin(t)*L3,'b');
h=plot(x,y,'-o');
a=length(The1);
for i=1:a
the1=The1(i);
the3=The3(i);
set(h,'XData',eval(X),'YData',eval(Y))
drawnow
end
end
功能函数(判断连杆机构类型)
- 有一个致命漏洞就是 没有判断连杆类型
- 并没有这个漏洞,是自己脑子有坑
function y= ff(L)
% clc
% clear
% close all
% L=[ 2 7 8 1]
x=sort(L);
if x(1)+x(4)<=x(2)+x(3)
if x(1)+x(4)==x(2)+x(3)
if L(1)+L(2)==L(3)+L(4)
y= [1 1 -1 -1];
end
if L(1)+L(4)==L(3)+L(2)
y= [1 -1 -1 1];
end
if L(1)+L(2)==L(3)+L(4) && L(1)+L(4)==L(3)+L(2)
y= [1 -1 1 -1];
end
if L(1)+L(3)==L(2)+L(4)
y= [1 1 -1 -1];
end
else
y= [1 1 1 1];
end
else
y= [0 0 0 0];
end
end
保存gif动图
function [The1,The3]= f(L,mode)
clc
clear
close all
pic_num=1;% L=[ 2 7 8 1]
L=[ 2 7 6 10]
mode=1;
syms L1 L2 L3 L4 ;
syms the1 the3 ;
syms The1 The3 ;
A=2*L1*L3*sin(the1);
B=2*L3*(L1*cos(the1)-L4);
C=L2^2-L1^2-L3^2-L4^2+2*L1*L4*cos(the1);
D=(A.*A+B.*B-C.*C).^0.5;
mood1=(A+D)./(B-C);
mood2=(A-D)./(B-C);
the3_1=atan(mood1)*2;
the3_2=atan(mood2)*2;
L1=L(1) ;
L2=L(2) ;
L3=L(3) ;
L4=L(4) ;
L=[L1 L2 L3 L4];
y=ff(L);
y=y*mode
X=[0 cos(the1)*L1 L4+cos(the3)*L3 L4];
Y=[0 sin(the1)*L1 sin(the3)*L3 0];
for i=1:4
j=0:0.05:pi;
the1=j+(i-1)*pi;
if y(i)==0
the1=0;
the3=0;
else
if y(i)>0
the3=eval(the3_1);
else
the3=eval(the3_2);
end
end
if i==1
The1=the1;
The3=the3;
else
The1=[The1,the1];
The3=[The3,the3];
end
end
figure
plot(The1,The3)
figure
hold on;
t=[-20,20,-20,20]/2;
axis(t)
t=1:0.01:4*pi;
x=[0];
y=[0];
plot(cos(t)*L1,sin(t)*L1,'r');
plot(cos(t)*L3+L4,sin(t)*L3,'b');
h=plot(x,y,'-o');
a=length(The1);
for i=1:a
the1=The1(i);
the3=The3(i);
set(h,'XData',eval(X),'YData',eval(Y))
drawnow
FF=getframe(gcf)
F=getframe(gcf);
I=frame2im(F);
[I,map]=rgb2ind(I,256);
if pic_num == 1
imwrite(I,map,'test.gif','gif', 'Loopcount',inf,'DelayTime',0.2);
else
imwrite(I,map,'test.gif','gif','WriteMode','append','DelayTime',0.2);
end
pic_num = pic_num + 1;
end
end
版权声明:本文为weixin_44700970原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。