资源描述:
《直线插补与圆弧插补程序设计》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、直线插补与圆弧插补程序设计一.直线插补1.直线插补程序流程图置FM=0输入XE、YE、XOY、NXYFM≥0?XOR=1或4?XOR=1或2?ZF=1ZF=2ZF=3ZF=4FM=FM-YEFM=FM+YE调用走步控制程序NXY=NXY-1NXY=0?开始结束YNYNYNYN直线插补程序流程图2.直线插补程序设计#include #include #include void cb_line(int x1, int y1, int x2, int y2){ int dx, dy, n, k,
2、i, f; int x, y; dx = abs(x2-x1); dy = abs(y2-y1); n = dx + dy; if (x2 >= x1) { k = y2 >= y1 ? 1: 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 < n; i++)
3、 if (f >= 0) switch (k) { case 1: putpixel(x++, y, 1); f -= dy; break; case 2: putpixel(x, y++, 1); f -= dx; break; case 3: putp
4、ixel(x--, y, 1); f -= dy; break; case 4:putpixel(x, y--, 1); f -= dx; break; } else switch (k) { case 1: putpixel(x, y++, 1); f += dx;
5、 break; case 2: putpixel(x--, y, 1); f += dy; break; case 3: putpixel(x, y--, 1); f += dx; break; case 4: putpixel(x++, y, 1);
6、 f += dy; break; }}int main(){ cb_line(0,0,15,20); /* <--- you forgot ; here */ return 0; }二.圆弧插补2.1.四象限圆弧插补程序流程图ZF=4ZF=4RNS=1,6?RNS=2,5?输入X0、Y0、NXY、RNS置FM=0、XM=X0、YM=Y0RNS=1,2,6,8?FM≥0?FM≥0?RNS=2,7?RNS=1,8?ZF=3ZF=2ZF=1ZF=1ZF=2ZF=3FM=FM-2XM=1FM=FM+
7、2XM=1FM=FM-2YM=1FM=FM+2YM+1YM=YM+1YM=XM-1YM=XM+1YM=YM-1调用走步控制程序NXY=NXY-1NXY=0?结束NNYNYYNNYNYNYNYNNNN2.1四象限圆弧插补程序设计#include#includeintArcXY(doubledfx0,doubledfy0,doubledfrx,doubledfry,intangle);intsymbol(doublenumber);main(){ArcXY(0,0,-3,5,360);getch();}intArcXY(doubl
8、edfx0,doubledfy0,do