How to know the benefits of easily Easy Learning Line clipping using cohen Sutherland Algorithm

 Line clipping using cohen sutherhand Algorithm

“On this page you will find about the benefits of easily Easy Learning Line clipping Algorithm . Line clipping algorithm a major role in IT department and in the Computer professional . We will explain why easily Easy Learning Computer Hardware is important, how to Learning Computer Hardware, and how to learn it if you're unfamiliar with Line clipping Algorithm . "

What is Line clipping algorithm and why is it important? 

Line used in go for easy IT department.Therefore, in everyday learning , Line clippingis added to the life help the go to IT profesional job.On this page we have explained in detail in writing what is the solution to How to learning Easy Line algorithm .

Why is Line algorithm impotent?

Do not worry if you have any doest not know to computer knowledge while getting job and go to IT field.It will be more effective if we use the tips mentioned. It will be more effective if we use the tips mentioned. The number of sizes to use in the notes is specifically given.

Line clippimg algorithm and Reminders:

You mentioned similar tips on another page about Computer Hardware.

How to know the benefits of easily Easy Learning Line clipping Algorithm :

Aim:

To write a program in C to clip a line in using cohen Sutherland line clipping algorithm.

Algorithm:

1.start the program

2.obtain the coordinates of the clipping window x min, ymin, xmax, ymax.

3.Get the coordinates of the line xa,ya,xb,yb

4. Region codes are assignd to the line and point according to relative position with repeat to the clipping rectangle 

5. The region codes of the line end points which passes through the clipping rectangle are ANDED 

6. If the result is zero (0000), them the line as completely inside the window if the result as one (1,1,1,1) then the line is- entrly at side the windows 

7.The point at which the line interest the clipping windows can be obtained using the equation x’<=x, +M(y-y1)and y’<=y1+m(x-x1)

8.using the Intersaction point the point of the outside the clipping windows one clipped off.

9. stop the program 


Program :

 #include<stdio.h> 

#include<conio.h>

#include<graphics.h>

#include<math.h>

void main()

(

Int gd =DETECT, gm;

float xmin,ymin,xmax,y,max,x1,y1,x2,y2,x,y,slope,y11,yll,yr1,xa1,xb1;

float xa2,xr2;

float y12,xb2,x12,xe,ye,yr2;

int 11,r1,b1,a1,12,r2,b2,a2,1,r,b,a;

initgraph(&gd,&gm,””);

clscr();

printf(“enter the coordinates for rectagle:”);

scanf(“%f\n%f\n%f\n%f”, &xmin,&ymin,&xmax,&ymax);

printf(“enter the coordinates for line :”);

scanf(“%f\n%f\n%f\n%f”,&x1,&y1,&x2,&y2);

setcolor (3);

rectangle(xmin,ymin,xmax,ymax);

line(x1,y1,x2,y2);

if((x1-xmin)<0)

11=1;

else

11=0;

If((xmax-x1)<0)

r1=1;

else

r1=1;

else

r1=0;

if((ymax-y1)<0)

b1=1;

else

b1=0;

if((y1-ymin)<0)

a1=1;

else

a1=0;

if((x2-xmin)<0)

12=1;

else

12=0;

if((xmax-x2)<0)

r2=1;

else

r2=1;

else

r2=1;

else

r2=0;

if((ymax-y2)<0)

b2=1;

else

b2=0;

if((y2-ymin)<0)

a2=1;

else

a2=0;

if((11*12)==0)

1=0;

else

1=1;

if((r1*r2)==0)

r=0;

else

r=1;

if((b1*b2)==0)

b=0;

else

b=1;

if((a1*a2)==0)

a=0;

else

a=1;

if((a==0)&&(b==0)&&(1==0)&&(r==0))

{

slope=(y2-y1)/(x2-x1);

if(y1<ymin)

{

xa1=x1;

xb2=x2;

}

else 

xa1=x1+(ymin-y1)/slope;

gerch();

else

xa1=x1+(ymin-y1)/slope;

gerch();

cleardevice();

rectangle(xmin,ymin,xmax,ymay);

line(xa1,ymin,x2,y3);

xe=xa1;

ye=ymin;

}

if(x1<xmin)

{

y11=y1+slope*(xmin-x1);

getch();

cleardevice();

rectangle(xmin,ymin,xmax,ymax);

line(xmin,y11,x2,y2);

xe=xmin;

ye=y11;

}

if(x1>xmax)

{

yr1=y1+slope*(xmax-x1);

getch();

cleardevice();

rectangle(xmin,ymin,xmax,ymax);

line(xmax,yr1,x2,y2);

a2=1;

else

a2=0;

if((11*12)==0)

1=0;

else

1=1;

if((r1*r2)==0)

r=0;

else

r=1;

if((b1*b2)==0)

b=0;

else

b=1;

if((a1*a2)==0)

a=0;

else

a=1;

if((a==0)&&(b==0)&&(1==0)&&(r==))

{

slope =(y2-y1)/(x2-x1);

if(y1<ymin)

{

xa1=x1;

xb2=x2;

}

else 

xa1=x1+(ymin-y1)/slope;

getch();

cleardevice();

rectangle(xmin,ymin,.xmax,ymax);

line(xa1,ymin,x2,y2);

xe=xa1;

ye=ymin;

}

if(x1<xmin)

{

y11=y1+slope*(xmin-x1);

getch();

cleardevice();

rectangle(xmin,ymin,xmax,ymax);

line(xmin,y11,x2,y2);

xe=xmin;

ye=y11;

}

if(x1>xmax)

{

yr1=y1+slope*(xmax-x1);

getch();

cleardevice();

rectagle(xmin,yr1,x2 ,y2);

line(xmax,yr1,x2,y2);

xe=xmax;

ye=yr1;

}

if (y1>ymax)

{

xb1=x1+(ymax-y1)/slope;

getch();

cleardevice();

rectangle(xmin,ymin,xmax,ymax);

line(xb1,ymax,x2,y2);

xe=xb1;

ye=ymax;

}

if(y2<ymin)

{

if((x2-x1)==0)

{

xa2=x2;xb2=x2;

}

else

xa2=x2+(ymin-y2)/slope;

getch();

cleardevice();

rectagle(xmin,ymin,xminx,ymax);

line(xa2,ymin,xe,ye);

}

if(x2>xmax)

{

yr2=y2+slope*(xmax-x2);

getch(); cleardevice();

rectagle(xmin,ymin,xmax,ymax);

line(xmax,yr2,xe,ye);

}

if(x2<xmin)

{

y12=y2+slope*(xmin-x2); getch();

cleardevice();

rectangle(xmin,ymin,xmax,ymax);

line(xmin,y12,xe,ye);

}

if(y2>ymax)

{

if((x2-x1)==0)

xb2=x2;

else

xb2=x2+(ymax-y2)/slope;

getch();  cleardevice();

rectangle(xmin,ymin,xmax,ymax);

line(xb2,ymax,xe,ye);

}

getch();

closegraph();

closegraph();

}


Output:

Enter the coordinates for rectangle: 200 200 300 300 

Enter the coordinates for line: 150 200 350 450







Awesome information about Line clipping algorithm was given above in this wonderful new blog of yours. It provided information on types, references, pictures, etc.

Comments