Group a Assignment 2 Cohen-clipping-Algo
Group a Assignment 2 Cohen-clipping-Algo
Group a Assignment 2 Cohen-clipping-Algo
Problem Statement: Write C++ program to implement Cohen Southerland line clipping
algorithm
Pre-requisite
1. Basic programming skills of C++
2. 64-bit Open source Linux
3. Open Source C++ Programming tool like G++/GCC
Objective :
Theory:
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.
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.
Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)
(a) If bit 1 is "1" line intersects with left boundary of rectangle window
y3=y1+m(x-X1)
where X = Xwmin
where Xwminis the minimum value of X co-ordinate of window