In computer graphics, the Liang–Barsky algorithm (named after You-Dong Liang and Brian A. Barsky) is a line clipping algorithm first published in early 1984. The Liang–Barsky algorithm uses the parametric equation of a line and inequalities describing the range of the clipping window to determine the intersections between the line and the clip window. With these intersections, it knows which portion of the line should be drawn. So this algorithm is significantly more efficient than Cohen–Sutherland. The idea of the Liang–Barsky clipping algorithm is to do as much testing as possible before computing line intersections. The algorithm uses the parametric form of a straight line:
x = x 0 + t ( x 1 − x 0 ) = x 0 + t Δ x , {\displaystyle x=x_{0}+t(x_{1}-x_{0})=x_{0}+t\Delta x,}
y = y 0 + t ( y 1 − y 0 ) = y 0 + t Δ y . {\displaystyle y=y_{0}+t(y_{1}-y_{0})=y_{0}+t\Delta y.}
A point is in the clip window, if
x min ≤ x 0 + t Δ x ≤ x max {\displaystyle x_{\text{min}}\leq x_{0}+t\Delta x\leq x_{\text{max}}}
and
y min ≤ y 0 + t Δ y ≤ y max , {\displaystyle y_{\text{min}}\leq y_{0}+t\Delta y\leq y_{\text{max}},}
which can be expressed as the 4 inequalities
t p i ≤ q i , i = 1 , 2 , 3 , 4 , {\displaystyle tp_{i}\leq q_{i},\quad i=1,2,3,4,}
where
… excerpt ends here. Continue reading the full article.
