Algorithms for computing intersection and union of ... · rithm that compute as union/intersection...

10
Artificial Intelligence for Engineering Design, Analysis and Manufacturing (1997), //, 263-272. Printed in the USA. Copyright © 1997 Cambridge University Press 0890-0604/97 $11.00 + .10 Algorithms for computing intersection and union of toleranced polygons with applications F. CAZALS 1 AND G.D. RAMKUMAR 2 1 iMAGIS-IMAG, BP 53-38041 Grenoble Cedex 09, France 2 Robotics Laboratory, Department of Computer Science, Stanford University, Stanford, CA 94396, USA (RECEIVED April 1, 1996; ACCEPTED November 18, 1996; REVISED January 15, 1997) Abstract Because mechanical operations are performed only up to a certain precision, the geometry of parts involved in real-life products is never known precisely. But if tolerance models for specifying acceptable variations have received a sub- stantial attention, operations on toleranced objects have not been studied extensively. That is the reason why we address in this paper the computation of the union and the intersection of toleranced simple polygons, under a simple and already known tolerance model. First, we provide a practical and efficient algorithm that stores in an implicit data structure the information necessary to answer a request for specific values of the tolerances without performing a computation from scratch. If the polygons are of sizes m and n, and s 1 is the number of intersections between edges occurring for all the combinations of tolerance values, the preprocessed data structure takes O(s) space and the algo- rithm that computes a union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices of the union/intersection and k £ k' ^ s. Although the algorithm is not output sensitive, we show that the expectations of k and k' remain within a constant factor T, a function of the input geometry. Second, we define and study the stability of union or intersection features. Third, we list interesting applications of the algorithms related to feasibility of assembly and assembly sequencing of real assemblies. Keywords: Union; Intersection; Tolerancing; Computational Geometry; Solid Modeling; Randomized Algorithms 1. INTRODUCTION 1.1. Geometric operations for toleranced objects In the life cycle of a part in a manufactured product, say an engine, a piece of furniture, or a toy, etc., its exact geometry can never be described exactly. In fact, mechanical opera- tions are performed only up to as much precision as to en- sure that a feature of the part (for example a vertex) lies within a zone called its tolerance zone. Tolerance models and their role in product design have received substantial interest in the literature (Fang & Briiderlin, 1991; Moller, 1991; Roy et al., 1991; Wang & Ozsoy, 1991; Srinivasan 1993; Walker & Srinivasan, 1994). Most of this work con- centrates on defining models that enable a precise and math- ematically accurate representation of manufacturing defects—imperfect edges and datums, existence of a max- Reprint requests to: F. Cazals, /MAGIS-IMAG, BP 53-38041 Grenoble Cedex 09, France. E-mail: [email protected]. imum material part, etc. But geometric properties have not been looked at extensively, so that it is not known how eas- ily these models can undergo the usual operations of solid modeling. Intersection volumes and surface areas for cyl- inders with tolerances are described in ElMaraghy et al. (1994). Planning the assembly of toleranced products is ad- dressed in Latombe et al. (1997). But basic operations such as intersection, union, convolution, and Minkowski sum of toleranced polygons have not yet been studied. The basic operations among these are the union and the intersection. We address their computation in this paper: given two sim- ple polygons whose geometry (but not topology) can vary according to a simple tolerance model, preprocess the set of all possible intersections between edges of the two poly- gons so that for a particular set of tolerance values their in- tersection or union can be computed efficiently. It should be observed that this is in essence different from D. Sales- in's (1991) work on e-geometries. Indeed, the focus of his work is to build robust geometric algorithms from impre- cise geometric primitives, while we are aiming at perform- 263

Transcript of Algorithms for computing intersection and union of ... · rithm that compute as union/intersection...

Page 1: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

Artificial Intelligence for Engineering Design, Analysis and Manufacturing (1997), / / , 2 6 3 - 2 7 2 . Printed in the USA.Copyright © 1997 Cambridge University Press 0890-0604/97 $11.00 + .10

Algorithms for computing intersection and union oftoleranced polygons with applications

F. CAZALS1 AND G.D. RAMKUMAR2

1 iMAGIS-IMAG, BP 53-38041 Grenoble Cedex 09, France2Robotics Laboratory, Department of Computer Science, Stanford University, Stanford, CA 94396, USA

(RECEIVED April 1, 1996; ACCEPTED November 18, 1996; REVISED January 15, 1997)

Abstract

Because mechanical operations are performed only up to a certain precision, the geometry of parts involved in real-lifeproducts is never known precisely. But if tolerance models for specifying acceptable variations have received a sub-stantial attention, operations on toleranced objects have not been studied extensively. That is the reason why we addressin this paper the computation of the union and the intersection of toleranced simple polygons, under a simple andalready known tolerance model. First, we provide a practical and efficient algorithm that stores in an implicit datastructure the information necessary to answer a request for specific values of the tolerances without performing acomputation from scratch. If the polygons are of sizes m and n, and s1 is the number of intersections between edgesoccurring for all the combinations of tolerance values, the preprocessed data structure takes O(s) space and the algo-rithm that computes a union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number ofvertices of the union/intersection and k £ k' ^ s. Although the algorithm is not output sensitive, we show that theexpectations of k and k' remain within a constant factor T, a function of the input geometry. Second, we define andstudy the stability of union or intersection features. Third, we list interesting applications of the algorithms related tofeasibility of assembly and assembly sequencing of real assemblies.

