### AN APPROACH FOR LINE CLIPPING AGAINST A CONVEX POLYHEDRON

*Kasun Ranga Wijeweera, S. R. Kodituwakku*

#### Abstract

Line clipping operation is a bottleneck in most of computer graphics applications. There are situations when millions of line segments need to be clipped against convex polyhedrons with millions of facets. An algorithm to clip line segments against a convex polyhedron is proposed in this work. The salient feature of the proposed algorithm is that it minimizes the number of computations by ignoring unnecessary intersection calculations. The other advantage of the proposed algorithm is that it needs minimum details about the convex polyhedron; the equations of the facets and the centroid. Therefore, it improves the efficiency of the algorithm. The line segment may have zero length (a point) or positive length. When line segment is just a point which is outside with respect to at least one facet, it should be rejected as the line segment is outside the convex polyhedron. When the line segment is parallel to a facet and one of its end points is outside, that line segment is also completely outside and it should also be rejected. Unless the line segment belongs to none of the above two cases, it should be pruned against each facet in a certain order. In this case, the intersection points with only some of the facets need to be computed and some other intersection calculations can be ignored. If the line segment is completely outside then it becomes a single point. That means the two end points coincide. But due to the precision error they do not exactly coincide. Therefore, approximate equality should be tested. By using this property, completely outside line segments can be identified. Having two end points outside does not necessarily keep the line segment completely outside. The widely used Cyrus Beck algorithm computes all the intersection points with each facet of the polyhedron while the proposed algorithm successfully avoids some of the intersection point calculations. In the best case; it is capable of avoiding all the unnecessary intersection calculations. An experimental comparison between the Cyrus Beck algorithm and the proposed algorithm was carried out. Random polyhedrons were created with different number of facets. Random points were generated and they were considered as end points of line segments. For a given polyhedron, the number of clock cycles consumed to clip 10^{8} number of line segments was computed using the Cyrus Beck algorithm and the proposed algorithm. For a polyhedron with four vertices, the proposed algorithm is 1.02 times faster than the Cyrus Beck algorithm. For a polyhedron with nine vertices, the proposed algorithm is 1.16 times faster than the Cyrus Beck algorithm. When the number of facts is large, then the performance of the proposed algorithm is significantly faster since more intersection calculations are avoided. The proposed approach could be very useful for applications where large number of lines to be clipped. It can also be applied in linear programming as well since it can be extended to arbitrary dimensions.

#### References

D. Hearn and M. P. Baker (1998), Computer Graphics, C Version, 2nd Edition, Prentice Hall, Inc., Upper Saddle River, pp. 224-248.

W. Huang (2010), The Line Clipping Algorithm Based on Affine Transformation, Intelligent Information Management, Volume. 2, pp. 380-385.

S. R. Kodituwakku, K. R. Wijeweera, M. A. P. Chamikara (2013), An Efficient Algorithm for Line Clipping in Computer Graphics Programming, Ceylon Journal of Science (Physical Sciences), Volume. 17, pp. 1 – 7.

CS 535 NOTES CYRUS-BECK CLIPPING ALGORITHM, http://cs1.bradley.edu/public/jcm/cs535CyrusBeck.html; accessed on 20 July 2012.

### Refbacks

- There are currently no refbacks.

Ruhuna Journal of Science by University of Ruhuna is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.

eISSN: 2536-8400

Print ISSN: 1800-279X (Before 2014)