Download Liang Barsky algorithm and more Lecture notes Computer Graphics in PDF only on Docsity!
Computer Graphics
Liang-Barsky
(Line Clipping Algorithm)
Covered by:-
Arvind Kumar
Assistant Professor
Vidya College of Engg.
Liang-Barsky Line Clipping Algorithm This algorithm uses the parametric equations for a line and solves four inequalities to find the range of the parameter for which the line is in the viewport. Parametric Equations are given below:
๐
+ t*ฮ ๐
y = ๐
๐
+ t*ฮ y , 0 โค t โฅ 1
Where ฮ ๐ฅ = ๐ฅ
2
ฮ y = ๐ฆ
2
As we know the point clipping condition is:
๐๐๐๐
๐๐๐๐
โฆโฆโฆโฆโฆโฆ(i)
๐๐๐๐
๐๐๐๐
.โฆโฆโฆโฆโฆ...(ii)
Liang-Barsky Line Clipping Algorithm
Following observations can be :
if ๐
๐
= 0 : Line is parallel to the clipping boundary.
if ๐๐ < 0 : Line is completely outside the clipping
boundary.
if ๐๐ < 0 : Line proceeds from outside to inside of the
clipping boundary.
if ๐๐ < 0 : Line proceeds from inside to outside of the
clipping boundary.
i.e ,
Line intersect the clipping boundary
Liang-Barsky Line Clipping Algorithm
This algorithm calculate value parameter t: ๐๐ and ๐๐.
โข The value of ๐๐ is determined checking the edge for which
line proceed from outside to inside( ๐
๐
< 0 ). The
maximum value is taken.
โข The value of ๐๐ is determined checking the edge for which
line proceed from inside to outside(๐๐ > 0 ). The minimum
value is taken if ๐ ๐
๐ ๐ , the line is completely outside the window
and it can be rejected.
Otherwise, the value of ๐๐ & ๐๐ , are substituted in the
parametric equations to get the intersection points of the
clipped line.
Liang-Barsky Line Clipping Algorithm
- If ๐๐ = 0 , then { Line is parallel to the clipping boundary. Now , if ๐๐ < 0 then { Line is completely outside the clipping boundary. } } else Check for intersection point.
- Initialize values ๐๐= 0 and ๐๐ = 1.
- Calculate values for ๐๐ ๐๐ for i= 1 , 2 , 3 , 4.
Liang-Barsky Line Clipping Algorithm
- Select values of ๐๐ ๐๐ , where ( ๐๐ < 0 ), assign maximum value out of them as ๐๐.
- Select values of ๐๐ ๐๐ , where ( ๐๐ > 0 ), assign minimum value out of them as ๐๐.
- If ๐๐<๐๐ , then calculate intersection points are as : { ๐๐๐ = ๐๐ + ๐๐ *ฮ ๐ ๐๐๐ = ๐๐ + ๐๐ *ฮ y ๐๐๐ = ๐๐ + ๐๐ *ฮ ๐ ๐๐๐ = ๐๐ + ๐๐ *ฮ y } Draw clipped line (๐๐๐, ๐๐๐ , ๐๐๐ , ๐๐๐)
- Stop
- Calculate the value of parameter ๐๐ and ๐๐, for i = 1 , 2 , 3 & 4. ๐๐ = - ฮ ๐ ๐๐ = ๐๐ - ๐๐๐๐๐ ๐๐ = - 50 ๐๐ = โ๐ ๐๐ ๐๐
๐๐ ๐๐
๐๐ ๐๐
๐๐ ๐๐
โข ๐๐= max( 0 , 0. 25 , 0. 1 ) = 0. 25 , for the values (๐๐ < 0 ) โข ๐๐= min( 0. 25 , 0. 1 , 1 )= 0. 3 , for the values (๐๐ > 0 )
Calculate the intersection points: ๐๐๐ = ๐๐ + ๐๐ *ฮ ๐ = 10 + 0. 25 * 50 = 22. 5 ๐๐๐ = ๐๐ + ๐๐ *ฮ y = 10 + 0. 25 * 20 = 15 ๐๐๐ = ๐๐ + ๐๐ *ฮ ๐ = 10 + 0. 3 * 50 = 25 ๐๐๐ = ๐๐ + ๐๐ *ฮ y = 10 + 0. 3 * 20 = 16 The Clipped Line end points are ( 22.5,15) & (25, 16)