Liang Barskey ClippingAlgorithm
Liang Barskey ClippingAlgorithm
UNIT-2
tpk <= qk
Where k = 1, 2, 3, 4 (correspond to the left, right, bottom, and top boundaries, respectively).
The p and q are defined as-
p1 = -(x2-x1), q1 = x1 - xwmin (Left Boundary)
p2 = (x2-x1), q2 = xwmax - x1 (Right Boundary)
p3 = -(y2-y1), q3 = y1 - ywmin (Bottom Boundary)
p4 = (y2-y1), q4 = ywmax - y1 (Top Boundary)
1. When the line is parallel to a view window boundary, the p value for that boundary is
zero.
2. When pk < 0, as t increase line goes from the outside to inside (entering).
3. When pk > 0, line goes from inside to outside (exiting).
4. When pk = 0 and qk < 0 then line is trivially invisible because it is outside view window.
5. When pk = 0 and qk > 0 then the line is inside the corresponding window boundary.
If t1 > t2, the line is completely outside the clip window and it can be rejected. Otherwise, the
endpoints of the clipped line are calculated from the two values of parameter t.
Algorithm –
1. Set tmin=0, tmax=1.
2. Calculate the values of t (t(left), t(right), t(top), t(bottom)),
(i) If t < tmin ignore that and move to the next edge.
(ii) else separate the t values as entering or exiting values using the inner product.
(iii) If t is entering value, set tmin = t; if t is existing value, set tmax = t.
3. If tmin < tmax, draw a line from (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) to (x1 + tmax(x2-x1), y1 +
tmax(y2-y1)).
4. If the line crosses over the window, (x1 + tmin(x2-x1), y1 + tmin(y2-y1)) and (x1 + tmax(x2-
x1), y1 + tmax(y2-y1)) are the intersection point of line and edge.
Polygon
A polygon can be defined as a geometric object "consisting of a number of points (called
vertices) and an equal number of line segments (called sides), namely a cyclically ordered set
of points in a plane, with no three successive points collinear, together with the line segments
joining consecutive pairs of the points.
This figure represents a polygon (large, solid, upward pointing arrow) before clipping has occurred.
The following figures show how this algorithm works at each edge, clipping the polygon.
References
[1] https://www.geeksforgeeks.org/liang-barsky-algorithm/
[2] Amrendra N Sinha and Arun D Udai,” Computer Graphics”, TMH
[3] Udit Agarwal “Computer Graphics”, KATSON