资源描述:
《XY工作台四个象限的直线插补程序.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、求助四个象限的直线插补程序2011-5-1621:55最佳答案#include#include/*<--includedforputpixel()*/#include/*<--includedforabs()*/voidcb_line(intx1,inty1,intx2,inty2){intdx,dy,n,k,i,f;intx,y;dx=abs(x2-x1);dy=abs(y2-y1);n=dx+dy;if(x2>=x1){k=y2>=y1?1:
2、4;x=x1;y=y1;}else{k=y2>=y1?2:3;x=x2;y=y2;}putpixel(x,y,1);for(i=0,f=0;i=0)switch(k){case1:putpixel(x++,y,1);f-=dy;break;case2:putpixel(x,y++,1);f-=dx;break;case3:putpixel(x--,y,1);f-=dy;break;case4:putpixel(x,y--,1);f-=dx;break;}elseswitch(k){c
3、ase1:putpixel(x,y++,1);f+=dx;break;case2:putpixel(x--,y,1);f+=dy;break;case3:putpixel(x,y--,1);f+=dx;break;case4:putpixel(x++,y,1);f+=dy;break;}}intmain(){cb_line(0,0,15,20);/*<---youforgot;here*/return0;/*betterreturnsomething*/}语言直线插补程序,高手请进采纳后追加20分2010-
4、11-822:39提问者:1004459133夜曲
5、悬赏分:5
6、浏览次数:725次我用c语言写了一个直线插补程序,用来模拟数控机床的直线插补运动,但是在c-free软件中总是无法运行,提示头文件错误,那位高手帮忙解决一下,(在我的基础上修改)请尽量详细说明,指导我把这个问题解决就算被采纳。具体程序如下:#include#include#include"conio.h"voidmain(){floatx1,y1,x2,y2,n1,n2,xe,ye,f,n;printf
7、("请输入直线的第一个点");scanf("%f,%f",&x1,&y1);printf("请输入直线的第二个点");scanf("%f,%f",x2,y2);/*判断需要走的步数*/n1=(y2-y1)>=0?(y2-y1)*100:(y1-y2)*100;n2=(x2-x1)>=0?(x2-x1)*100:(y2-y1)*100;n=n1+n2;/*第一象限内的直线*/if((x2>=x1)&&(y2>=y1)){intgdriver=DETECT,gmode;intx,y;initgr
8、aph(&gdriver,&gmode,"");cleardevice();xe=x2-x1;ye=y2-y1;moveto(x1,y1);for(f=0;n>0;n--){if(f>=0){linerel(0.01,0);f-=ye;}else{linerel(0,0.01);f+=xe;}}/*第二象限内的直线*/if((x2>=x1)&&(y2>=y1)){intgdriver=DETECT,gmode;intx,y;initgraph(&gdriver,&gmode,"");cleardevice(
9、);xe=x2-x1;ye=y2-y1;moveto(x1,y1);for(f=0;n>0;n--){if(f>=0){linerel(0.01,0);f-=ye;}else{linerel(0,0.01);f+=xe;}}/*第三象限内的直线*/if((x2y1)){intgdriver=DETECT,gmode;intx,y;initgraph(&gdriver,&gmode,"");cleardevice();xe=x2-x1;ye=y2-y1;moveto(x1,y1);for(
10、f=0;n>0;n--){if(f>=0){linerel(0.01,0);f-=ye;}else{linerel(0,-0.01);f+=xe;}}/*第四象限内的直线*/if((x2