Keywords: Union; Intersection; Tolerancing; Computational Geometry; Solid Modeling; Randomized Algorithms

1. INTRODUCTION

1.1. Geometric operations for toleranced objects

In the life cycle of a part in a manufactured product, say anengine, a piece of furniture, or a toy, etc., its exact geometrycan never be described exactly. In fact, mechanical opera-tions are performed only up to as much precision as to en-sure that a feature of the part (for example a vertex) lieswithin a zone called its tolerance zone. Tolerance modelsand their role in product design have received substantialinterest in the literature (Fang & Briiderlin, 1991; Moller,1991; Roy et al., 1991; Wang & Ozsoy, 1991; Srinivasan1993; Walker & Srinivasan, 1994). Most of this work con-centrates on defining models that enable a precise and math-ematically accurate representation of manufacturingdefects—imperfect edges and datums, existence of a max-

Reprint requests to: F. Cazals, /MAGIS-IMAG, BP 53-38041 GrenobleCedex 09, France. E-mail: [email protected].

imum material part, etc. But geometric properties have notbeen looked at extensively, so that it is not known how eas-ily these models can undergo the usual operations of solidmodeling. Intersection volumes and surface areas for cyl-inders with tolerances are described in ElMaraghy et al.(1994). Planning the assembly of toleranced products is ad-dressed in Latombe et al. (1997). But basic operations suchas intersection, union, convolution, and Minkowski sum oftoleranced polygons have not yet been studied. The basicoperations among these are the union and the intersection.We address their computation in this paper: given two sim-ple polygons whose geometry (but not topology) can varyaccording to a simple tolerance model, preprocess the set ofall possible intersections between edges of the two poly-gons so that for a particular set of tolerance values their in-tersection or union can be computed efficiently. It shouldbe observed that this is in essence different from D. Sales-in's (1991) work on e-geometries. Indeed, the focus of hiswork is to build robust geometric algorithms from impre-cise geometric primitives, while we are aiming at perform-

263

Page 2: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

264 F. Cazals and G. D. Ramkumar

ing operations on a continuum of exact geometries assumingprecise geometric primitives. But of course, should we haveaddressed the robustness issue, the core problem would havebeen the same since the computations we end up with con-sist in evaluating the sign of algebraic expressions (Sec-tions 2.2.2 and 3.1). The reader is referred to Shewchuk(1996) and Avnaim et al. (1994) for recent developments inthis area.

Figure 1 a shows an example of two toleranced polygonsintersecting in a configuration that may produce zero, one,or two components in the intersection depending on the ex-act tolerance values. Figure lb shows such an example oftwo intersecting comb-like polygons R, and B—one verti-cal and one horizontal with tolerances et and e2 on theirhorizontal and vertical edges, respectively. In this example,the number of components in the intersection can vary from0 to &(m * n). In addition, the components are determinedby different tolerance values, causing an exponential num-ber of topologies. Hence, it is infeasible to represent the to-pologies explicitly.

There is substantial literature related to computing unionand intersection of polygons without tolerances. The inter-section algorithm of Chazelle and Edelsbrunner (1992) canbe used to compute the trapezoidal decomposition of an ar-rangement of edges. This provides a union/intersection al-gorithm of simple polygons that runs in O((m + n)log(m +n) + k). Our method is simpler and thus easier to imple-ment and also is more efficient if \S\ = o(n + m), that is thetolerances space does not admit a superlinear number of in-tersections; we believe this is the case in practical situa-tions. Other previous work in the area of union/intersectioncomputation is an integration of the linear time triangula-tion algorithm of Chazelle (1991) with the linear time mapmerging of Finke and Hinrichs (1995), giving a space-timeoptimal solution. But this involved method does not giveany feedback on the probability of occurrence of say an in-tersection feature, which we call stability in the sequel.

The specification of the problem we address is as fol-lows. The input consists of two simple polygons, referredto as a red polygon of n edges and a blue polygon of m

\ \

•>

\ \

\

- \

\

•7 •''

' ' • ' / ; '

-i .'

—1 —1

11I

(a) (b)

Fig. 1. (a) Intersection of two toleranced polygons, (b) Worst-case exam-ple of intersection.

edges. Each edge has an associated tolerance parameter—denoted r {b) for the red (blue) polygon, or t if the polygoncolor is not specified—defined with respect to a referenceframe attached to its polygon. The relative position of thetwo polygons is determined by those of their respectiveframes. The configuration space 2T has dimension n + mand an instantiation of the two polygons is fully specifiedby a set of tolerance values T= {rl,...,rn,bl,...,bm}. LetSrefer to the set of intersections between pairs of edges oc-curring for all combinations of tolerance values and by ST

those valid only for the input T.

