CG EXP-7
CG EXP-7
Experiment No.: 7:
Roll Number: 19
Date of Performance:19/09/2024
Date of Submission:26/09/2024
Evaluation
Performance Indicator Max. Marks Marks Obtained
Performance 5
Understanding 5
Journal work and timely submission. 10
Total 20
Checked by
Signature :
Date :
In the algorithm, first of all, it is detected whether line lies inside the screen
or it is outside the screen. All lines come under any one of the following
categories:
1. Visible
2. Not Visible
3. Clipping Case
1. Visible: If a line lies within the window, i.e., both endpoints of the line
lies within the window. A line is visible and will be displayed as it is.
2. Not Visible: If a line lies outside the window it will be invisible and
rejected. Such lines will not display. If any one of the following
inequalities is satisfied, then the line is considered invisible. Let A (x1,y2)
and B (x2,y2) are endpoints of line.
xmin,xmax are coordinates of the window.
ymin,ymax are also coordinates of the window.
x1>xmax
x2>xmax
y1>ymax
y2>ymax
x1<xmin
x2<xmin
y1<ymin
y2<ymin
3. Clipping Case: If the line is neither visible case nor invisible case. It
is considered to be clipped case. First of all, the category of a line is found
based on nine regions given below. All nine regions are assigned codes.
Each code is of 4 bits. If both endpoints of the line have end bits zero, then
the line is considered to be visible.
The center area is having the code, 0000, i.e., region 5 is considered a
rectangle window.
Conditions
Case I:
Bitwise OR of region of 2 endpoints of line = 0000 → Line lies inside the
window
Case II :
1. Completely invisible
Bitwise OR ≠ 0000
1. Partially Visible
Bitwise AND ≠ 0000
Completely invisible
Case III :
Partially Visible
1. Choose the endpoints of the line.
2. Find the intersection point with the window.
3. Replace the endpoints with the intersection point.
Program #include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<math.h>
void main() {
int a[4], b[4];
float m, xnew, ynew;
float x1 = 100, y1 = 100, xh = 300, yh = 300, xa =
10, ya = 200, xb = 250, yb = 150;
int gd = DETECT, gm;
getch();
getch();
closegraph();
}
Output