Computing the Fréchet distance between piecewise smooth curves
Abstract
We consider the Fréchet distance between two curves which are given as a sequence of m+n curved pieces. If these pieces are sufficiently well-ehaved, we can compute the Fréchet distance in O(mn log(mn)) time. The decision version of the problem can be solved in O(mn) time.
Full text
Computing the Frehet Distane b etween Pieewise Smo oth Curves ? G unter Rote Freie Universitat Berlin, Institut fur Informatik, Takustrae 9, 14195 Berlin, Germany, roteinf.fu-berlin.de. Abstrat We onsider the Frehet distane between two urves whih are given as a sequene of m + n urved piees. If these piees are suÆiently well-b ehaved, we an ompute the Frehet distane in O ( mn log ( mn )) time. The deision version of the problem an b e solved in O ( mn ) time. 1. Intro dution The Frehet distane is a distane measure b etween urves. Denition 1 (Frehet distane) Let f : I = [ l I ; r I ℄ ! R 2 and g : J = [ l J ; r J ℄ ! R 2 be two planar urves, and let kk denote the Eu- lidean norm. Then the Frehet distane Æ F ( f ; g ) is dened as Æ F ( f ; g ) := inf : [0 ; 1℄ ! I : [0 ; 1℄ ! J max t 2 [0 ; 1℄ k f ( ( t )) g ( ( t )) k : where and range over ontinuous and nondereasing reparameterizations with (0) = l I , (1) = r I , (0) = l J , (1) = r J . In ontrast to other ommon distane measures like the Hausdor distane, the Frehet distane resp ets the one-dimensional struture of the urves and do esn't just treat them as a point set. The study of the Frehet distane from a omputational p oint of view has b een initiated by Alt and Go dau [2℄. The deision problem is the problem to deide, for a given " , whether the Frehet distane b etween two urves is at most " . Alt and Godau [2℄ treated the ase of two polygonal urves. For two urves of m and n piees, resp etively, they showed how to solve the deision problem in O ( mn ) time and the optimization prob- ? Partially supported by the IST Programme of the EU as a Shared-ost RTD (FET Op en) Pro jet under Contrat No IST-2000-26473 (ECG|Eetive Computational Geometry for Curves and Surfaes). lem in O ( mn log( mn )) time. Some related problems have also been onsidered, like minimizing the Frehet distane under translations [3℄, or a generalized Frehet distane b etween a urve and a graph [1℄. In all ases, however, the ob jets are pieewise linear. In this pap er, we explore the Frehet distane b etween more general urves. We assume that eah input urve is given as a sequene of smo oth urve piees that are\suÆiently well-b ehaved", suh as irular ars, parab oli ars, or some lass of spline urves. Our algorithm will p erform ertain op erations on these urves, like interseting them with a irle. We will show that the ombinatorial omplexity , i. e., the number of steps, for solving the deision problem is not larger than for p olygonal paths, O ( mn ). The omplexity of the individual op erations (the algebrai omplexity ) dep ends of ourse on the nature of the urves. Under the stronger assumption that the urves onsist of algebrai piees whose degree is bounded by a onstant, we an solve the optimization problem in O ( mn log( mn )), thus mathing the running time for the polygonal ase. The elementary op erations, however, are algebrai op erations of higher degree. We assume that eah urve is given as a sequene of piees whih are onneted at their endp oints. Every piee is a smo oth urve of lass C 2 , i. e., the urvature is dened everywhere and varies ontinuously within a piee. We will not make any assumptions how the urves are given; it is only imp ortant that the neessary geometri op erations 20th EWCG Seville, Spain (2004)
20th Europ ean Workshop on Computational Geometry an b e arried out. We need urves whose turning angle is bounded by . Curves of larger b ounding angle must b e sub divided. For solving the deision problem with parameter " , we sub divide the urve at all points where the urvature is 1 =" , in order to ensure that in eah piee of the urve, the urvature is either uniformly smaller or bigger than 1 =" . We have omitted most pro ofs, but we state one auxiliary lemma in order to illustrate the elementary arguments on whih the results are based. Lemma 2 Let f be a smooth urve of turning angle at most , and let by a irle of radius r . (a) If the urvature of f is at most 1 =r everywhere, the urve an interset at most twie. If it intersets twie, then its endpoints lie outside or on the boundary, and the midd le piee between the two intersetions lies inside . (b) If the urvature of f is at least 1 =r everywhere, the urve an interset at most twie. The full version of this pap er is available as a tehnial rep ort [5℄. 2. The Free Spae Diagram The main to ol of the algorithm is the free spae diagram whih was intro dued in [2℄. It is a twodimensional representation of all pairs of p oints on the two urves, together with the identiation of those pairs whih are loser than " . Denition 3 Let f : I ! R 2 , g : J ! R 2 be two urves, I ; J R . The set F " ( f ; g ) := f ( s; t ) 2 I J : k f ( s ) g ( t ) k " g denotes the free spae of f and g . the partition of I J into the free spae and its omplement is al led the free spae diagram . Points in F " are alled feasible or free , and they are usually drawn in white. The other p oints are alled forbidden points or obstales , see Figure 1. The following simple observation from [2℄ is ruial. Lemma 4 Let f : I = [ l I ; r I ℄ ! R 2 , g : J = [ l J ; r J ℄ ! R 2 be two urves. Then Æ F ( f ; g ) " if and only if there exists a urve within F " ( f ; g ) from ( l I ; l J ) to ( r I ; r J ) whih is monotone in both oordinates. 2 As f and g onsist of several piees, the free spae diagram deomp oses naturally into a grid of retangular el ls . ε f g Fig. 1. Two p olygonal urves and their free spae diagram. The sale of the free spae diagram is 50% redued with resp et to the urves. 3. Critial p oints We regards as ritial points on the b oundary of F " those p oints whih are lo al extrema in the horizontal or vertial diretion. There are eight lasses of ritial p oints, shown in Figure 2. W+ N+ S+ E+ N− E− S− W− Fig. 2. The eight types of ritial p oints. N , S , E , W refers to the diretion in whih the p oint is extreme, and the sup ersript tells whether the area in this diretion is feasible (+) or forbidden ( ). In terms of the urves f and g , these p oints orresp ond to situations where a irle of radius " around a point of one urve is tangent to the other urve. For example, a ritial point of typ e W + o - urs in the situation where g touhes the irle of radius " around a p oint x on f from inside. As x pro eeds further away from g , a portion of g b egins to stik out from .
Marh 25-26, 2004 Seville (Spain) 4. The struture of a single ell The free spae may b e arbitrarily ompliated even inside a ell. For example, if " is very small, F " will ontain isolated islands of free spae for all intersetions b etween f and g . However, we will show that the reahable p oints an b e omputed in a onstant numb er of elementary geometri operations. We have sub divided the urves, and onsequently, the parameter intervals I and J into m and n piees, resp etively. Corresp ondingly, we ut the retangle I J into mn ells. On the b oundaries of these ells, we ompute all p oints whih are reahable from the lower left orner ( l I ; l J ) of the retangle by a path in free spae whih is monotone in b oth diretions. We do this inrementally from the lower left ell to the upp ermost right ell. A vertial line in the free-spae diagram orresp onds to a xed p oint f ( s ) on f . The p oints in F " on this line orrespond to the points of g whih lie inside a irle of radius " around f ( s ). The b oundary of F " orresp onds to the intersetions of with g , and hene we an apply Lemma 2. Lemma 5 Inside a el l, a vertial or horizontal line intersets the boundary of F " at most twie. A vertial tangent line trough a ritial point of type E or W or a horizontal tangent line trough a ritial point of type N or S does not ross the boundary of F " in any other point. 2 Lemma 6 A urve forming a omponent of the boundary of the free spae inside a el l an ontain at most four ritial points. 2 This lemma implies that there is a limited numb er of p ossibilities for suh a b oundary, the most ompliated b eing an \s-shaped" path between b etween the left edge and the right edge of the retangle, ontaining two ritial p oints S + and N . 5. Pro essing a ell We are given the reahable p oints on the left and b ottom edge, and we ompute the p oints on the right edge and on the top edge whih are reahable from there. On eah edge of the retangle there are at most two intervals of free p oints, by Lemma 5. Inside eah interval of free points, there is only a single interval of reahable p oints b eause from every free p oint, everything whih is to the right or to the top in the same free interval is reahable diretly. We will illustrate how to ompute the leftmost reahable p oint in eah free interval on the top edge from a given interval X on left edge. Other ases are similar. We are given the lowest reahable p oint B in X . The upper end of X may b e the upp er left orner of the retangle, or it may b e a forbidden p oint whih belongs to a omp onent O of forbidden p oints. Similarly, the left endp oint F of Y may b e part of a omponent of forbidden points, whih we denote by O 2 . ( O and O 2 are not neessarily dierent, see Figure 3a.) Lemma 7 The leftmost point U in Y reahable from X depends only on the presene and the relative loations of O and O 2 and the horizontal line through B . PROOF. We have to show that any other \obstales" of forbidden p oints do not play any role in this question. We show this by giving an algorithm for onstruting U in all ases. If the horizontal line through B intersets O or O 2 , it is lear that one annot reah Y , see for example the interval X 1 in Figure 3a or the interval X 2 in onnetion with Y 2 in Figure 3b. Otherwise, we laim that the desired p oint U lies diretly ab ove the rightmost p oint of O or of O 2 , whihever is further to the right. The monotone path from X to Y has to pass to the right of O and O 2 . Thus, no point in Y left of U is reahable from X . To see that U is reahable, onsider rst the ase that O exists, see the example of the interval X 1 in Figure 3b. Let A b e the rightmost p oint of O . A an lie on the upper edge, or it an b e a ritial p oint of typ e E + . Assume rst that A is a ritial p oint of typ e E + . The vertial line a through A lies ompletely in the free spae, by Lemma 5, and O is the only obstale left of a . By assumption, the horizontal line b from the lowest reahable p oint B in X do es not interset O b efore reahing a , and there are no other obstales in this range. Thus, A is reahable from B , and the upp er end A 0 of a is the leftmost reahable p oint on the top edge. If it lies in Y , we an take it as our p oint U , and we are done. (This is the ase for the intervals X 1 and Y 1 in Figure 3b.) If Y lies left of a , we are done as well, as no p oints in Y are reahable from X . So let us deal with the
20th Europ ean Workshop on Computational Geometry B O F AB B2 a A′ A O b O2 FC′ C (a) (b) D Y1Y2Y1Y2 X2 X1 X2 X1 Fig. 3. Determining the reahable p oints on the top edge only remaining ase that Y lies to the right of a , and a is separated from Y by the obstale O 2 . The lowest p oint D of O 2 must lie ab ove O , and the horizontal line through D intersets a , whih is reahable. Therefore D is reahable. From D we an reah the rightmost p oint C of O 2 , whih is either a ritial point of typ e E + or the p oint F . In either ase, we an indeed reah the point C 0 vertially ab ove C as the leftmost p oint U . The ases when O do es not exist, or when the rightmost point A of O lies on the upp er edge, an b e treated similarly. 2 Will have desrib ed our proedure in terms of geometri op erations in the free spae diagram, like nding the right-most point in a omp onent of forbidden p oints. By working out what these operations mean in terms of the urves f and g , we obtain the following theorems. Theorem 8 Given the reahable points on the bottom edge and the left edge of a el l, the reahable points on the top edge and the right edge of the el l an be omputed in a onstant number of the following operations: { Interseting a irle of radius " with one of the urves { Finding the rst intersetion of one urve with an oset urve of the other urve at distane " . In both ases, we must be able to nd the parameter values on the respetive urves, orresponding to the points that we have omputed. 2 Theorem 9 Given two urves onsisting of m and n piees, respetively, where eah piee has a turning angle at most and has urvature " or " throughout, we an deide O ( m + n ) spae and in O ( mn ) primitive operations of the type desribed in Theorem 8 whether their Frehet distane is at most " , for a given parameter " . 2 6. The Minimization Problem The minimization problem of omputing the Frehet distane an b e solved by Megiddo's parametri searh tehnique [4℄, losely following the approah of [2℄ for p olygonal urves. The tehnial details are more involved, and we have to make some stronger assumptions on the urves. Theorem 10 Given two urves onsisting of m and n piees, respetively, of smooth algebrai urves of xed maximum degree we an ompute their Frehet distane in O ( nm ) spae and in O ( mn log( mn )) algebrai operations, i.e., degree omparison between two real solutions of algebrai equations of bounded degree. 2 Referenes [1℄ H. Alt, A. Efrat, G. Rote, and C. Wenk, Mathing planar maps , Journal of Algorithms 49 (2003), 262{283. [2℄ H. Alt and M. Go dau, Computing the Frehet distane between two polygonal urves , Internat. J. Comput. Geom. Appl. 5 (1995), 75{91. [3℄ H. Alt, C. Knauer, and C. Wenk, Mathing polygonal urves with respet to the Frehet distane , STACS 2001 (A. Ferreira and H. Reihel, eds.), Let. Notes Comp. Si., vol. 2010, Springer-Verlag, 2001, pp. 63{74. [4℄ N. Megiddo, Applying paral lel omputation algorithms in the design of serial algorithms , J. Asso . Comput. Mah. 30 (1983), 852{865. [5℄ G unter Rote, Computing the frehet distane between pieewise smooth urves , Teh. Rep ort ECG-TR- 241108-01, 2003.