8
Computer Aided Geometric Design 5 (1988) 51-58 51 North-Holland Finding the composite outer boundary and holes of a set of closed curves Glen MULLINEUX Manufacturing and Engineering Systems, Brunel University, Uxbridge, Middlesex UB8 3PH, UK Received June 1986 Revised December 1987 Abstract. Closed (planar) curves arise, for example, as NC toolpaths. They are composed of various line and curve segments. While the intersection of the individual entities may be straightforward these then have to be regrouped to determine the outer boundary (which is taken to include the boundaries of the holes). A procedure and data structure for handling this rearrangement is described. Keywords. Closed curves, free-form curves, intersections I. Introduction Many methods exist for finding the intersection of various pairs of geometric entities such as straight line segments, circular arcs and spline curve segments. These are implemented widely on CAD and draughting systems. In practice, however, the entities are grouped to form more complex geometrical structures representing the real-world components being designed. It is the intersection of these larger structures that the user is interested in. This requires that the individual parts must be investigated but this is not the prime concern of the user. For example, a user may want to know if the arm of a robot interferes with its work cell. It is preferable if the command to the CAD system can be given in terms of these large scale entities and for the system to decide which of the individual lines, arcs and faces need to be checked. A more simple example, and one of the forms discussed in this paper, is that of dosed curves composed of several line or curve segments. These occur, for example, as toolpaths for machining components. [Chart et al. '79] describe a simple modelling system for the computer- aided manufacture of forging dies by 2.5-axis machining. Closed horizontal machining contours are generated for each part of the given component. Each is composed of simple geometric entities such as straight line segments and circular arcs. These together enclose a region which is a cross section through the relevant part of the component. The section through the entire component is the union of these overlapping regions. We need to modify (in a sense explained later) the boundaries of the individual regions to deduce the correct outer boundary of the composite region. The term 'outer boundary' is intended to include also the boundaries of any holes present in the composite region. The intersections of the constituent geometric entities (from different contours) are found. These subdivide the entities into subsegments and it is necessary to decide which of these subsegments form the new bounding curve for the composite region. Ad hoc methods have been devised to do this. However problems result. Holes within the area bounded by the closed curved need to be handled. Rounding errors can lead to intersections being found more than once, particularly where curves touch. Some of these difficulties are discussed in Section 2 of this paper. 0167-8396/88/$3.50 © 1988, Elsevier Science Publishers B.V. (North-Holland)

Finding the composite outer boundary and holes of a set of closed curves

Embed Size (px)

Citation preview

Page 1: Finding the composite outer boundary and holes of a set of closed curves

Computer Aided Geometric Design 5 (1988) 51-58 51 North-Holland

Finding the composite outer boundary and holes of a set of closed curves

Glen MULLINEUX

Manufacturing and Engineering Systems, Brunel University, Uxbridge, Middlesex UB8 3PH, UK

Received June 1986 Revised December 1987

Abstract. Closed (planar) curves arise, for example, as NC toolpaths. They are composed of various line and curve segments. While the intersection of the individual entities may be straightforward these then have to be regrouped to determine the outer boundary (which is taken to include the boundaries of the holes). A procedure and data structure for handling this rearrangement is described.

Keywords. Closed curves, free-form curves, intersections

I. Introduction

Many methods exist for finding the intersection of various pairs of geometric entities such as straight line segments, circular arcs and spline curve segments. These are implemented widely on CAD and draughting systems. In practice, however, the entities are grouped to form more complex geometrical structures representing the real-world components being designed. It is the intersection of these larger structures that the user is interested in. This requires that the individual parts must be investigated but this is not the prime concern of the user. For example, a user may want to know if the arm of a robot interferes with its work cell. It is preferable if the command to the CAD system can be given in terms of these large scale entities and for the system to decide which of the individual lines, arcs and faces need to be checked.

A more simple example, and one of the forms discussed in this paper, is that of dosed curves composed of several line or curve segments. These occur, for example, as toolpaths for machining components. [Chart et al. '79] describe a simple modelling system for the computer- aided manufacture of forging dies by 2.5-axis machining. Closed horizontal machining contours are generated for each part of the given component. Each is composed of simple geometric entities such as straight line segments and circular arcs. These together enclose a region which is a cross section through the relevant part of the component. The section through the entire component is the union of these overlapping regions.

We need to modify (in a sense explained later) the boundaries of the individual regions to deduce the correct outer boundary of the composite region. The term 'outer boundary' is intended to include also the boundaries of any holes present in the composite region.

The intersections of the constituent geometric entities (from different contours) are found. These subdivide the entities into subsegments and it is necessary to decide which of these subsegments form the new bounding curve for the composite region. Ad hoc methods have been devised to do this. However problems result. Holes within the area bounded by the closed curved need to be handled. Rounding errors can lead to intersections being found more than once, particularly where curves touch. Some of these difficulties are discussed in Section 2 of this paper.

0167-8396/88/$3.50 © 1988, Elsevier Science Publishers B.V. (North-Holland)

Page 2: Finding the composite outer boundary and holes of a set of closed curves

52 G. Mullineux / Intersection of closed curves

In Sections 3 and 4 we describe an attempt to streamline the problem of identifying the full outer boundary. It is based upon a data structure in which each intersection point is held twice. Section 5 provides some examples. We describe some limitations of the method and how they can be resolved in Section 6.

2. Review of ideas and problems

Several methods are available for determining the points of intersection of a pair of line or curve segments. They vary from analytical methods to numerical ones. A well-known approach based upon subdivision is particulary useful when parametric curves are involved [Boehm et al. '84]. A rectangular (or, in three dimensions, cuboidal) box is placed around each segment; if these do not overlap, no intersection exists between different segments. If overlap occurs, each segment is subdivided, say at the point corresponding to its middle parameter value, and the process repeated on the four new segments thus formed. This continues recursively until the segments involved are smaller than the acceptable tolerance on the intersection point.

Problems arise because of the lack of precision that exists. For example two curve segments may touch in two or more coincident points. It is not clear how many intersections we wish a method to find let alone how many are found in practice. For example, two segments cross over at point P if they intersect in a single point or if they touch in an odd number of coincident points. If we are only interested in whether curves cross over we can either find the number of coincident points at P or, more simply, examine the curves on either side of P.

Problems can increase with curves composed of a number of contiguous line or curve segments. Fig. l(a) shows the same type of touching problem for two closed curves each composed of three straight line segments. When considering the intersection of lines PQ and PR with line BC it is possible that neither, or one, or both will be found to intersect. Fig. l(b) shows this type of situation again. AB, BC and PQ are three curve segments; PQ cuts the ABC curve at or near B. The intersection point could be found twice: once on AB and again on BC.

We are concerned in this paper with dosed curves. One way for deciding if a given point lies inside or outside a closed curve is to construct a line from the point to infinity. If this cuts the curve an odd number of times then the point is inside. This requires the correct number of intersections to be found with the appropriate allowances for multi-point contact (including tangencies).

None of the problems discussed here is insuperable. However they require special-purpose coding in addition to the main algorithms used. We consider the problem of finding the outer boundary of a region formed from a number of overlapping subregions whose boundaries are closed curves. Holes are allowed. We need to identify and remove those parts which are in the

0

B 0 A

(a) (b) P

C

Fig. 1. Multiple point intersections.

Page 3: Finding the composite outer boundary and holes of a set of closed curves

G. Mullineux / Intersection of closed curves 53

.<

>

Fig. 2. A number of orientated boundary curves.

region of overlap and piece together the various parts of the remaining curve segments. The approach avoids most problems.

We describe a boundary curve as follows. (a) It is composed of a number of (planar) parametric curve segments which do not intersect

each other and which join together to form a number of closed curves. (b) Some of these closed curves may surround others and there is a hierarchy of nesting. (c) Any closed curve that is not surrounded in another is deemed to enclose a positive area

or region and is orientated anticlockwise. Closed curves at the next level of nesting enclose holes (negative areas) and are orientated clockwise. The next level enclose positive regions, and so on.

Fig. 2 shows some examples of boundary curves.

3. Some graph theory

Euler's theorem in graph theory is well-known (see, for example, [Harary '69]) and is given here for completeness. For a directed graph, in which each node has the same number of edges entering it as leaving it, the theorem says that the graph can be decomposed as a number of disjoint directed loops.

The boundary curve, introduced in the last section, is a directed graph; the nodes are the ends of segments and the orientated segments themselves are the edges. If two or more such curves overlap we can form intersections and regard these as new nodes. Each node has one edge entering and another leaving; these are produced by each boundary of which the node is a part. So Euler's theorem applies. Indeed the graph is generated as a union of loops. We make the restriction that three separate boundary curves do not intersect in the same point. Thus

Page 4: Finding the composite outer boundary and holes of a set of closed curves

54 G. Mullineux / Intersection of closed curves

Fig. 3. Decomposition into loops.

each node has either one or two edges entering and the same number leaving. This limitation is dicussed in Section 6.

The loops in Euler's theorem are generated by traversing edges in the graph until a Iiode is repeated. There is ambiguity about which edge to take on leaving any node. With the assumption in the last paragraph, we specify that at nodes where there are two edges in and two edges out, we leave on that edge of the boundary which is different from the one used to enter the node. This creates a new decomposition into loops. Fig. 3 shows an example.

The original boundary curves enclose regions; when they overlap we consider the region enclosed to be the union. We check that the outer boundary of the union is among the loops formed by the above process. In fact the example of Fig. 3 is the only case we need to check. At the point P two original boundaries meet. The orientation of the edge relative to the region enclosed ensures that when we enter P by the outer boundary on the left we leave by the correct outer boundary on the right. A separate argument for holes in the regions is not necessary; however, for completeness, Fig. 4 shows an example. Note that the holes are still described in a clockwise sense. The algorithm is described in the next section.

4. Implementation

This section describes a method for attaining the second decomposition into loops discussed in Section 3. The data structure used is illustrated with the example shown in Fig. 5. Each segment end-point corresponds to a node and is recorded as the pair of segments that meet there. These are the columns labelled Seg 1 and Seg 2 in Table 1. On each segment the parameter value is chosen to run from 0 to 1. Column Par 1 shows the parameter value on segment Seg 1 at the node; this is unity. Par 2 is defined similarly and is zero. The Next column creates a linked list to describe each closed curve. The curves are composed of elliptical

Fig. 4. Decomposition with holes.

Page 5: Finding the composite outer boundary and holes of a set of closed curves

G. Mullineux / Intersection of closed curves 55

( / Fig. 5. Curves for data structure exam- pies.

quadrants, 16 in all, each described as a rational Bezier curve of degree 2. The data structure is given in Table 1 and, as subsequently modified, in Table 2.

Step 1 The initial data structure is formed.

Step 2 All intersections between pairs of segments are found. These are new nodes. Each is entered

as a pair of segment numbers together with the appropriate parameter values. Each is entered twice; the second being with the segment order reversed. These extra entries are shown in Table 2. It is useful to have some pointers to indicate, for each intersection, which is the reversed entry in the structure; for simplicity this is not shown in Table 2.

Step 3 This is the reordering step which relinks the list of entries. A start point is chosen arbitrarily.

At a general stage, suppose the current entry has s 2 in the Seg 2 column and P2 in the Par 2 column. Among those entries with s 2 in their Seg 1 column we seek the one with the smallest

Table 1

Seg I Seg 2 Par 1 Par 2 Next

1 1 2 1.000 0.000 2 2 2 3 1.000 0.000 3 3 3 4 1.000 0.000 4 4 4 1 1.000 0.000 1 5 5 6 1.000 0.000 6 6 6 7 1.000 0.000 7 7 7 8 1.000 0.000 8 8 8 5 1.000 0.000 5 9 9 10 1.000 0.000 10

10 10 11 1.000 0.000 11 11 11 12 1.000 0.000 12 12 12 9 1.000 0.000 9 13 13 14 1.000 0.000 14 14 14 15 1.000 0.000 15 15 15 16 1.000 0.000 16 16 16 13 1.000 0.000 13

Page 6: Finding the composite outer boundary and holes of a set of closed curves

56

Table 2

G. Mullineux / Intersection of closed curves

Seg I Seg 2 Par I Par 2 Next Loop

1 1 2 1.000 0.000 21 a 2 2 3 1.000 0.000 3 b 3 3 4 1.000 0.000 23 b 4 4 1 1.000 0.000 17 5 5 6 1.000 0.000 6 c 6 6 7 1.000 0.000 27 c 7 7 8 1.000 0.000 31 d 8 8 5 1.000 0.000 25 9 9 10 1.000 0.000 20 b

10 10 11 1.000 0.000 28 11 11 12 1.000 0.000 26 c 12 12 9 1.000 0.000 9 b

13 13 14 1.000 0.000 30 d 14 14 15 1.000 0.000 22 15 15 16 1.000 0.000 16 a 16 16 13 1.000 0.000 18 a 17 1 13 0.069 0.662 32 18 13 1 0.662 0.069 1 a 19 2 10 0.263 0.881 10 20 10 2 0.881 0.263 2 b 21 2 15 0.110 0.216 15 a 22 15 2 0.216 0.110 19 23 4 12 0.881 0.263 12 b 24 12 4 0.263 0.881 4 25 4 12 0.216 0.110 24 26 12 4 0.110 0.216 5 c 27 7 11 0.662 0.069 11 c 28 11 7 0.069 0.662 29 29 7 14 0.829 0.977 14 30 14 7 0.977 0.829 7 d 31 8 13 0.977 0.829 13 d 32 13 8 0.829 0.977 8

Par 1 value exceeding P2- This allows the Next value of the current entry to be filled in and we move on to the next point. It is useful to flag each entry as it is used and to restrict the search at each stage to unflagged ones. To allow for rounding errors, if no suitable entry is found, we reduce P2 by an amount of the same order as the error tolerance for the intersection procedure and search again.

In this step we also check if the underlying graph comprises more than one component. By finding which loops have an intersection point in common (one the reversal of the other), the components of the graph can be determined. In the example, there is only one component.

Step 4 The area of each loop is approximated, taking account of sign. A very crude approximation

has been found to be successful. The area of the polygon whose vertices are (xi, y,) for i = 1, 2 . . . . , n is given by the following expression where the subscripts are taken modulo n:

t l

½ E ( x i Y i + l - - X i + l Y i ) • i=l

This is positive if the points describe the boundary in an anticlockwise sense and negative if not. The area of the loop can be approximated to that of the polygon of the chords of its segments and this has been found to be adequate.

Page 7: Finding the composite outer boundary and holes of a set of closed curves

G. Mullineux / Intersection of closed curves

Fig. 6. More complex example.

57

For each component of the underlying graph, we retain all loops with negative area and the one with the largest positive area. The others can be removed from the data structure. Negative area loops correspond to holes in the overlapped region and largest positive area loops to outside boundary curves. This elimination process works in most simple cases. It fails if one of the original boundary curves completely contains another without intersecting it; this is discussed in Section 6.

The column headed Loop in Table 2 shows the reformed loops for the example. An entry indicates that the loop is retained.

5. Some examples

Fig. 6 shows an example based on combining curves forming the letters C, A and D. Note that the internal holes are formed correctly including one which does not exist within the original letters.

In the case of two non-overlapping closed curves which touch, the method of the last section produces acceptable results. For the examples of Fig. l(a), there are four possible combinations of intersection or non-intersection that could be found. The loops formed in each case are shown in exaggerated form in Fig. 7. Some tidying-up can be achieved by removing segments of very small length and making their end-points identical.

When dealing with touching segments, it seems to be satisfactory to arrange that the intersection algorithm removes duplicate points, so that only one intersection is found. An acceptable outer boundary is then produced.

Fig. 7. Four possible decompositions.

Page 8: Finding the composite outer boundary and holes of a set of closed curves

58 G. Mullineux / Intersection of closed curves

6. Limitations

The definition of a boundary curve given in Section 2 ensures that if dosed curves are nested, then there is alternation between enclosure of 'solid' regions and holes. When two boundary curves are merged, it is possible that nest ing (without intersection) occurs and the alternation is violated. In this case the means for eliminating loops in Step 4 of the method of Section 4 fails. This can be overcome by checking the new sequence of nesting.

We assume in some of the previous discussions that at most two boundary curves intersect at a point. Thus no node in the underlying graph is incident with more than four edges. This assumption is valid for merging just two boundary curves and holds in the majority of cases when dealing with three or more. In other cases the me thod still achieves a decomposi t ion into loops but they may not be genuine outer boundaries. If three segments do intersect in a single point, one option is to move one of them slightly and recalculate the intersections. We can use this extra information to increase or decrease the parameter values originally found at the intersections by amounts small compared with the tolerance error. The previous method then applies.

An alternative is to restrict ourselves to intersections of pairs of boundary curves and deal with three or more by merging the first two, merging the result with the third, and so on.

References

Boehm, W., Farin, G. and I(ahmann~ J. (1984), A survey of curve and surface methods in CAGD, Computer Aided Geometric Design 1, 1-60.

Chan, Y.K., Mullineux, O. and Knight, W.A. (1979), Progress in the computer-aided design and manufacture of hot forging dies, Proceedings: 20th International Machine Tool Design and Research Conference, Birmingham 1979, 29-38.

Harary, F. (1969), Graph Theory, Addison-Wesley, Reading, MA.