Our results are threefold. First, we preprocess the toler-anced polygons to enable efficient computation of the unionor intersection for a query instance of tolerance values. Thepreprocessing results are stored in an interval-tree like datastructure (Preparata & Shamos, 1985; de Berg et al. 1996)from which an instance of the intersection or union is com-puted in time O((n + m)log|S| + k' + k log/c), where k isthe number of vertices of the union or intersection and k' isthe cardinality of a superset of the output vertices, with k sk' ^ \S\. This term k' causes the complexity to be not out-put sensitive; however, this aspect seems necessary becausethe space of intersection of two toleranced edges only ad-mits a complicated definition as a semialgebraic set in di-mension six defined by four inequalities involvingpolynomials of degree two. But we show that the expected run-ning time of our algorithm is output-sensitive by proving thatthe expectations of k and k' remain within a constant factorT, a function of the input geometry. Second, we use our datastructure to report the set of all possible "local" topologies ofthe union and intersection of the polygons. Third, we presentseveral straightforward applications of our algorithms to fea-sibility of assembly and assembly sequencing.

1.2. Paper overview

In Section 2 we introduce the tolerance model and study theintersection of the so-called toleranced edges, the basic prim-itive. In Section 3 we present the algorithm that outputs SrfromS. In Section 4 we show how to perform the intersection/union operation from the set ST. In Section 5 we discuss thestability of intersection features. In Section 6 we consider threeapplications of the toleranced intersection, and in Section 7we list some outstanding problems and conclude.

2. TOLERANCE MODEL

2.1. Toleranced polygon

By toleranced polygon, we mean a simple polygon with anattached coordinate system {p,i,j) (Fig. 2a) and each edgeof which is defined by a triple (8, [a, b]) as follows: the nor-mal to the line supporting this edge makes an angle 8 £[0,2TT) with the frame attached to the reference point of thepolygon; the distance between the edge and the polygon ref-

Page 3: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

Tolerance polygons with applications 265

erence point is allowed to span the interval [a,b], wherea > 0, b s a. The model assumes that the parameter 6 isconstant; in more general models 0 can have a tolerance rangeas well. An edge is therefore characterized in (p,i,j) by theequation AT cos 6 + ysind - t = 0 with t £ [a,b].

For a given polygon, these tolerance zones should be smallenough so that all instances of the polygon have the sametopology. A sufficient condition is that no vertex falls intothe intersection of more than two stripes spanned by theedges.

In this model, the domain spanned by each edge is a trap-ezoid, as indicated in grey on Figure 2b. In fact, the linessupporting the two edges that have extremal values deter-mine the parallel sides of the trapezoid, and the two othersides correspond to the maximal values of the two con-nected edges. More precisely, this trapezoid can be sub-divided into three regions as indicated on Figure 2b:

• the C—domain: whatever value /, €E [a,,fc,] may have,the /th edge crosses this domain all the way (C standsfor compulsory),

• the 0—domains 0, and Or: a point lying on the ith edgemight not be attained because of the tolerance valuesof the adjacent edges {O stands for optional, / and r forleft and right). It is for example the case of the point Pin Or on Figure 2b.

This trapezoid is called the toleranced edge in the sequel ofthis paper, and is denoted with capital letters. For example/?, refers to the ith toleranced edge of the red polygon. It isimportant to observe that it depends on three variational pa-rameters: the main parameter /,-, and the two connected pa-rameters r,_, and ti+l. The tolerance model we use wasintroduced in Latombe et al. (1997).

2.2. Intersection of toleranced edges

2.2.1. Problem statement

In dealing with geometric operations between tolerancedpolygons, a crucial step consists in intersecting tolerancededges. Given two toleranced edges, the status of their inter-section is one of the following: 1) they never intersect, 2)

they always intersect, and 3) they intersect conditionally tothe variational parameters involved. Intersections corre-sponding to the cases 2) and 3) are referred to as compul-sory and optional, respectively.

