]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // QuickBook Example | |
3 | ||
4 | // Copyright (c) 2011-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
5 | ||
6 | // Use, modification and distribution is subject to the Boost Software License, | |
7 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
8 | // http://www.boost.org/LICENSE_1_0.txt) | |
9 | ||
10 | //[intersection_segment | |
11 | //` Calculate the intersection point (or points) of two segments | |
12 | ||
13 | #include <iostream> | |
14 | ||
15 | #include <boost/geometry.hpp> | |
16 | #include <boost/geometry/geometries/point_xy.hpp> | |
17 | ||
18 | #include <boost/foreach.hpp> | |
19 | ||
20 | ||
21 | int main() | |
22 | { | |
23 | typedef boost::geometry::model::d2::point_xy<double> P; | |
24 | boost::geometry::model::segment<P> segment1, segment2; | |
25 | boost::geometry::read_wkt("linestring(1 1,2 2)", segment1); | |
26 | boost::geometry::read_wkt("linestring(2 1,1 2)", segment2); | |
27 | ||
28 | std::vector<P> intersections; | |
29 | boost::geometry::intersection(segment1, segment2, intersections); | |
30 | ||
31 | BOOST_FOREACH(P const& p, intersections) | |
32 | { | |
33 | std::cout << " " << boost::geometry::wkt(p); | |
34 | } | |
35 | std::cout << std::endl; | |
36 | ||
37 | return 0; | |
38 | } | |
39 | ||
40 | //] | |
41 | ||
42 | ||
43 | //[intersection_segment_output | |
44 | /*` | |
45 | Output: | |
46 | [pre | |
47 | POINT(1.5 1.5) | |
48 | ] | |
49 | */ | |
50 | //] |