1 // Boost.Geometry
2 // QuickBook Example
3 // Copyright (c) 2018, Oracle and/or its affiliates
4 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8
9 //[discrete_frechet_distance
10 //` Calculate Similarity between two geometries as the discrete frechet distance between them.
11
12 #include <iostream>
13
14 #include <boost/geometry.hpp>
15 #include <boost/geometry/geometries/point_xy.hpp>
16 #include <boost/geometry/geometries/linestring.hpp>
17
main()18 int main()
19 {
20 typedef boost::geometry::model::d2::point_xy<double> point_type;
21 typedef boost::geometry::model::linestring<point_type> linestring_type;
22
23 linestring_type ls1, ls2;
24 boost::geometry::read_wkt("LINESTRING(0 0,1 1,1 2,2 1,2 2)", ls1);
25 boost::geometry::read_wkt("LINESTRING(1 0,0 1,1 1,2 1,3 1)", ls2);
26
27 double res = boost::geometry::discrete_frechet_distance(ls1, ls2);
28
29 std::cout << "Discrete Frechet Distance: " << res << std::endl;
30
31 return 0;
32 }
33
34 //]
35
36 //[discrete_frechet_distance_output
37 /*`
38 Output:
39 [pre
40 Discrete Frechet Distance: 1.41421
41 ]
42 */
43 //]
44