As already observed, each toleranced edge depends onthree parameters. The intersection between edge i of the redpolygon and edge j of the blue polygon therefore dependson the six parameters {ri_l,ri,ri+l,bJ_l,bj,bj+l}. We noteVjj the corresponding subspace of 2T. If an intersection ex-ists, it belongs to the polygon Iy intersection of the two tol-eranced edges. This polygon is shown in grey on Figure 3a(see also Fig. 5). Compulsory intersections require that /,-,lies within the intersection of the C — domain of the toler-anced edges and that any of its section along the directionof a main parameter spans the whole domain of this param-eter. This is the case on Figure 3a for edges Rt and Bj. Onthe other hand, finding a simple description of optional in-tersections is more laborious. Consider Figure 3b, where thethree edges fl,,Ri+\, andBj have non-null tolerances zones—all the other edges, that is, fl,_,, Bj_,, Bj+ { being reduced toline segments. The three dashed lines correspond to in-stances of these edges for the tolerance values ri = x, rj+, =y and bj = z. In this configuration, edges /?, and Bj intersectsat point /. But in addition to x and z, I also depends on y.Indeed for any value of y smaller than the one displayed, Bjintersects Ri+l, but not /?, anymore. It turns out that the con-dition under which the intersection occurs cannot be easilyfound by a geometric analysis of the edges interaction, whichaccounts for an algebraic computation of v^.

2.2.2. Algebraic specification of tolerancedintersection vertex

LEMMA 1. Let e, and e7 be two edges delimited by thevertices («,, y,) and (u2, v2), respectively, and let (a,, a2),(a2, a3), (£,, b2), (b2, b3) be the variational parametersthese vertices depend on. Then, the subset of these param-eters such that e, and ey intersect is defined by four qua-dratic inequalities in the space of 6 tolerance values: •Proof: Edges e, and e, intersect iff the line supporting e;

divides the edge ej and vice-versa (see Fig. 4). Let Det(w, v,w) represent the signed area of the triangle uvw defined byvertices u = (ux, uy), v = (vx, vy), and w = (wx, wy):

-AT/ _\ \_

(b)

Fig. 2. (a) Toleranced polygon, (b) Edge domain.

Page 4: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

266 F. Cazals and G.D. Ramkumar

B:,

B-j-l R-.

Rss-i

(b)

Fig. 3. Edges intersection.

j+l

1 1 1

<*x vx wx

« V Vy Wv

The condition Det(u, v, w) > 0 requires that u, v, w are incounterclockwise order on the plane. The line supportingedge e, divides the edge e, iff u2 and v2 are on the oppositesides of the line supporting e,, so that the conditions soughtare

Det(u2,U|,V|)Det(f2,U|,.f|) < 0 and

Det(u,,«2,(;2)Det(i>|,«2,<;2) < 0 ($)

Each of the vertices ux, v,, u2, v2 is a linear function of thetolerance parameters of the two edges intersecting to pro-duce it. The set of constraints defines a volume bounded byquadratic surfaces in the space of 6 tolerance values. Be-cause the edges preserve their orientation under variation oftolerance parameters, requiring the two edges to intersect istantamount to fixing the sign of each determinant (a stron-ger condition than above). •

To illustrate the previous computation, we implementedcondition $ under Maple to run some experiments. For ex-

! edge i-1

edge ,'

edge j - ledge j + i

edge i

\ """••-- edge i + 1

Fig. 4. Intersection conditions.

ample, the configuration of Figure 3b, which is defined asfollows

/?,_, := {Pi,a\ £ [5.,5.]); /?, := (Pi/2,a2 £ [5.,11.]);

/?,-+, := (P//4,a3 G [4.5 * sqrt(2),1.5 * sqrt(2)])

Bj-i := {Pi/2,b\ e [3.,3.]); Bj•:= (0,b2 E [l.,6.]);

leads to the two conditions

(b\ - a2)(-a2 a\)2{bl - al) < 0

2 - b2)(-b3 + b\)2(b2 + a\) < 0.

As this example shows, this space is not linear and actu-ally not even convex. Indeed, it is easily checked that thetwo following points />, = [5.; 6.; 8,48.; 3.; 6.; 14.] andP2 = [5.; 7.; 9.19; 3.; 6.; 14.] belong to vtj but not theirmiddle. Computing the volume p^ of v^ cannot be per-formed using simple techniques as those of Lawrence (1991)for convex polytopes and this issue will be addressed in Sec-tion 5.1 in dealing with the stability of the intersection com-ponents. Moreover, storing v^ in a data structure to efficientlyselect the relevant intersections with respect to a particularinput of tolerances remains an open question.

2.2.3. Approximate representation

For these reasons, we address the problem of finding anapproximate representation of vtj as an hyper-rectangle v'V]

of volume /?,y such that all the points located in this hyper-rectangle are candidates with a high probability to be a trueintersection between the two edges.

As intersection of two four-sided polygons each depend-ing on at least three parameters, /,-, is at most eight-sidedand depends on at most six parameters. Moreover, it is con-vex because the toleranced edges are convex. If k is one of

Page 5: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

Tolerance polygons with applications 267

the six parameters involved in the intersection of edges iand j , then let stripek be the minimal closed stripe of theplane with sides parallel to the kth parameter direction andcontaining /,-,-. The two lines defining a stripe correspond totwo values in the variational space of the corresponding pa-rameter, possibly out of the range [ak,bk] so that it is pos-sible to reduce any stripe to its intersection with the tolerancezone of its parameter. Let rsk be the bounds of the reducedstripe in the variational zone of parameter k. It is also pos-sible that rsk = [ak,bk] in which case the corresponding pa-rameter is called useless because an intersection can occurfor any of its value. If the opposite holds, it is called useful.

An obvious necessary condition on the main parametersfor an intersection to exist is that r, G rs, and b} G rsj. See,for example, Figures 5a and 5b. For the optional param-eters, the situation is more involved. First, observe that auseless parameter can be discarded because we are inter-ested in the intersection of edges i andy and it does not carryany information. It is the case of £>,_, on Figure 5a. Second,the notion of minimal stripe enclosing Itj is not sufficientany more: consider the parameter ri+ { on Figure 5c and thetwo vertical lines Vu V2 enclosing /,-,. If the (/ + l)th edgelies to the left of Vu no intersection is possible. But if it liesto the right of V2 the intersection is possible. Therefore, fora connected parameter, the correct stripe is the stripe en-closing Ijj whose upper bound is extended to this parametermaximal value.

In summary, each of the six parameters involved in theintersection of edges i and j produces a range in its toler-ance zone. Such a range might be useless if it spans the wholetolerance zone, and in this case we discard it for a con-nected parameter. This leads to a representation of /,-,- as ahyper-rectangle v\j of dimension at least two and at mostsix that partitions vtj in two: the set of points that fulfill anecessary condition for the edges to intersect, and its com-plement.

2.3. Computing the intersection of toleranced edges

We use a traditional Bentley-Ottman style algorithm to com-pute the intersection of toleranced edges. This algorithm thatruns in O((m + n + s)log(ra + n)) for line-segments isdescribed in Preparata and Shamos (1985) and can be eas-

ily modified for trapezoids as follows. The idea consists inparsing the edges from left to right, the events to be handledbeing the insertion (deletion) of a new edge when its left-most (right-most) point is found. To get the ordering fromleft to right, we just have to sort the n + m left-most andright-most points. Now, for a given abscissa x, we need toknow which are the other edges in the y-range of the edgeprocessed at this abscissa. This can be done using the inter-val tree data structure of Preparata and Shamos (1985) andde Berg et al. (1996). A precise analysis should, however,be performed to state a precise complexity for this Bentley-Ottman sweep applied to trapezoids. But this is not that im-portant because this step is a preprocessing.

3. SELECTION OF RELEVANTINTERSECTIONS

3.1. Selecting a subset of events

Let T= {r,,..., rn, b,,..., bm } be an instantiation of the twoinput polygons. Before we can get the topology of theintersection/union, we must select the subset ET of intersec-tions that are valid for the particular input T. The problemwe have to face here is that each /,-, depends on at most sixparameters while the whole space has dimension m + n.Devising an efficient data structure to retrieve these smalldimensional subspaces is a challenging problem. An easyway to get around it is therefore to allow the selection pro-cess to operate in two steps as follows: first select a subsetEAT C E and then derive ET from EAT.

This strategy allows us to represent /,-, using the hyper-rectangle v'jj described above. For a given th finding allthe v'jj containing it reduces to a point-in-segment enclosuretest. A suitable data structure to perform this is an intervaltree (Preparata & Shamos, 1985; de Berg et al. 1996) foreach parameter, which leads to a forest of interval trees forthe n + m parameters. But as noticed in Section 2.2 someparameters appearing in v'y do not express any constraintbecause their range is equal to their tolerance zone. We storethem in linked lists instead of the interval tree. More pre-cisely, each main parameter k involved in the description ofany v'y is stored as follows:

stripe

Bj+l stripe^

(a) (b) (c)

Fig. 5. Intersection and stripes.

Page 6: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

268 F. Cazals and G.D. Ramkumar

• If it is useful, it is stored in its interval tree ITk. In ad-dition, each such range is given a pointer to the v'y itcomes from,

• If it is useless but is involved in a compulsory inter-section, it is stored in the linked list CLk with a pointerto the p'ij it comes from,

• If it is useless and is involved in an optional intersec-tion, it is stored in the linked list OLk with a pointer tothe v'jj it comes from.

An example configuration of the forest of interval treesis shown in Figure 6. Observe that we have not stored theconnected parameters, but they are accessed through thepointer from the main parameters to the v\j they belong to.

We now describe below the selection process that leadsfrom E to ET.

Selection algorithmfor i: = 1 to n + m do

(1) Add to ET the intersections referenced by CLi

still not accessed(2) Add to ET the relevant intersections referenced

by OLj still not checked(3) Add to £ r the intersections referenced by the seg-

ments of IT( containing /,, not accessed and rel-evant

od

First observe that any v'y involves two main ranges storedeither in a list or an interval tree. Each intersection or hyper-rectangle can thus be accessed by either of the two pointers.We assume that the first access sets a flag. Now, there aretwo kinds of intersections: compulsory and optional, of whichthe latter have to be checked. If more than two parametersare involved in the description of its v\j, the first step is tocheck that the connected parameters fulfill the required con-ditions. If so, the intersection has to be computed and a checkhas to be performed to see if it belongs to the two line seg-

0

E

E

Edges

Intervaltrees

Set ofevents

Subset fora tolerance

Fig. 6. Selecting active edges.

ments supported by the main parameters. These tests shouldbe applied in this order because of their respective compu-tational costs.

3.2. Analysis

Let St be the cumulated size of the ith interval tree and theassociated lists. Selecting and reporting all the segmentscontaining tt in these structures costs O(log*, + kj) withk\ the output size. The first term sums to 2"=im0(log.s,),which is easily seen to be smaller than (n + m) log s withs = X"=i" Si. And the second one sums to it' + k with k' =2"^im kj and k = 2"^T *i because the relevance of each in-tersection has to be checked.

An important task is to compare the relative values of kand k'. Because our data structure is intended to processseveral queries, it would be nice to have an amortizationphenomenon over these queries. Suppose we have to pro-cess r queries, and for any query i in \..r and any intersec-tion j in \..s, let e'jj be the random variable defined as 1 ifthe intersection j is selected at stage i through the IT datastructure and 0 otherwise. Also, let etj be a random variabledefined as 1 if the previous intersection is not discarded and0 otherwise. Of course, ej, = 0 implies e,-, = 0, and a mea-sure of the IT data structure goodness to select the relevantintersections is the ratio of the number of intersections keptover the number of intersections initially selected. Moreprecisely:

DEFINITION 1. The acceptance rate T of intersections se-lected with the interval-trees is defined as the ratio of theexpectations of the number of events kept over the numberof events initially selected, that is

r = .

And we have

LEMMA 2. The value of T is given by 2/>;/2/>j withPj the volume of the subset of parameters defining the jthintersection, andp) the volume of the approximation of thissubset:Proof: For any;', 2,-eJ/ and 2,-s,-,- are distributed as binomialrandom variables of parameters B(r,pj) and B{r,p}), respec-tively, whence the result •

It is difficult to state precisely which value T might have.But because the only case where Pj/pj = 0 is when theedges involved in that intersection are parallel, while con-figurations such as the one Figures 3a and 3b, respec-tively, correspond to ratios of 1 and .549 (see Section 5.1),it is reasonable to say that k' and k are within a constantfactor.

Another interesting problem is whether or not it is pos-sible to apply the paradigm of divide-and-conquer to thisselection process. The answer seems to be negative. Indeed,

Page 7: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

Tolerance polygons with applications 269

unlike for d-dimensional query using say a ^-dimensionalsearch tree where we start by looking at the first direction,then proceed along the second one for the subset selected sofar, and so on, the edges independence make this processimpossible here.

4. INTERSECTION/UNION

We now show how to reconstruct the intersection or the unionfrom the intersection events. Decisions have to be made atthe intersection points only because by following the bound-ary of a polygon we eventually end up on an edge involvedin an intersection! However, at any vertex of the intersec-tion it is clear from the local structure which edge must bepursued next, as shown in Figure 7a. The only informationwe are missing when following an edge is therefore the la-bel of the next intersection of that edge with the second poly-gon. For example, on Figure 7b, after deciding to followedge 1 after the intersection /, / ; we must know that the nextintersection to be analyzed is /, h. This is not straightfor-ward because what we get from the selection process of Sec-tion 3.1, is for a given edge a sequence of edges of the secondpolygon. Ordering these intersections requires running a stan-dard sorting algorithms which takes O(k\ogk) time for kintersection points.

It should also be noticed that computing the sequence ofintersections along the edge given the sequence along thesecond polygon is what does the so-called Jordan sortingalgorithm described in Fung et al. (1990). Unfortunately,this algorithm does not apply here because the ordering ofthe segments imposed by the interval tree data structure (deBerg et al., 1996) is incompatible with the lexicographicorder along the polygon. But had this algorithm been ap-propriate, the complexity gain would have been minor—actually, the O constant.

Once the previous ordering is known, getting a compo-nent of the union or the intersection consists in enumeratingits vertices applying the rules explained above. And findingall the components consists in iterating the previous pro-cess until all the intersections have been used.

5. STABILITY OF INTERSECTION FEATURES

In this section, we study the stability of features of the in-tersection. Features of the union can be handled similarly.There are obviously two kinds of features: vertices, and com-ponents that can involve several vertices. For each of these,stability refers the probability of occurrence, with the dis-tinction of stable features that always exist, and optionalfeatures otherwise.

5.1. Vertices

Checking if a vertex is compulsory is easily done when com-puting the approximation v'y of v^. If the vertex is optional,a measure of its stability is the volume ptj of vtj. Computingthe exact value of this volume seems difficult since we donot have a description of its boundary. Getting an (e,S) ap-proximation Pij of ptj using a Monte Carlo method [seeDyer et al. (1989), Motwani & Raghavan (1995), Dagumet al. (1995)] is also an open problem since vtj might in gen-eral be nonconvex. However, from a practical point of view,the following boot-strapping algorithm may give satisfac-tory results:

1. First, get a rough estimate /?,-, of pi} as the fraction ofpoints satisfying condition $• over a sample of "rea-sonable" size uniformly drawn in [0,l]6,

2. Second, plug p,y into the estimator theorem (Theorem11.1) of Motwani and Raghavan (1995), which in turngives the sample size such that /?,-, is accurate within afactor e with a probability greater than 1 — S.

For example, on the configuration of Figure 3b, an estimateon a sample of size 1000 gives pfJ = .543 while the correctedvalue according to a sample of size 11,000 given by the es-timator theorem for a (.05,.05) approximation is p^ = .549.

5.2. Components

Let a purple vertex be the intersection of a red edge with ablue edge, and let a component be defined as a sequence of

b

1

/ a

LV / ̂e

f

intersection

(a)

3

(b)

Fig. 7. (a) Local analysis, (b) Computing the intersection.

Page 8: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

270 F. Cazals and G.D. Ramkumar

1 2

(b)

• b c d

Fig. 8. Components, stable vertices, and W B graph.

red, blue, and purple vertices forming a simple polygon in-tersection of the original polygons. Extending this defini-tion is tricky. Indeed, as depicted in Figure 8a, a componentcan be stable while none of its vertices are—when the tri-angle grows downward, edge b is not intersected anymoreby edges 1 and/or 2. In a similar way, a component can bestable while none of its edges are so: in Figure 9a and 9b,by continuously transforming the leftmost configuration tothe rightmost one, we go from a configuration where theintersection consists of the leftmost edge of the vertical rect-angle together with the rightmost edges of the rotated square,to a configuration involving the rightmost edge of the rect-angle and the leftmost edges of the square. For these rea-sons, we constrain the previous definition to a fixed sequenceof edges from the two polygons. For example in Figure 8,there are four different components, {2,b,\}, {2,b,c,l},{2,a,b,\}and{2,a,b,c,\}.

Enumerating these components is different from enumer-ating the set of all topologies of the intersection. Indeed, thelater reflects the local interference between red and blueedges, while the former is the cartesian product of these.We therefore focus our attention on the computation of com-ponents involving a given intersecting edge. We do not claimany bound on the running time of the algorithm and justsketch it here. Let ^ T ^ be the intersection vertices graphthat is the oriented graph defining the possible intersectionsbetween edges of the two polygons as well as the connec-tivity between the red and blue edges. Figure 8b depicts theS'VS for Figure 8a. The convention used to assign direc-tions to edges of $ T $ is the following: edge u points toedge v if a turn from u into v has interior to the left. Thebasic idea of the algorithm consists in considering each cy-

(a) (b)

Fig. 9. Components and stable edges.

cle of the ^Y^ and checking if it corresponds to a validcomponent. But any cycle is not a good candidate becausethe following constraints need to be satisfied:

• Each turn must have the interior to its left,

• If an edge e of a polygon, say the blue edge, appearsseveral times in the labeling, the red intersecting edgesmust respect the ordering along the blue edge,

• The labeling must respect as much as possible, the "lo-cality" of the intersection sought. For example, on Fig-ure 8b, the word 2abc can be expanded as 2abc\ or2abcd. But 2abcd is obviously not valid. It is not clearhowever how to use this geometric information whilegenerating good candidates cycles.

6. APPLICATIONS

We briefly examine in this section two applications of thecomputations described so far and list another one that re-quires Minkowski operations to be defined for tolerancedpolygons. Because we do not make any contribution to theseexamples, the reader is referred to the original papers forthe details.

6.1. Feasibility of assembly of two parts

A simple but instructive real-life example on how usefuloperations between toleranced objects is the following onefrom ElMaraghy et al. (1994); a fly fishing reel consists ofa spool mounted on high-quality bearings spinning arounda center pin assembly. The hole in the center of the reel hasto be machined smaller than the bearing so that when thereel is pressed in place interference is observed. Performingthe intersection operations between the different parts of thereel (on a cross section so that cylinders are represented asrectangles) therefore turns out to be very useful; it gives thetopology of the interference zones, which provides feed-back to the designer on how precisely the parts have to bemilled depending on the type of material used (aluminumin this case).

6.2. Assembly sequencing

As already mentioned in the introduction, results were ob-tained recently for assembly sequencing of toleranced as-semblies (Latombe et al., 1997). Without mentioning thedetails, the authors propose two algorithms:

• one that lists all the assembly sequences that are al-ways feasible, whatever the tolerance values are; and

• another one that lists the sequences that may be feasi-ble only for some combinations of the parameters.

A failure of the second algorithm means that no instanceof the product is assemblable, which in turn implies thatthere is a collision between two parts, or that the product is

Page 9: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

Tolerance polygons with applications 271

"intrinsically" infeasible for assembly. In the first case, ap-plying our intersection algorithm to the toleranced poly-gons gives the parameters involved in the intersection. Thisis important because paying more attention to these parts inthe manufacturing process, that is, reducing the tolerancezones, might solve the problem. Handling the second caseis much more difficult and goes beyond the scope of thispaper.

It should be observed that using polygonal models as in-put for the union and intersection operations is not restric-tive because most of the contacts between real products partsare either cylindrical or between flat surfaces.

6.3. Collision detection

It is well known that one of the most elementary operationsin robotics consists in computing the Minkowski differencebetween the robot and the obstacles, which gives the spaceof intersection free translations of the robot. In particular,in configurations that contain degenerate inputs, such as con-tacts, tangencies, etc., collision checking on the tolerancedobjects may give additional information.

7. CONCLUSION

In this paper we presented data structures and algorithmsfor computing the intersection and the union of simple poly-gons with tolerances on edges. Given two polygons of sizesn and m whose edges give rise to .s intersections for all thecombinations of the tolerances values, our algorithm pre-computes in time O((m + n + s)\og(m + n)) a search struc-ture that takes O(s) space. Given specific values for thetolerances, we use the structure to output the specific inter-section or union in time O((m + n)\ogs + k' + klogk),where k is the output size and k ^ k' ^ s. Although thealgorithm is not output sensitive, the expected values of kand k' remain within a constant factor r, a function of theinput geometry. The algorithm is easy to implement, practi-cal, and we believe it works well for realistic input instances.Also, several straightforward applications to feasibility of as-sembly and assembly sequencing are described.

Many difficult issues still remain. First, directly storingthe semialgebraic set describing the intersection of toler-anced edges may enable more efficient processing of unionand intersection queries. Second, getting an (e,8) approxi-mation for the volume of the semialgebraic set is an openquestion.

At last, the problems remain unaddressed for the case whenthe tolerance model is extended to include angles on thepolygons. There is also scope for future work on computingconvolutions and Minkowski sums of toleranced polygonalobjects.

ACKNOWLEDGMENTS

Work on this paper was done while F. Cazals was visiting the Ro-botics Laboratory at Stanford University and was supported by

Matra Datavision. G.D. Ramkumar is supported by NSF. Part ofthis work has also been supported by NSF/ARPA grant IRI-9306544. The authors wish to thank Cyprien Godard and DannyHalperin for insightful discussions, as well as the reviewers andthe editors for helpful comments.

REFERENCES

Avnaim, F., Boissonnat, J.-D., Devillers, O., Preparata, F., & Yvinec, M.(1994). Evaluating signs of determinants using single-precision arith-metic. Research Report 2306, INRIA, BP93, 06902 Sophia-Antipolis,France.

Chazelle, B. (1991). Triangulating a simple polygon in linear time. Dis-crete Comput. Geom. 6, 485-524.

Chazelle, B., & Edelsbrunner, H. (1992). An optimal algorithm for inter-secting line segments in the plane. J. ACM 39, 1-54.

Dagum, P., Karp, R., Luby, M, & Ross, S. (1995). An optimal algorithmfor Monte Carlo estimation (extended abstract). 36th Annu. Symp.Found. Comput. Sci. pp. 142-149.

de Berg, M., et al. (1996). Computational geometry by example. StanfordUniversity Press (draft version).

Dyer, M, Frieze, A., & Kannan, R. (1989). A random polynomial timealgorithm for approximating the volume of convex bodies. A CM STOC,pp. 375-381.

ElMaraghy, W.H., et al. (1994). Intersection volumes and surface areas ofcylinders for geometrical modelling and tolerancing. CAD 26(1), 29-45.

Fang, S., & Briiderlin, B. (1991). Robustness in geometric modeling—tolerance-based methods. Computational Geometry—Methods, Algo-rithms and Applications: Proc. Int. Workshop Comput. Geom. CG '91,vol. 553 of Lecture Notes in Computer Science, pp. 85-101.

Finke, U., & Hinrichs, K. (1995). Overlaying simply connected planar sub-divisions in linear time. 11th ACM Symp. Comput. Geom.

Fung, K.Y., et al. (1990). Simplified linear-time Jordan sorting and poly-gon clipping. 1PL 35.

Guibas, L.J., Salesin, D., & Stolfi, J. (1989). Epsilon geometry: Buildingrobust algorithms from imprecise computations. Proc. 5th Annu. ACMSymp. Comput. Geom., pp. 208-217.

Latombe, J.C., Wilson, R.H., & Cazals, F. (1997). Assembly sequencingwith toleranced parts. Computer Aided Design 29(2).

Lawrence, J. (1991). Polytope volume computation. Mathematics of Com-putations 57(195), 259-271.

Moller, B. (1991). Tolerances in product modelling. Informatik, Informa-tionen Reporte 1991(5), 4-52.

Motwani, R., & Raghavan, P. (1995). Randomized algorithms. CambridgeUniversity Press, New York.

Preparata, F.P., & Shamos, M.I. (1985). Computational geometry: An in-troduction. Springer-Verlag, New York.

Roy, U., Liu, C.R., & Woo, T.C. (1991). Review of dimensioning and tol-erancing: Representation and processing. Computer Aided Design 23(7),466-483.

Salesin, D.H. (1991). Epsilon geometry: Building robust algorithms fromimprecise computations. PhD thesis, Stanford University.

Shewchuk, J.R. (1996). Robust adaptive floating-point geometric predi-cates. Proc. 12th Annu. ACM Symp. Comput. Geom., pp. 141-150.

Srinivasan, V. (1993). Recent efforts in mathematization of asme/ansiyl4.5m standard. 3rd C1RP Seminars on Computer Aided Tolerancing.

Walker, R.K., & Srinivasan, V. (1994). Creation and evolution of the asmey 14.5.1 standard. Manufact. Rev. 7(1).

Wang, N., & Ozsoy, T.M. (1991). A scheme to represent features, dimen-sions, and tolerances in geometric modeling. J. Manufact. Syst. 10(3),233-240.

F. Cazals was born in 1969 in Toulouse, France. He grad-uated in 1992 from Institut National Agronomique Paris-Grignon in agronomy and from Ecole Normale Superieureand Ecole Polytechnique in theoretical computer science.In 1995-96, he spent 16 months visting the Robotics Lab-

Page 10: Algorithms for computing intersection and union of ... · rithm that compute as union/intersection from it takes O((n + m)log s + k' + k log k) time, where k is the number of vertices

272 F. Cazals and G.D. Ramkumar

oratory at Stanford University, Stanford, CA. In 1997, hecompleted a Ph.D. in Computer Science from the Univer-sity of Paris VII, Paris. He is now a Postdoc at INRIA Roc-quencourt in the Algorithms Project. His research interestsinclude data structures, analysis of algorithms, computa-tional geometry, and computer graphics.

G.D. Ramkumar is a Researcher working in the R&DDivision of Hitachi America, Ltd., in Santa Clara, CA. He

did a Ph.D. at Stanford University in the Departmentof Computer Science, 1996. Prior to that he received anundergraduate degree of Bachelor of Technology, also inComputer Science, at the Indian Institute of Technology(IIT), Madras, India, 1990. At ITT, he received the Presi-dent of India gold medal for having the best academic recordamong all undergraduates. He has published several pa-pers in the areas of algorithms, computational geometry,and data mining.