A Sweep-Line Algorithm and Its Application to Spiral Pocketing

- - - - This paper presents an efficient line-offset algorithm for general polygonal shapes with islands. A developed sweep-line algorithm (SL) is introduced to find all self-intersection points accurately and quickly. The previous work is limited to handle polygons that having no line-segments in parallel to sweep-line directions. The proposed algorithm has been implemented in Visual C++ and applied to offset point sequence curves, which contain several islands.


Introduction
In order to machine complex pockets on milling machines, it is necessary to fill 2D areas with a back and forth sweeping motions of the cutting tool.There are two sweeping motions, spiral offset and zigzagging paths.The spiral offset is defined as a locus of the points, which are at constant distance d along the normal from the generator curve.Spiral offsets are widely used in various applications, such as tool path generation for 2.5-D pocket machining [3,9,14,15,20], 3D NC machining, and access space representations in robotics.Spiral milling is an important operation in CAD/CAM, and the problem has been widely studied, mostly, as a pocket-machining problem through three approaches.Line-offset (pair-wise) [8,13,17], Voronoi diagram [10], and pixel-based approach [4].Voronoi diagram needs a very careful implementation to avoid numerical computational error [10].Pixel-based approach would require a large amount of memory and an excessive computation time to achieve an adequate level of precision [5].Lineoffset approach is more stable, not prone to computational errors, and would not require a large amount of memory [5].Self-intersection is one of the main problems in line-offset so, it is an essential task for practical applications to detect all polygons of the self-intersection points correctly and generate valid polygons.The literature survey on offset curve and self-intersection polygons prior to 1992 was conducted by Pham [18] and after 1992 by Takashi [22].The self-intersection polygons can be handled through two approaches, linesegments intersections [7,18] and sweep-line [1,11,12].Sweep-line is more efficient than line-segments intersections [21].Bentley and Ottmann 1979 [1] introduced a sweep-line algorithm to find all k intersections among n line-segments with an O((n+k).logn) time complexity.Chazelle et al. [2] and Mehlhorn et al. [16] developed Bentley et al. algorithm [1], but their algorithm is more complicated to implement [17].Park et al. 98, developed a sweep-line algorithm to find all intersections k among polygonal chain which has m monotone and n linesegments with an O ((n +k).log m) time complexity, but it is only restricted for polygons which contain line segments nonparallel to sweep-line direction.
In this paper, a sweep-line algorithm, for general polygonal shapes with islands, is developed.The developed algorithm can be applied to find selfintersection points, even if the sweep-line was parallel to one or more line-segment in the polygon.Also, invalidloops detection and removing algorithm are proposed.The proposed algorithm has been implemented in Visual C++, and extensively tested for several polygonal shapes.The results show robustness, and quickness of the developed algorithm for offsetting general polygonal shapes with islands.

Definitions and Terminology
This section contains some preliminary definitions and terms that are used throughout this paper.The following definition of a monotone chain is based on those of Preparata et al. [19] and Park et al. [17].To handle the chains with line-segments parallel to sweepline, parallel monotone is suggested in this paper.

Definition of Chain
Chain is a connected sequence of line segments, and a polygon is a chain that is closed and non selfintersecting [17].It is assumed that a consecutive collinear sequence of line-segments is merged together into a single line segment.

Definition of Monotone Chain
A chain C in Fig. 1 is a monotone with respect to a line ZL, if C has at most one intersection point with a line L perpendicular to ZL [17].The line ZL is called the monotone direction, and the line L becomes a sweep line.It is assumed that ZL-line has an x-axis direction.There are two types of monotone: non-parallel monotone (which contains no parallel line-segment to sweep-line direction), and parallel monotone (which is only one line segment parallel to sweep-line direction).

Definition of Parallel Monotone Chain (PMC)
The Monotone is parallel, if it has at most one linesegment whose direction is parallel to sweep-line Fig.

Definition of Extreme Point
A point in a chain is called a left-extreme and/or right-extreme point, if its x-value is locally minimum or maximum.The monotone contains right & left extreme point [17].PMC contains two points: the first point (P1 Fig. 2) is an up-extreme point and the last point (P2 Fig. 2) is a down-extreme point, like right and left extreme points in general chain (non parallel chain).

