Frechet Distance between two curves
May 2013, updated June 2020
f = frechet(X1,Y1,X2,Y2)
f = frechet(X1,Y1,X2,Y2,res)
(X1,Y1) are the ordered x and y coordinates of the first curve.
(X2,Y2) are the ordered x and y coordinates of the second curve.
The number of points composing the two curves does not have to be the same.
'res' is an optional positive parameter setting the number of linearly spaced distances spanning the minimum pairwise distance between any two points and the maximum pairwise distance between any two points. In general, first try without setting 'res', as that is guaranteed to give the highest precision answer. If computations are taking too long, try setting 'res=1000' for starters. When not using 'res', the script examines thresholds for all unique values of pairwise distances (O(N^2)). This might be ok for curves made up of (eg) 1000 points, but not 100,000.
This function estimates the Frechet Distance, which is a measure of the dissimilarity between two curves in space (in this case in 2D). It is a scalar value that is symmetric with respect to the two curves (i.e. switching X1->X2 and Y1->Y2 does not change the value). Roughly speaking, this distance metric is the minimum length of a line 'f' that connects a point on each curve, and allows one to traverse both curves from start to finish with a line of length 'f' or shorter.
(wiki: Frechet Distance)
The function requires the function 'bwlabel' from the image processing toolbox.
EXAMPLE: compare three curves to find out which two are most similar
legend('curve 1','curve 2','curve 3','location','eastoutside')
axis equal tight
title(['three space curves to compare'])
axis equal tight
Tristan Ursell (2021). Frechet Distance Calculator (https://www.mathworks.com/matlabcentral/fileexchange/41956-frechet-distance-calculator), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!