/***** IT TELLS UPTO THE REGION CODES AND IDENTIFIES THE POINTS TO BE CLIPPED ****/
int main()
{
int bit[4],bit1[4],temp[4];
char str[4],str1[4],str2[4];int i;
char temp5[4]={0000};
int choice3,choice4;
int check=0,choice1,choice2;
int x1,y1,x2,y2,xmin,ymin,xmax,ymax;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("\n\n\t\t --------------CAUTION --------------");
printf("\n\t\t *FINALLY CLIPPING REQUIRED MEANS* WE HAVE TO\n\t\t\t DO CLIPPING FOR THAT POINT --\n\n");
printf("\n\n\t\t **** Enter Line Cooridnates ****");
printf("\n\n Enter x1:");
scanf("%d",&x1);
printf("\n\n Enter y1:");
scanf("%d",&y1);
printf("\n\n Enter x2:");
scanf("%d",&x2);
printf("\n\n Enter y2:");
scanf("%d",&y2);
printf("\n\n\t\t **** Enter window coordinates ****");
printf("\n\n Enter xmin:");
scanf("%d",&xmin);
printf("\n\n Enter ymin:");
scanf("%d",&ymin);
printf("\n\n Enter xmax:");
scanf("%d",&xmax);
printf("\n\n Enter ymax:");
scanf("%d",&ymax);
outtextxy(700,200,"ORIGINAL LINE");
line(x1,y1,x2,y2);
outtextxy(700,200,"ORIGINAL LINE");
rectangle(xmin,ymin,xmax,ymax);
if((x1 &&x2)>xmax || ((x1 && x2)<xmin))
{
if((y1 &&y2)>ymax || ((y1 && y2)<ymin))
printf("\n\n do clipping");
bit[0]= ymax-y1;
printf("\n\n%d",bit[0]);
if(bit[0]<0)
{
bit[0]=1; }
else
{
bit[0]=0;
}
bit[1]= y1-ymin;
printf("\n\n%d",bit[1]);
if(bit[1]<0)
{
bit[1]=1; }
else
{
bit[1]=0;
}
bit[2]=xmax-x1;
printf("\n\n%d",bit[2]);
if(bit[2]<0)
{
bit[2]=1; }
else
{
bit[2]=0;
}
bit[3]=x1-xmin;
printf("\n\n%d",bit[3]);
if(bit[3]<0)
{
bit[3]=1; }
else
{
bit[3]=0;
}
bit1[0]=ymax-y2;
printf("\n\n%d",bit[0]);
if(bit1[0]<0)
{
bit1[0]=1; }
else
{
bit1[0]=0;
}
bit1[1]=y2-ymin;
printf("\n\n%d",bit1[1]);
if(bit1[1]<0)
{
bit1[1]=1; }
else
{
bit1[1]=0;
}
bit1[2]=xmax-x2;
printf("\n\n%d",bit1[2]);
if(bit1[2]<0)
{
bit1[2]=1; }
else
{
bit1[2]=0;
}
bit1[3]=x2-xmin;
printf("\n\n%d",bit1[3]);
if(bit1[3]<0)
{
bit1[3]=1; }
else
{
bit1[3]=0;
}
// int str[4];
for(i=0;i<4;i++)
{
str[i]=0;
}
printf("\n\n\t\t ----- Region codes for point 1 -------\n\n");
for(i=0;i<4;i++)
{
str[i]=bit[i];
printf("\nregion code for point1 bit[%d]= %d",i,str[i]);
}
// int str1[4];
for(i=0;i<4;i++)
{
if( str[i]!=temp5[i])
{
check=1;
printf("\n\n FINally clipping required");
choice1=1;
choice3=1;
}
else
{
printf("\n\n no clipping required");
}
}
for(i=0;i<4;i++)
{
str1[i]=0;
}
printf("\n\n\t\t ----- Region codes for point 2 -------\n\n");
for(i=0;i<4;i++)
{
str1[i]=bit1[i];
printf("\n region code for point2 (bit[%d])=%d",i, str1[i]);
}
// int str2[4];
for(i=0;i<4;i++)
{
if( str1[i]!=temp5[i])
{
check=1;
printf("\n\n clipping required");
choice2=1;
choice4=1;
}
else
{
printf("\n\n no clipping required");
//goto x1;
}
}
}
else
{
printf("\n\n\n no clipping is required");
}
getch();
closegraph();
return 0;
}
int main()
{
int bit[4],bit1[4],temp[4];
char str[4],str1[4],str2[4];int i;
char temp5[4]={0000};
int choice3,choice4;
int check=0,choice1,choice2;
int x1,y1,x2,y2,xmin,ymin,xmax,ymax;
int gd=DETECT,gm;
initgraph(&gd,&gm," ");
printf("\n\n\t\t --------------CAUTION --------------");
printf("\n\t\t *FINALLY CLIPPING REQUIRED MEANS* WE HAVE TO\n\t\t\t DO CLIPPING FOR THAT POINT --\n\n");
printf("\n\n\t\t **** Enter Line Cooridnates ****");
printf("\n\n Enter x1:");
scanf("%d",&x1);
printf("\n\n Enter y1:");
scanf("%d",&y1);
printf("\n\n Enter x2:");
scanf("%d",&x2);
printf("\n\n Enter y2:");
scanf("%d",&y2);
printf("\n\n\t\t **** Enter window coordinates ****");
printf("\n\n Enter xmin:");
scanf("%d",&xmin);
printf("\n\n Enter ymin:");
scanf("%d",&ymin);
printf("\n\n Enter xmax:");
scanf("%d",&xmax);
printf("\n\n Enter ymax:");
scanf("%d",&ymax);
outtextxy(700,200,"ORIGINAL LINE");
line(x1,y1,x2,y2);
outtextxy(700,200,"ORIGINAL LINE");
rectangle(xmin,ymin,xmax,ymax);
if((x1 &&x2)>xmax || ((x1 && x2)<xmin))
{
if((y1 &&y2)>ymax || ((y1 && y2)<ymin))
printf("\n\n do clipping");
bit[0]= ymax-y1;
printf("\n\n%d",bit[0]);
if(bit[0]<0)
{
bit[0]=1; }
else
{
bit[0]=0;
}
bit[1]= y1-ymin;
printf("\n\n%d",bit[1]);
if(bit[1]<0)
{
bit[1]=1; }
else
{
bit[1]=0;
}
bit[2]=xmax-x1;
printf("\n\n%d",bit[2]);
if(bit[2]<0)
{
bit[2]=1; }
else
{
bit[2]=0;
}
bit[3]=x1-xmin;
printf("\n\n%d",bit[3]);
if(bit[3]<0)
{
bit[3]=1; }
else
{
bit[3]=0;
}
bit1[0]=ymax-y2;
printf("\n\n%d",bit[0]);
if(bit1[0]<0)
{
bit1[0]=1; }
else
{
bit1[0]=0;
}
bit1[1]=y2-ymin;
printf("\n\n%d",bit1[1]);
if(bit1[1]<0)
{
bit1[1]=1; }
else
{
bit1[1]=0;
}
bit1[2]=xmax-x2;
printf("\n\n%d",bit1[2]);
if(bit1[2]<0)
{
bit1[2]=1; }
else
{
bit1[2]=0;
}
bit1[3]=x2-xmin;
printf("\n\n%d",bit1[3]);
if(bit1[3]<0)
{
bit1[3]=1; }
else
{
bit1[3]=0;
}
// int str[4];
for(i=0;i<4;i++)
{
str[i]=0;
}
printf("\n\n\t\t ----- Region codes for point 1 -------\n\n");
for(i=0;i<4;i++)
{
str[i]=bit[i];
printf("\nregion code for point1 bit[%d]= %d",i,str[i]);
}
// int str1[4];
for(i=0;i<4;i++)
{
if( str[i]!=temp5[i])
{
check=1;
printf("\n\n FINally clipping required");
choice1=1;
choice3=1;
}
else
{
printf("\n\n no clipping required");
}
}
for(i=0;i<4;i++)
{
str1[i]=0;
}
printf("\n\n\t\t ----- Region codes for point 2 -------\n\n");
for(i=0;i<4;i++)
{
str1[i]=bit1[i];
printf("\n region code for point2 (bit[%d])=%d",i, str1[i]);
}
// int str2[4];
for(i=0;i<4;i++)
{
if( str1[i]!=temp5[i])
{
check=1;
printf("\n\n clipping required");
choice2=1;
choice4=1;
}
else
{
printf("\n\n no clipping required");
//goto x1;
}
}
}
else
{
printf("\n\n\n no clipping is required");
}
getch();
closegraph();
return 0;
}
No comments:
Post a Comment