您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > Matlab圆弧插补程序+郑国安
Matlab圆弧插补程序+郑国安X0=input('请输入起点横轴坐标X\nX0=');Y0=input('请输入起点纵轴坐标Y\nY0=');Xe=input('请输入终点横轴坐标X\nXe=');Ye=input('请输入终点纵轴坐标Y\nYe=');R=input('请输入圆弧半径\nR=');NorF=input('请选择圆心(1代表靠近原点2代表远离原点):\n');SorN=input('请选择补走向(1代表顺时针/2代表逆时针):\n');h=input('请输入步长\nh=');if((Xe==X0)&(Ye==Y0))x01=0;y01=0;x02=2*Xe;y02=2*Ye;R=sqrt(Xe^2+Ye^2);mark=0;elsemark=1;k1=(Ye-Y0)/(Xe-X0);k2=-1/k1;Xz=(X0+Xe)/2;Yz=(Y0+Ye)/2;%两点中点坐标L1=sqrt((X0-Xe)^2+(Y0-Ye)^2)/2;%两点之间距离的一半L2=sqrt(R^2-L1^2);beta=atan(k2);x01=Xz-L2*cos(beta);y01=Yz-L2*sin(beta);%靠近原点的圆心x02=Xz+L2*cos(beta);y02=Yz+L2*sin(beta);%远离原点的圆心endif(NorF==1)%判断圆心位置if((x01^2+y01^2-x02^2-y02^2)=0)x0=x01;y0=y01;elsex0=x02;y0=y02;endelseif((x01^2+y01^2-x02^2-y02^2)=0)x0=x02;y0=y02;elsex0=x01;y0=y01;endend%画基准圆alpha=0:pi/20:2*pi;xx=R*cos(alpha)+x0;yy=R*sin(alpha)+y0;plot(xx,yy,'g:');holdon;axisequal;Xm=X0;Ym=Y0;%NXY=(abs(Xe-X0)+abs(Ye-Y0))/h;step=0;Fm=0;while((Xm-Xe)^2+(Ym-Ye)^2h*h/2|(step==0&mark==0))if((Xm-x0)0&(Ym-y0)=0)XOY=1;%判断动点所在象限endif((Xm-x0)=0&(Ym-y0)0)XOY=2;endif((Xm-x0)0&(Ym-y0)=0)XOY=3;endif((Xm-x0)=0&(Ym-y0)0)XOY=4;endswitchXOYcase1if(SorN==1)if(Fm=0)x1=[Xm,Xm];y1=[Ym,Ym-h];elsex1=[Xm,Xm+h];y1=[Ym,Ym];endelseif(Fm=0)x1=[Xm,Xm];y1=[Ym,Ym+h];elsex1=[Xm,Xm-h];y1=[Ym,Ym];endendcase2if(SorN==1)if(Fm=0)x1=[Xm,Xm+h];y1=[Ym,Ym];elsex1=[Xm,Xm];y1=[Ym,Ym+h];endelseif(Fm0)x1=[Xm,Xm];y1=[Ym,Ym-h];elsex1=[Xm,Xm-h];y1=[Ym,Ym];endendcase3if(SorN==1)if(Fm=0)x1=[Xm,Xm];y1=[Ym,Ym+h];elsex1=[Xm,Xm-h];y1=[Ym,Ym];endelseif(Fm0)x1=[Xm,Xm+h];y1=[Ym,Ym];elsex1=[Xm,Xm];y1=[Ym,Ym-h];endendcase4if(SorN==1)if(Fm=0)x1=[Xm,Xm-h];y1=[Ym,Ym];elsex1=[Xm,Xm];y1=[Ym,Ym-h];endelseif(Fm0)x1=[Xm,Xm];y1=[Ym,Ym+h];elsex1=[Xm,Xm+h];y1=[Ym,Ym];endendendstep=step+1;plot(x1,y1,'r-');%由此点和前一点坐标组成的2个向量画直线Xm=x1(2);%保存此点坐标供下次作图和比较时使用Ym=y1(2);Fm=(Xm-x0)^2+(Ym-y0)^2-R^2;holdon;text((x1(1)+x1(2))/2,(y1(1)+y1(2))/2,[num2str(step)])pause(0.5);%延时程序形参为每走一步所用时间endxlabel('X')ylabel('Y')title(['四象限圆弧插补'])holdoff;
本文标题:Matlab圆弧插补程序+郑国安
链接地址:https://www.777doc.com/doc-8281046 .html