1、。/*sutherland_cohen裁剪算法 */#define LEFT 1#define RIGHT 2#define BOTTOM 4#define TOP 8#define XL 150#define XR 350#define YB 150#define YT 300#include math.h#includegraphics.h#include conio.h#include stdio.hvoid initialize(void) int graphdriver; int graphmode; int errorcode; graphdriver=DETECT; initgr
2、aph(&graphdriver,&graphmode,d:tc); errorcode=graphresult();if (errorcode!=0)printf(graphics system erreor: %s,grapherrormsg(errorcode);-可编辑修改 -。exit(1);main() initialize( );setcolor(12);line(XL,YT,XR,YT);line(XL,YB,XR,YB);line(XL,YT,XL,YB);line(XR,YT,XR,YB);setcolor(14);draw_ett();getch();closegraph
3、();encode(x,y,code)int x,y; int *code; int c; c=0;if(xXR) c=c|RIGHT; if(yYT) c=c|TOP; *code=c;-可编辑修改 -。return;draw_ett()int x1,x2,y1,y2,x,y;int code1,code2,code;x1=50;y1=250;x2=400;y2=300;setcolor(1);line(x1,y1,x2,y2);encode(x1,y1,&code1);encode(x2,y2,&code2);while(code1!=0)|(code2!=0)if(code1&code2
4、)!=0) return;code=code1;if(code1=0) code=code2;if(LEFT&code)!=0)x=XL;y=y1+(y2-y1)*(XL-x1)/(x2-x1);elseif(RIGHT&code)!=0)-可编辑修改 -。x=XR;y=y1+(y2-y1)*(XR-x1)/(x2-x1);else if(BOTTOM&code)!=0)y=YB;x=x1+(x2-x1)*(YB-y1)/(y2-y1);else if(TOP&code)!=0)y=YT;x=x1+(x2-x1)*(YT-y1)/(y2-y1);if(code=code1)x1=x;y1=y;
5、encode(x,y,&code1);else x2=x;y2=y;encode(x,y,&code2);setcolor(14);line(x1,y1,x2,y2);-可编辑修改 -。return;#define LEFT 1#define RIGHT 2#define BOTTOM 4#define TOP 8#define XL 150#define XR 350#define YB 150#define YT 300#include math.h#includegraphics.h#include conio.h#include stdio.hvoid initialize(void)
6、 int graphdriver; int graphmode; int errorcode;-可编辑修改 -。graphdriver=DETECT;initgraph(&graphdriver,&graphmode,d:tc);errorcode=graphresult();if (errorcode!=0)printf(graphics system erreor: %s,grapherrormsg(errorcode);exit(1);main()int x1,y1,x2,y2,xx,yy,xxx,yyy;initialize();scanf(%d,%d,%d,%d,&x1,&y1,&x
7、2,&y2);cleardevice();xx=0;yy=0;xxx=0;yyy=0;setcolor(12);line(XL,YT,XR,YT);line(XL,YB,XR,YB);line(XL,YT,XL,YB);line(XR,YT,XR,YB);setcolor(14);draw_ett(x1,y1,x2,y2,&xx,&yy);draw_ett(x2,y2,xx,yy,&xxx,&yyy);line(xx,yy,xxx,yyy);-可编辑修改 -。getch();closegraph();encode(x,y,code)int x,y; int *code; int c; c=0;
8、if(xXR) c=c|RIGHT; if(yYT) c=c|TOP; *code=c;return;draw_ett(x1,y1,x2,y2,x,y) int x1,x2,y1,y2;int *x,*y;int code1,code2,code; int xx,yy;long d,d1,d2; encode(x1,y1,&code1); encode(x2,y2,&code2);-可编辑修改 -。if(code2=0)xx=x2;yy=y2;*x=xx; *y=yy;return;if(code1&code2)!=0) return;do xx=(x1+x2)/2;yy=(y1+y2)/2;encode(xx,yy,&code);d1=(yy-y1)*(yy-y1);d2=(xx-x1)*(xx-x1);d=sqrt(d1+d2);if(d1);-可编辑修改 -。THANKS !致力为企业和个人提供合同协议,策划案计划书, 学习课件等等打造全网一站式需求欢迎您的下载,资料仅供参考-可编辑修改 -