This paper proposes an algorithm for clipping line segment against an axis-aligned rectangular window. The conventional algorithms for line segment clipping treat the clipping boundary and/or the line segment to be clipped as line. The present algorithm treats the clipping boundary and the line segment to be clipped as line segment and using this strategy, it succeeds to avoid computation of false intersection points. A quadrilateral is constructed using the end points of a clipping boundary segment and the end points of the line segment to be clipped as its vertices. The concavity and convexity of the quadrilateral dictates whether a line segment actually intersects the clipping boundary. If the quadrilateral is found to be concave then the line segment is rejected, otherwise the point of intersection of the line segment with the clipping boundary is computed. Since a 'test & intersect' approach is used instead of a 'intersect & test', hence the proposed algorithm does not compute false intersection point thereby reducing the number of divisions required to obtain a clipped line segment. Only one routine can process line segments at any position. Improved performance is observed with respect to the Nicholl-Lee-Nicholl, Liang-Barsky, Cohen-Sutherland and Skala's algorithm through experiments with random line segments using a metric based on execution time.
翻译:本文提出了一种针对轴对齐矩形窗口的线段裁剪算法。传统线段裁剪算法通常将裁剪边界和/或待裁剪线段视为直线进行处理。本算法将裁剪边界与待裁剪线段均视为线段,通过这一策略成功避免了虚假交点的计算。该算法以裁剪边界线段的端点与待裁剪线段的端点作为顶点构造四边形,通过判断四边形的凹凸性来决定线段是否与裁剪边界实际相交。若四边形为凹四边形,则拒绝该线段;反之则计算线段与裁剪边界的交点。由于采用"先测试后求交"而非"先求交后测试"的策略,本算法无需计算虚假交点,从而减少了获得裁剪线段所需的除法运算次数。仅需单一例程即可处理任意位置的线段。基于执行时间指标的随机线段实验表明:与Nicholl-Lee-Nicholl算法、梁友栋-柏世雄算法、Cohen-Sutherland算法及Skala算法相比,本算法具有更优的性能。