Liang–Barsky algorithm: Difference between revisions

Content deleted Content added
Undid revision 718388679 by 117.55.247.118 (talk)
No edit summary
Line 1:
In [[computer graphics]], the '''Liang–BarskyLiang–Bhosdi algorithm''' (named after [[You-Dong Liang]] and [[Brian A. Barsky]]) is a [[line clipping]] algorithm. 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 clipping window. With these intersections it knows which portion of the line should be drawn. 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.
 
 
Consider first the usual parametric form of a straight line:
 
:<math>x = x_0 + u (x_1 - x_0) = x_0 + ut \Delta x\,\!</math>
:<math>y = y_0 + u (y_1 - y_0) = y_0 + ut \Delta y\,\!</math>
 
A point is in the clip window, if
:<math>x_{\text{min}} \le x_0 + ut \Delta x \le x_{\text{max}}\,\!</math>
and
:<math>y_{\text{min}} \le y_0 + ut \Delta y \le y_{\text{max}}\,\!</math>,
which can be expressed as the 4 inequalities
:<math>ut p_k \le q_k, \quad k = 1, 2, 3, 4\,\!</math>,
where
 
Line 25:
# When <math>p_k < 0</math> the line proceeds outside to inside the clip window and when <math>p_k > 0</math>, the line proceeds inside to outside.
# For nonzero <math>p_k</math>, <math>u = \frac{q_k}{p_k}</math> gives the intersection point.
# For each line, calculate <math>u_1</math> and <math>u_2</math>. For <math>u_1</math>, look at boundaries for which <math>p_k < 0</math> (i.e. outside to inside). Take <math>u_1</math> to be the largest among <math>\left\{ 0,\frac{q_k}{p_k} \right\}</math>. For <math>u_2t_2</math>, look at boundaries for which <math>p_k > 0</math> (i.e. inside to outside). Take <math>u_2</math> to be the minimum of <math>\left\{ 1, \frac{q_k}{p_k} \right\}</math>. If <math>u_1 > u_2</math>, the line is outside and therefore rejected.
==See also==
Algorithms used for the same purpose: