0% found this document useful (0 votes)
6 views3 pages

CG 7

Uploaded by

muskan872b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

CG 7

Uploaded by

muskan872b
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 7

Student Name: Ujjwal Pal UID: 22BCS10793


Branch: BE-CSE Section/Group: 601-A
Semester : 6th Date of Performance: 13-03-2025
Subject Name: Computer Graphics with Lab. Subject Code: 22CSH-352

1. Aim:
Evaluate the 4-bit region code for line endpoints and determine whether the
line lies inside or outside the screen.

2. Objective:
To calculate and display the 4-bit region code for line endpoints and
determine whether the line lies within the screen boundaries.

Implementation/Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>

void main()

{
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
int xmax=400,
ymax=300,
xmin=200,
ymin=150;
line(xmin,0,xmin,getmaxy());
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

line(xmax,0,xmax,getmaxy());
line(0,ymax,getmaxx(),ymax);
line(0,ymin,getmaxx(),ymin);
cout<<"Enter the endpoints of the line :";

int x[2],y[2],num[2];
cin>>x[0]>>y[0]>>x[1]>>y[1];
line(x[0],y[0],x[1],y[1]);
for(int i=0;i<2;i++)
{
int bit1=0,bit2=0,bit3=0,bit4=0;
if(y[i]<ymin) bit1=1;
if(y[i]>ymax) bit2=1;
if(x[i]>xmax) bit3=1;
if(x[i]<xmin)
bit4=1;

cout<<"For"<<i<<"th endpoint region code is


:"<<bit1<<bit2<<bit3<<bit4<<endl;

num[i]=bit4*1+bit3*2+bit2*4+bit1*8;
} if(!(num[0]|num[1]))
cout<<"Line is completely in window";
else if(!(num[0]&num[1])
cout<<"Line is required to be
clipped"; else
cout<<"Line is off the window";
getch();
}

5. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

6. Learning Outcome:
a) Implementation of Cohen-Sutherland Algorithm – Learned how to determine the
visibility of a line using region codes and logical operations.

b) Bitwise Operations in Clipping – Explored how bitwise AND (&) and OR (|)
operations help in efficient line clipping decisions.

c) Dynamic Graphics Rendering – Understood how to visualize computational


geometry problems using Turbo C++ graphics functions.

d) Real-World Application in Computer Graphics – Gained insights into how clipping


algorithms optimize rendering in CAD software and gaming engines.

You might also like