Liang–Barsky algorithm

This is an old revision of this page, as edited by 14.139.122.98 (talk) at 08:42, 29 May 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.


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

(left)
(right)
(bottom)
(top)

To compute the final line segment:

  1. A line parallel to a clipping window edge has for that boundary.
  2. If for that , , the line is completely outside and can be eliminated.
  3. When the line proceeds outside to inside the clip window and when , the line proceeds inside to outside.
  4. For nonzero , gives the intersection point.
  5. 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.