An Alternative Algorithm for Line Clipping
Bimal Kumar Ray · Journal of Graphics Tools · 2012
The development, testing, and validation of the Nicholl-Lee-Nicholl algorithm are difficult, and when it is extended to 3D, the number of cases rockets, making it even harder. This article presents an alternative algorithm for line clipping and its immediate extension to 3D. The algorithm is simple, fast, and numerically correct. It uses a trivial test for rejecting lines that are completely beyond the boundaries of the clipping region. If the trivial test fails, then it splits the clipping problem into two calls to a routine that returns a Boolean value. If at least one of the calls returns false, then no portion of the line is inside the clipping region. The algorithm is compared with the Cohen-Sutherland(CS), Liang-Barsky(LB), and Nicholl-Lee-Nicholl(NLN) algorithms with respect to execution time on a large number of random lines, and it is found that its performance is better than the CS and LB algorithms. The pseudocode of the 3D algorithm is available in Appendix A.