Program /* This program is all about to show only the region code of the line drawn as inputted coordinate. The region code is on the b...
Program
/*
This program is all about to show only the region code of the line drawn as inputted coordinate.
The region code is on the basis of Cohen Sutherland Line Clipping Algorithm.
If the end point of the line drawn lies inside window i.e the rectangle the region code is 0000.
If left of the window region code is 0001.
If right of the window region code is 0010.
If bottom of the window region code is 0100.
If top of the window region code is 1000.
If left-top of the window region code is 1001.
If left-bottom of the window region code is 0101.
If right-top of the window region code is 1010.
If right-bottom of the window region code is 0110.
According to the algorithm the line is clipped only the portion lies inside the window.
Visit daily for updates....
Thank You!!!
*/
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void check(int,int);
void main()
{
int gd=DETECT,gm,x1,x2,y1,y2;
clrscr();
initgraph(&gd,&gm,"..\\bgi");
line(100,0,100,getmaxy());
line(getmaxx()-100,0,getmaxx()-100,getmaxy());
line(0,100,getmaxx(),100);
line(0,getmaxy()-100,getmaxx(),getmaxy()-100);
// outtextxy(getmaxx()/2,getmaxy()/2,"0000");
printf("Program to show region code of two end point of line\nCohen Sutherland Line Clipping Algorithm\n");
printf("Enter coordinates x1,y1,x2,y2 to draw line\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
line(x1,y1,x2,y2);
check(x1,y1);
check(x2,y2);
getch();
}
void check(int x,int y)
{
settextstyle(2,0,0);
if(x<100 && y<100)
outtextxy(x,y,"1001");
else if(x>getmaxx()-100 && y<100)
outtextxy(x,y,"1010");
else if(x<100 && y>getmaxy()-100)
outtextxy(x,y,"0101");
else if(x>getmaxx()-100 && y>getmaxy()-100)
outtextxy(x,y,"0110");
else if(x<100 && y>=100 && y<=getmaxy()-100)
outtextxy(x,y,"0001");
else if(x>getmaxx()-100 && y>=100 && y<=getmaxy()-100)
outtextxy(x,y,"0010");
else if(x>=100 && x<getmaxx()-100 && y<100)
outtextxy(x,y,"1000");
else if(x>=100 && x<getmaxx()-100 && y>getmaxy()-100)
outtextxy(x,y,"0100");
else
outtextxy(x,y,"0000");
}
/*
This program is all about to show only the region code of the line drawn as inputted coordinate.
The region code is on the basis of Cohen Sutherland Line Clipping Algorithm.
If the end point of the line drawn lies inside window i.e the rectangle the region code is 0000.
If left of the window region code is 0001.
If right of the window region code is 0010.
If bottom of the window region code is 0100.
If top of the window region code is 1000.
If left-top of the window region code is 1001.
If left-bottom of the window region code is 0101.
If right-top of the window region code is 1010.
If right-bottom of the window region code is 0110.
According to the algorithm the line is clipped only the portion lies inside the window.
Visit daily for updates....
Thank You!!!
*/
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void check(int,int);
void main()
{
int gd=DETECT,gm,x1,x2,y1,y2;
clrscr();
initgraph(&gd,&gm,"..\\bgi");
line(100,0,100,getmaxy());
line(getmaxx()-100,0,getmaxx()-100,getmaxy());
line(0,100,getmaxx(),100);
line(0,getmaxy()-100,getmaxx(),getmaxy()-100);
// outtextxy(getmaxx()/2,getmaxy()/2,"0000");
printf("Program to show region code of two end point of line\nCohen Sutherland Line Clipping Algorithm\n");
printf("Enter coordinates x1,y1,x2,y2 to draw line\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
line(x1,y1,x2,y2);
check(x1,y1);
check(x2,y2);
getch();
}
void check(int x,int y)
{
settextstyle(2,0,0);
if(x<100 && y<100)
outtextxy(x,y,"1001");
else if(x>getmaxx()-100 && y<100)
outtextxy(x,y,"1010");
else if(x<100 && y>getmaxy()-100)
outtextxy(x,y,"0101");
else if(x>getmaxx()-100 && y>getmaxy()-100)
outtextxy(x,y,"0110");
else if(x<100 && y>=100 && y<=getmaxy()-100)
outtextxy(x,y,"0001");
else if(x>getmaxx()-100 && y>=100 && y<=getmaxy()-100)
outtextxy(x,y,"0010");
else if(x>=100 && x<getmaxx()-100 && y<100)
outtextxy(x,y,"1000");
else if(x>=100 && x<getmaxx()-100 && y>getmaxy()-100)
outtextxy(x,y,"0100");
else
outtextxy(x,y,"0000");
}
COMMENTS