0% found this document useful (0 votes)
8 views4 pages

Liang Barskey ClippingAlgorithm

Uploaded by

priyanka.yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Liang Barskey ClippingAlgorithm

Uploaded by

priyanka.yadav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

FACULTY NAME- PRAVIN KUMAR PANDEY

DEPARTMENT NAME- COMPUTER SCIENCE AND ENGINEERING


SUBJECT- COMPUTER GRAPHICS
SEMESTER- 5
YEAR- 3

UNIT-2

Liang-Barsky Line ClippingAlgorithm


The Liang-Barsky algorithm is a line clipping algorithm. This algorithm is more efficient
than Cohen–Sutherland line clipping algorithm and can be extended to 3-Dimensional clipping.
This algorithm is considered to be the faster parametric line-clipping algorithm. The following
concepts are used in this clipping-
• The parametric equation of the line.
• The inequalities describing the range of the clipping window which is used to determine
the intersections between the line and the clip window.

The parametric equation of a line can be given by-


X = x1 + t(x2-x1)
Y = y1 + t(y2-y1)
Where, t is between 0 and 1.

Then, writing the point-clipping conditions in the parametric form:


xwmin <= x1 + t(x2-x1) <= xwmax
ywmin <= y1 + t(y2-y1) <= ywmax

The above 4 inequalities can be expressed as-

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.

Using the following conditions, the position of line can be determined:


Condition Position of Line
pk = 0 parallel to the clipping boundaries
pk = 0 and qk < 0 completely outside the boundary
pk = 0 and qk >= 0 inside the parallel clipping boundary
pk < 0 line proceeds from outside to inside
pk > 0 line proceeds from inside to outside
Parameters t1 and t2 can be calculated that define the part of line that lies within the clip
rectangle.
When,
pk < 0, maximum(0, qk/pk) is taken.
pk > 0, minimum(1, qk/pk) is taken.

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.

Sutherland Hodgman Polygon Clipping


The Sutherland Hodgman algorithm performs a clipping of a polygon against each window
edge in turn. It accepts an ordered sequence of vertices v1, v2, v3, ..., vn and puts out a set of
vertices defining the clipped polygon.

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.

• Clipping against the left side of the clip window.


• Clipping against the top side of the clip window.
• Clipping against the right side of the clip window.
• Clipping against the bottom side of the clip window.
Four Types of Edges
As the algorithm goes around the edges of the window, clipping the polygon, it encounters four
types of edges. All four edge types are illustrated by the polygon in the following figure. For
each edge type zero, one, or two vertices are added to the output list of vertices that define the
clipped polygon.

The four types of edges are-


1. Edges that are totally inside the clip window. - add the second inside vertex point
2. Edges that are leaving the clip window. - add the intersection point as a vertex
3. Edges that are entirely outside the clip window. - add nothing to the vertex output list
4. Edges that are entering the clip window. - save the intersection and inside points as
vertices

Procedure to Calculate Intersections


Assume that we're clipping a polygon's edge with vertices at (𝑥1 , 𝑦1) and (𝑥2 , 𝑦2 ) against a
clip window with vertices at (𝑥𝑚𝑖𝑛 , 𝑦𝑚𝑖𝑛 ) and (𝑥𝑚𝑎𝑥 , 𝑦𝑚𝑎𝑥 ).
The location (IX, IY) of the intersection of the edge with the left side of the window is-
IX = 𝑥𝑚𝑖𝑛
IY = slope*(𝑥𝑚𝑖𝑛 -𝑥1 ) + 𝑦1 , where the slope = (𝑦2 -𝑦1 )/ ( 𝑥2 -𝑥1 )
The location of the intersection of the edge with the right side of the window is-
IX = 𝑥𝑚𝑎𝑥
IY = slope*(𝑥𝑚𝑎𝑥 -𝑥1 ) + 𝑦1 , where the slope = (𝑦2 -𝑦1 )/ ( 𝑥2 -𝑥1 )
The intersection of the polygon's edge with the top side of the window is-
IX = 𝑥2 + (𝑦𝑚𝑎𝑥 - 𝑦1 ) / slope
IY = 𝑦𝑚𝑎𝑥
Finally, the intersection of the edge with the bottom side of the window is-
IX = 𝑥1 + (𝑦𝑚𝑖𝑛 - 𝑦1 ) / slope
IY = 𝑦𝑚𝑖𝑛
Some Problems with This Algorithm
1. This algorithm does not work if the clip window is not convex.
2. If the polygon is not also convex, there may be some dangling edges.

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy