s2 和s4 改下就行了!如下:
h=16;
r0=50;
ftuicheng=150*pi/180;%推程角
faiyuan=30*pi/180;%远休止角
fhuicheng=120*pi/180;%回程角
faijin=60*pi/180;%近休止角
fai1=linspace(0,ftuicheng)
s1=h*((fai1/ftuicheng)-(sin(2*pi*fai1/ftuicheng)/(2*pi)));
fai2=linspace(ftuicheng,ftuicheng+faiyuan)
s2=16*ones(1,100);
fai3=linspace(ftuicheng+faiyuan,ftuicheng+faiyuan+fhuicheng)
s3=h-10*h*(fai3-ftuicheng-faiyuan).^3/(fhuicheng)^3+15*h*(fai3-ftuicheng-faiyuan).^4/(fhuicheng)^4-6*h*(fai3-ftuicheng-faiyuan).^5/(fhuicheng)^5;
fai4=linspace(ftuicheng+faiyuan+fhuicheng,2*pi);
s4=0*ones(1,100);
fai=[fai1,fai2,fai3,fai4];
s=[s1,s2,s3,s4];
x=(r0+s).*sin(fai);
y=(r0+s).*cos(fai);
plot(x,y,'linewidth',2)
title('凸轮轮廓')
xlabel('mm')
ylabel('mm')
axis equal
grid on;
图: