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:
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 , , then 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 for the intersection point of the line and the window edge (possibly projected).
- The two actual intersections of the line with the window edges, if they exist, are described by and , calculated as follows. For , look at boundaries for which (i.e. outside to inside). Take to be the largest among . For , look at boundaries for which (i.e. inside to outside). Take to be the minimum of .
- If , the line is entirely outside the clip window. If it is entirely inside it.
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.
External links