Net migration rate: Difference between revisions
en>Mightymights Undid revision 490386319 by 182.177.133.76 (talk) |
No edit summary |
||
| Line 1: | Line 1: | ||
In [[computer graphics]], the '''Liang–Barsky 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 + u \Delta x\,\!</math> | |||
:<math>y = y_0 + u (y_1 - y_0) = y_0 + u \Delta y\,\!</math> | |||
A point is in the clip window, if | |||
:<math>x_{\text{min}} \le x_0 + u \Delta x \le x_{\text{max}}\,\!</math> | |||
and | |||
:<math>y_{\text{min}} \le y_0 + u \Delta y \le y_{\text{max}}\,\!</math>, | |||
which can be expressed as the 4 inequalities | |||
:<math>u p_k \le q_k, \quad k = 1, 2, 3, 4\,\!</math>, | |||
where | |||
:<math>p_1 = -\Delta x , q_1 = x_0 - x_{\text{min}}\,\!</math> (left) | |||
:<math>p_2 = \Delta x , q_2 = x_{\text{max}} - x_0\,\!</math> (right) | |||
:<math>p_3 = -\Delta y , q_3 = y_0 - y_\text{min}\,\!</math> (bottom) | |||
:<math>p_4 = \Delta y , q_4 = y_\text{max} - y_0\,\!</math> (top) | |||
To compute the final line segment: | |||
# A line parallel to a clipping window edge has <math>p_k = 0</math> for that boundary. | |||
# If for that <math>k</math>, <math>q_k < 0</math>, the line is completely outside and can be eliminated. | |||
# 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> (outside -> in). Take <math>u_1</math> to be the largest among <math>\left(0,\frac{q_k}{p_k}\right)</math>. For <math>u_2</math>, look at boundaries for which <math>p_k > 0</math> (inside -> out). 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: | |||
* [[Cyrus–Beck]] | |||
* [[Nicholl–Lee–Nicholl]] | |||
* [[Fast-clipping]] | |||
==References== | |||
* Liang, Y.D., and Barsky, B., "A New Concept and Method for Line Clipping", ''ACM Transactions on Graphics'', 3(1):1-22, January 1984. | |||
* Liang, Y.D., B.A., Barsky, and M. Slater, ''Some Improvements to a Parametric Line Clipping Algorithm'', CSD-92-688, Computer Science Division, University of California, Berkeley, 1992. | |||
* James D. Foley. ''[http://books.google.com/books/about/Computer_graphics.html?id=-4ngT05gmAQC Computer graphics: principles and practice]''. Addison-Wesley Professional, 1996. p. 117. | |||
==External links== | |||
* http://hinjang.com/articles/04.html | |||
{{DEFAULTSORT:Liang-Barsky algorithm}} | |||
[[Category:Clipping (computer graphics)]] | |||
Revision as of 00:10, 2 December 2013
In computer graphics, the Liang–Barsky 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:
A point is in the clip window, if
and
which can be expressed as the 4 inequalities
where
To compute the final line segment:
- A line parallel to a clipping window edge has for that boundary.
- If for that , , the line is completely outside and can be eliminated.
- When the line proceeds outside to inside the clip window and when , the line proceeds inside to outside.
- For nonzero , gives the intersection point.
- For each line, calculate and . For , look at boundaries for which (outside -> in). Take to be the largest among . For , look at boundaries for which (inside -> out). Take to be the minimum of . If , the line is outside and therefore rejected.
See also
Algorithms used for the same purpose:
References
- Liang, Y.D., and Barsky, B., "A New Concept and Method for Line Clipping", ACM Transactions on Graphics, 3(1):1-22, January 1984.
- Liang, Y.D., B.A., Barsky, and M. Slater, Some Improvements to a Parametric Line Clipping Algorithm, CSD-92-688, Computer Science Division, University of California, Berkeley, 1992.
- James D. Foley. Computer graphics: principles and practice. Addison-Wesley Professional, 1996. p. 117.