Definition of Sweep Step (SS) & Monotone
Sweep Value (MSV) Sweep-step (SS) is the x -coordinate of SL, and intersection of SL with certain monotone is called monotone sweep value (MSV)

Monotone Chains & Extreme Points
Shown in Fig. 3

Sweep-line Algorithm (SL)
The proposed polygonal-chain intersection algorithm mainly works on a set of monotone chains.The properties of a monotone chain are: ( 1) it has no self-intersections among its line segments, and (2) its points are in a sequence order of x-values allowing an efficient use of the sweep-line method.The following is the explanation of sweep-line algorithm.

Information Flow through the Sweep-line algorithm
The point data are exported from CAD system in DXF format and imported to data filter, Fig. 4. In this step collinear points are removed, and stored in monotones.These monotones are stored in monotone chain.The sweep-line values are sorted and stored in sweep chain.And then, monotone-intersection module will find self-intersection points.

Island Making Algorithm (IM)
The IM algorithm is proposed to handle the island during pocketing, Fig. 5.The algorithm contains the following steps: Step 1: Detect boundary and island polygons, make boundary CCW, and island CW direction.
Step 2: Make one outward offset for island and inward offset until it meets for boundary up to meet island offset.Store the generated offset of boundary and island in temporary polygons.
Step 3: Use SL to find self-intersection points for the temporary polygon, and call detection valid polygons [23] (DVP) to find all valid polygons.

Applications
This section contains two parts: Part I, shows the execution time for three-sample examples vs. offset distance for full offset.These sample examples are performed on PIII-800 MHz PC, the execution time calculated through a built-in Visual C++ function (refer to Fig. 6).It is assumed that the offset in the first generated polygon=50% from a cutting tool diameter and 90% for the remaining generated offset.Part II, shows the relationship between the number of offset and the execution time.

Part (I) Execution Time for Full Offset
As shown in Table 1, the execution time is decreasing while the offset distance is increasing.This variation is more significant for small offset distance, and almost  linearly with large values of offset distance.These results are plotted on a line-chart shown in Fig. 7 for threesample examples (bearing holder, deer, and magician).

Part (II) Effect of Repeated Offset
The relationship between the number of offset and the execution time for the three-sample example is given in Fig. 8.
This figure shows that the execution time is increasing linearly for small values of offset and becomes almost constant for large values of repeating offset.This constant variation occurs when the repeating offset value becomes closer to the full offset values of the application.Also, the figure shows that Magician starts with increasing rather sharply than Bearing Holder and Deer.This sharp variation depends on the complexity of the shape and the number of islands.

Conclusion
Presented in this paper an efficient line-offset algorithm for general polygonal shapes with islands.A developed sweep-line algorithm (SL) is introduced to find all selfintersection points accurately and quickly.The developed algorithm is a considerable improvement over previous work algorithms which were limited to handle polygons that having no line-segments in parallel to sweep-line directions.The proposed algorithms are tested through several application examples.

2 .
It has also two vertices (P1, P2) i.e. two sweep-lines L 1 and L 2 at P1 and P2 respectively.The two sweeplines are overlapped.It is assumed that the sweep-line L 1 intersects the PMC at point P1 and sweep-line L 2 intersects the PMC at point P2.While traversing a chain, each of the locals "extreme" points (with respect to their x-values) are marked either as a left or rightextreme point and up or down-extreme point as follows: are local extreme points of a closed polygonal chain consisting of 7 points (or 7 linesegments): There are two left-extreme points, P0 and P3, two right-extreme points, P2 and P4, one up-extreme point, P3, and one down-extreme point, P2.The chain can easily be divided into monotone chains.Since left & right-extreme points, up & down-extreme point alternate, each sequence of the line-segments starting from left to right-extreme point or from up-to downextreme point (or vise versa) is identified as a monotone chain.The sweep-line steps are defined at vertices of polygonal chain and sorted by a quick-sort algorithm.It is assumed that a vertical sweep-line is used in the developed algorithm.There is no problem, if the chains contain line-segments in parallel with the sweep-line through using of PMC, i.e. the fundamental limitation of the Park et al. [17] sweep-line method is removed.

Table 1 .
Sample example execution time vs. offset distance

Table 2 .
Execution time vs.No of offset