计算机图形学实验

#include\

#define LEFT 1 #define RIGHT 2 #define BOTTOM 4 #define TOP 8

int x1=60,y1=60,x2=200,y2=200,x3=200,y3=300,xl=30,xr=100,yb=100,yt=20; int encode(int x,int y,int*code) {

int c; c=0; if(xxr) c=RIGHT; if(y>yb)

c=BOTTOM; }

else if(y

if(x==xl||x==xr||y==yt||y==yb) c=0; *code=c;

C_S_LINECLIP(x1,y1,x2,y2,x3,y3,xl,xr,yb,yt) {

int x,y,code1,code2,code3,code; encode(x1,y1,&code1); encode(x2,y2,&code2); encode(x3,y3,&code3); while(code1!=0||code2!=0) {

if(code1&code2!=0) return; code=code1; if(code1==0) code=code2; if((LEFT&code)!=0) { x=x1;

y=y1+(long)(y2-y1)*(xl-x1)/(x2-x1); }

else if((RIGHT&code)!=0) { x=xr;

y=y1+(long)(y2-y1)*(xr-x1/x2-x1); }

else if((BOTTOM&code)!=0) { y=yb;

x=x1+(long)(x2-x1)*(yb-y1)/(y2-y1); }

else if((TOP&code)!=0) { y=yt;

x=x1+(long)(x2-x1)*(yt-y1)/(y2-y1); }

if(code==code1) {x1=x; y1=y;

encode(x,y,&code1); } else {x2=x; y2=y;

encode(x,y,&code2); } }

while(code1!=0||code3!=0) {

if(code1&code3!=0) return; code=code1; if(code1==0) code=code3; if((LEFT&code)!=0) { x=x1;

y=y1+(long)(y3-y1)*(xl-x1)/(x3-x1); }

else if((RIGHT&code)!=0) { x=xr;

y=y1+(long)(y3-y1)*(xr-x1/x3-x1); }

else if((BOTTOM&code)!=0) { y=yb;

x=x1+(long)(x3-x1)*(yb-y1)/(y3-y1); }

else if((TOP&code)!=0)

{ y=yt;

x=x1+(long)(x3-x1)*(yt-y1)/(y3-y1); }

if(code==code1) {x1=x; y1=y;

encode(x,y,&code1); } else {x3=x; y3=y;

encode(x,y,&code3); } }

while(code3!=0||code2!=0) {

if(code3&code2!=0) return; code=code3; if(code3==0) code=code2;

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4