| written 6.4 years ago by |
It is performed by using the line clipping algorithm. The line clipping algorithms are:
Cohen Sutherland Line Clipping Algorithm
Midpoint Subdivision Line Clipping Algorithm
Liang-Barsky Line Clipping Algorithm
Cohen Sutherland Line Clipping Algorithm:
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:
Visible
Not Visible
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\left(x_{1}, y_{2}\right)$ and $B\left(x_{2}, y_{2}\right)$ are endpoints of line.
$x_{\min }, x_{\max }$ are x coordinates of the window.
$y_{\min }, y_{\max }$ are y coordinates of the window.
$\mathrm{X}_{1}\gt\mathrm{X}_{\max }$ and $\mathrm{x}_{2}\gt\mathrm{X}_{\max }$
$\mathrm{y}_{1}\gt\mathrm{y}_{\max }$ and $\mathrm{y}_{2}\gt\mathrm{y}_{\max }$
$\mathrm{x}_{1}\lt\mathrm{x}_{\min }$ and $\mathrm{x}_{2}\lt\mathrm{x}_{\min }$
$\mathrm{y}_{1}\lt\mathrm{y}_{\min }$ and $\mathrm{y}_{2}\lt\mathrm{y}_{\min }$
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.
Following figure show lines of various types,

Line AB is the visible case
Line OP is an invisible case.
Line PQ is an invisible line
Line IJ are clipping candidates
Line MN are clipping candidate
Line CD are clipping candidate
Advantage of Cohen Sutherland Line Clipping
It calculates end-points very quickly and rejects and accepts lines quickly.
It can clip pictures much large than screen size.
Algorithm of Cohen Sutherland Line Clipping:
Step1: Calculate positions of both endpoints of the line
Step2: Perform OR operation on both of these end-points
Step3:
If the OR operation gives 0000
else
{
Perform AND operation on both endpoints
If And ≠ 0000, then the line is invisible
else And=0000, Line is considered the clipped case
}
Step4:
If a line is clipped case, find an intersection with boundaries of the window $\mathrm{m}=\left(\mathrm{y}_{2}-\mathrm{y}_{1}\right) /\left(\mathrm{x}_{2}-\mathrm{x}_{1}\right)$
(a) If bit 1 is " $1^{\prime \prime}$ line intersects with the top boundary
$$ x_{3}=x_{1}+\left(y-y_{1}\right) / m $$
where $y=y_{\text {wmax }}$
$Y_{\text{wmax}}$ is the maximum value of Y co-ordinate of the window.
(b) If bit 2 is " $1^{\prime \prime}$ line intersects with the top boundary
$$ x_{3}=x_{1}+\left(y-y_{1}\right) / m $$
where $y=y_{\text {wmin }}$
$Y_{\text{wmin}}$ is the minimum value of Y co-ordinate of the window
(c) If bit 3 is " $1^{\prime \prime}$ line intersect with right boundary $$ \begin{array}{l}{y_{3}=y_{1}+m\left(x-x_{1}\right)}\end{array} $$
where $\mathrm{x}=\mathrm{x}_{\mathrm{wmax}}$
where $\mathrm{x}$ more is maximum value of $\mathrm{x}$ co-ordinate of the window.
(d) If bit 4 is " $1^{\prime \prime}$ line intersect with left boundary of rectangle window
$$ \begin{array}{l}{y_{3}=y_{1}+m\left(x-x_{1}\right)}\end{array} $$
where $\mathrm{x}=\mathrm{x}_{\mathrm{wmin}}$
where $\mathrm{x}_{wmin}$ is minimum value of $\mathrm{x}$ co-ordinate of the window.

and 4 others joined a min ago.