100% found this document useful (2 votes)
4K views2 pages

Line Clipping Using Cyrus-Beck Method

This program uses the Cyrus-Beck line clipping algorithm to clip a line segment to a given rectangular region. It takes user input for the coordinates of the clipping window and line segment. It then calculates parameter values t1 and t2 to determine the intersection points of the line with the clipping window boundaries. If t1 is less than t2, the clipped line segment is drawn from the calculated intersection points.

Uploaded by

Vivek Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
4K views2 pages

Line Clipping Using Cyrus-Beck Method

This program uses the Cyrus-Beck line clipping algorithm to clip a line segment to a given rectangular region. It takes user input for the coordinates of the clipping window and line segment. It then calculates parameter values t1 and t2 to determine the intersection points of the line with the clipping window boundaries. If t1 is less than t2, the clipped line segment is drawn from the calculated intersection points.

Uploaded by

Vivek Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//LINE CLIPPING USING CYRUS-BECK METHOD #include<iostream.h> #include<conio.h> #include<graphics.h> #define round(a) (int(a+0.

5)) float max(float a,float b) { return ((a>b) ? a : b); } float min(float a,float b) { return ((a>b) ? b : a); } void main() { int gdriver=DETECT,gmode; float x,y,xmin,xmax,ymin,ymax,xi,xf,yi,yf,t,t1,t2=1; clrscr(); cout<<"Coordinates of rectangular clip window :\nxmin,ymin :"; cin>>xmin>>ymin; cout<<"xmax,ymax :"; cin>>xmax>>ymax; cout<<"\n\nCoordinates of line to be clipped :\nInitial :"; cin>>xi>>yi; cout<<"Final :"; cin>>xf>>yf; initgraph(&gdriver,&gmode,"C:\\TurboC3\\BGI"); rectangle(xmin,ymax,xmax,ymin); cout<<"\t\tUNCLIPPED LINE"; setcolor(RED); line(round(xi),round(yi),round(xf),round(yf)); getch(); cleardevice(); t=(xmin-xi)/(xf-xi); if(xf>xi) t1=max(t1,t); else t2=min(t2,t); t=(ymax-yi)/(yf-yi); if(yi>yf) t1=max(t1,t); else t2=min(t2,t); t=(xmax-xi)/(xf-xi); if(xi>xf) t1=max(t1,t); else t2=min(t2,t); t=(ymin-yi)/(yf-yi); if(yf>yi) t1=max(t1,t); else

t2=min(t2,t); if(t1<t2) { x=xf; y=yf; xf=xi+t2*(xf-xi); yf=yi+t2*(yf-yi); xi+=t1*(x-xi); yi+=t1*(y-yi); line(round(xi),round(yi),round(xf),round(yf)); } setcolor(WHITE); rectangle(xmin,ymax,xmax,ymin); cout<<"\t\tCLIPPED LINE"; getch(); closegraph(); }

You might also like