1 // Boost.Geometry
2 // QuickBook Example
3
4 // Copyright (c) 2018, Oracle and/or its affiliates
5 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 //[line_interpolate
12 //` Shows how to interpolate points on a linestring
13
14 #include <iostream>
15
16 #include <boost/geometry.hpp>
17 #include <boost/geometry/geometries/point_xy.hpp>
18
19 using namespace boost::geometry;
20
main()21 int main()
22 {
23 typedef boost::geometry::model::d2::point_xy<double> point_type;
24 using segment_type = model::segment<point_type>;
25 using linestring_type = model::linestring<point_type>;
26 using multipoint_type = model::multi_point<point_type>;
27
28 segment_type const s { {0, 0}, {1, 1} };
29 linestring_type const l { {0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2} };
30 point_type p;
31 multipoint_type mp;
32
33 std::cout << "point interpolation" << std::endl;
34
35 line_interpolate(s, std::sqrt(2)/4, p);
36 std::cout << "on segment : " << wkt(p) << std::endl;
37
38 line_interpolate(l, 1.4, p);
39 std::cout << "on linestring : " << wkt(p) << std::endl << std::endl;
40
41 std::cout << "multipoint interpolation" << std::endl;
42
43 line_interpolate(s, std::sqrt(2)/4, mp);
44 std::cout << "on segment : " << wkt(mp) << std::endl;
45
46 mp=multipoint_type();
47 line_interpolate(l, 1.4, mp);
48 std::cout << "on linestring : " << wkt(mp) << std::endl;
49
50 return 0;
51 }
52
53 //]
54
55 //[line_interpolate_output
56 /*`
57 Output:
58 [pre
59 point interpolation
60 on segment : POINT(0.25 0.25)
61 on linestring : POINT(1 0.4)
62
63 multipoint interpolation
64 on segment : MULTIPOINT((0.25 0.25),(0.5 0.5),(0.75 0.75),(1 1))
65 on linestring : MULTIPOINT((1 0.4),(0.2 1))
66 ]
67 */
68 //]
69