Complete Guide to Two-Dimensional Viewing and Clipping in Computer Graphics
Point clipping:
Point
clipping is a type of clipping algorithm that focuses specifically on
determining whether a point lies within the clip window or not. This method
checks if a point is within the bounds of the rectangular region defined by the
clip window.
Point clipping is essentially the evaluation of the
following inequlities:
((xmin ≤ x
≤ xmax) (ymin ≤ y
≤
ymax))
where xmin, xmax, ymin and
ymax define the clipping window. A point (x, y) is considered inside
the window when the inequalities all evaluate to true.
Math:
Here the (xmin, ymin) = (1, 2) and
(xmax, ymax) = (5, 4), the point coordinates are p1(2,
3), p2(3, 1)
For p1,
1 < 2 < 5
2 < 3 < 4
it satisfies the conditions
For p2,
1 < 3 < 5
2 < 1 < 4 (invalid condition)
it does not satisfy the condition for y, and it is clipped.
Line
clipping:
Line
clipping algorithm is used to remove the parts of lines that are outside the
area viewport. Line clipping reduces the computation cost by enabling or
disabling rendering operations within a defined region.
The
Cohen-Sutherland Algorithm:
In
this algorithm, divide the line clipping process into two phases: (1) identify
those lines which intersect the clipping window and so need to be clipped and
(2) perform the clipping.
All
lines fall into one of the following clipping categories:
- Visible---- both endpoints of the line lie within the window.
- Not visible--- the line definitely lies outside the window. This will occur if the line from (x1,y1) to (x2,y2) satisfies any one of the following four inequalities:
X1
,X2 > Xmax and
y1, y2 > ymax
X1
,X2 < Xmin and
y1, y2 < ymin
- Clipping candidate--- the line is in neither category 1 nor 2.
In Fig, line AB is in category 1 (visible); lines CD and EF
are in category 2 (not visible); and lines GH, IJ, and KL are in category 3
(clipping candidate).
No comments