资源描述:
《数控技术c语言直线、圆弧插补程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、以下是直线差补c语言程序,后面还有圆弧差补,数控老师布置的作业,没办法,自己编的,运行时没问题,保证质量,#include#includemain(){intx,y,x2,y2,dx,dy,n,k,i,f,a;printf("请输入起始点:");scanf("%d%d",&x,&y);printf("请输入终止点:");scanf("%d%d",&x2,&y2);dx=abs(x2-x);dy=abs(y2-y);n=dx+dy;printf("步数n=%d",n);{if(x2>0)if(y2>0)k=1;elsek=4;elsei
2、f(y2>0)k=2;elsek=3;}printf("相限k=%d",k);for(i=0,f=0;i=0){switch(k){case1:x++;printf("%d%d",x,y);f-=dy;continue;case2:y++;printf("%d%d",x,y);f-=dx;continue;case3:x--;printf("%d%d",x,y);f-=dy;continue;case4:y--;printf("%d%d",x,y);f-=dx;continue;}}else{switch(k){case1:y++;pr
3、intf("%d%d",x,y);f+=dx;continue;case2:x--;printf("%d%d",x,y);f+=dy;continue;case3:y--;printf("%d%d",x,y);f+=dx;continue;case4:x++;printf("%d%d",x,y);f+=dy;continue;}}}下面为圆弧差补c语言程序#include"stdio.h"#include"math.h"#include"ctype.h"main(){intX0,Y0,Xe,Ye,a,I,J,Ie,Je,f;printf("请输入圆弧上的两个点:"
4、);scanf("%d%d%d%d",&X0,&Y0,&Xe,&Ye);printf("(X0,Y0)=(%d,%d),(Xe,Ye)=(%d,%d)",X0,Y0,Xe,Ye);printf("请选择圆弧加工方向,逆时针加工请输入1,顺时针加工请输入2");scanf("%d",&a);I=X0,J=Y0,Ie=Xe,Je=Ye,f=0;switch(a){case1:{loop:while((Ie!=I)
5、
6、(Je!=J)){if(I>=0&&J>0){if(f>=0){f=f-2*I+1;I=I-1;printf("f=%dI=%dJ=%d",f,I,J);}els
7、e{f=f+2*J+1;J=J+1;printf("f=%dI=%dJ=%d",f,I,J);}gotoloop;}if(I<0&&J>=0){if(f>=0){f=f-2*J+1;J=J-1;printf("f=%dI=%dJ=%d",f,I,J);}else{f=f-2*I+1;I=I-1;printf("f=%dI=%dJ=%d",f,I,J);}gotoloop;}if(I<=0&&J<0){if(f>=0){f=f+2*I+1;I=I+1;printf("f=%dI=%dJ=%d",f,I,J);}else{f=f-2*J+1;J=J-1;printf(
8、"f=%dI=%dJ=%d",f,I,J);}gotoloop;}if(I>0&&J<=0){if(f>=0){f=f+2*J+1;J=J+1;printf("f=%dI=%dJ=%d",f,I,J);}else{f=f+2*I+1;I=I+1;printf("f=%dI=%dJ=%d",f,I,J);}gotoloop;}}}case2:{loop1:while((Ie!=I)
9、
10、(Je!=J)){if(I>=0&&J>0){if(f>=0){f=f-2*J+1;J=J-1;printf("f=%dI=%dJ=%d",f,I,J);}else{f=f+2*I+1
11、;I=I+1;printf("f=%dI=%dJ=%d",f,I,J);}gotoloop1;}if(I<0&&J>=0){if(f>=0){f=f+2*I+1;I=I+1;printf("f=%dI=%dJ=%d",f,I,J);}else{f=f+2*J+1;J=J+1;printf("f=%dI=%dJ=%d",f,I,J);}gotoloop1;}if(I<=0&&J<0){if(f>=0){f=f+2*J+1;J=J+1;printf("f=%dI=%dJ=