14. Clipping - 1
Dated: 13-05-2025
Concept
To protect other portions of the canvas, the graphics primitives are not drawn outside a rectangular boundary called clipping rectangle
.
The default clipping rectangle
is the full screen itself.
Clipping
Point Clipping
We will save a point
\((x, y)\) only if
Line Clipping
If \(u\) is not in this range then the line does not enters the clipping rectangle
.
Solve Simultaneous Equations
Consider 2 end points of a line
.1 If both are inside the clipping rectangle
then it is accepted. If either one or both points are outside, then we need to find if there are any intersections with clipping boundary
and then check for interior points again.
We don't have to touch the infinitely interior points of the line
1 but just its end points.
The Cohen-sutherland Line-clipping Algorithm
Extend the clipping boundaries
so that the screen is divided into 9 sub regions.
The data represented by each bit
in these 4 bits
code, assigned to each sub region, is as follows:
- \(y > y_\text{max}\)
- \(y < y_\text{min}\)
- \(x > x_\text{max}\)
- \(x < x_\text{min}\)
This algorithm is useful to keep computing intersections at minimal.
Liang-barsky Algorithm
These inequalities can be summed up as
Definitions of \(p_k\) and \(q_k\)
The \(k\) indices represent following edges
of the clipping rectangle
.
- right
- left
- bottom
- top
For each edge
\(k\), if \(p_kâ = 0\) and \(q_k â< 0\), the line
1 is parallel and outside â reject.
If (\(p_k \ne 0\)) \(r_k = \frac{p_k}{q_k}\)â
if (\(p_k < 0\)) \(u_1 = \max(0, r_k) \quad \forall k\)
if (\(p_k > 0\)) \(u_2 = \min(1, r_k) \quad \forall k\)
if \((u_1 > u_2)\) accept the line
else clip the line
1