CGAL 6.1 - dD Frechet Distance
|
This package provides functions for computing the Fréchet distance of polylines in any dimension under the Euclidean metric.
The Fréchet distance is a classical dissimilarity measure between polylines. Its advantages over other measures are that it both considers the polylines as continuous objects and takes into account the ordering of the points. Intuitively, the Fréchet distance is commonly explained as follows: Imagine a human walking on one polyline while a dog walks on the other polyline, they are connected by a leash, and they are only allowed to walk forward. The Fréchet distance is the shortest leash length that allows the human and the dog to jointly walk from start to end on their respective trajectories.
The Fréchet distance is a metric. This implies that two polylines have distance zero if and only if they are equal (after removing redundant vertices).
The package provides one function to approximate the Fréchet distance and one function to decide whether the Fréchet distance is at most a given value.
The function bounded_error_Frechet_distance()
computes an approximation of the Fréchet distance between two polylines, up to a given approximation error. It returns an interval that contains the true distance. The function is_Frechet_distance_larger()
decides if the Fréchet distance between two polylines is larger than a given bound.
Both functions have as template parameter a traits class defining the dimension and the point type. The traits classes have as template parameter a kernel, model of the concept Kernel
. In case the static constant Has_filtered_predicates
of the kernel is true
, the functions combine interval arithmetic with a fallback to exact computing in case comparisons of intervals are uncertain. This means for Simple_cartesian<double>
that there are no guarantees, for Simple_cartesian<Exact_rational>
that all computations are performed with exact rationals, and for kernels such as Exact_predicates_inexact_constructions_kernel
, Exact_predicates_exact_constructions_kernel
, Exact_predicates_exact_constructions_kernel_with_sqrt
, as well as Epick_d
and Epeck_d
, the computation is filtered and hence both fast and guaranteed to be correct.
The algorithms in this package are an adaption of the implementation of [1] and [2]. In particular, the implementation can decide non-difficult cases very fast while for difficult cases it still has the quadratic running time guarantee of the classical Fréchet distance algorithm by Alt and Godau cgalCite{ag-cfdbt-95}. This is achieved by using fast bounding box filtering methods and a divide and conquer algorithm with pruning rules on the free-space diagram.
In the examples we use different kernels to illustrate that the functions can be used with either inexact or exact kernels.
The following example shows how we can use is_Frechet_distance_larger()
to decide whether the Fréchet distance between two polylines in the Euclidean plane is at most a given value.
File Frechet_distance/Frechet_distance_2.cpp
The following example shows how we can compute the Fréchet distance up to a given error bound on two polylines in 3-dimensional Euclidean space using bounded_error_Frechet_distance()
. As we use Simple_cartesian<double>
the algorithm uses plain floating point arithmetic without guarantees for correctness.
File Frechet_distance/Frechet_distance_3.cpp
The following example shows how we can compute the Fréchet distance up to a given error bound on two polylines in 4-dimensional Euclidean space using bounded_error_Frechet_distance()
.
File Frechet_distance/Frechet_distance_d.cpp
The following example shows how to store many curves in a data structure and to find all curves closed than a distance bound for a query curve.
File Frechet_distance/Frechet_DS_3.cpp
The teaser image is a visualization of two data points from the Character Trajectories data set.
An initial version using floating point arithmetic was developed by the authors while working at the Max Planck Institute for Informatics in Saarbrücken, Germany. André Nusser, together with Sebastien Loriot and Andreas Fabri, introduced the usage of interval arithmetic and square root extensions to alleviate issues stemming from rounding errors and hence ensuring correctness of the computation.