Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <boost/geometry.hpp>
- #include <boost/geometry/geometries/point_xy.hpp>
- #include <boost/foreach.hpp>
- int main()
- {
- typedef boost::geometry::model::d2::point_xy<double> POINT;
- typedef boost::geometry::model::linestring<POINT> LINE;
- typedef boost::geometry::model::polygon<POINT> POLYGON;
- LINE line;
- POLYGON polygon;
- // Y
- // |
- // -------------
- // | | |
- // | | |
- // ------A>>>>>C>>>>>>>>>>>D>>>>>B-----> X
- // start | | | end
- // point | | | point
- // ------|------
- // |
- //
- // Create line from A to B.
- boost::geometry::read_wkt("linestring(-2 0, 2 0)", line);
- boost::geometry::correct(line);
- boost::geometry::read_wkt("POLYGON((1 1, -1 1, -1 -1, 1 -1))", polygon);
- boost::geometry::correct(polygon);
- std::vector<LINE> output;
- boost::geometry::difference(line, polygon, output);
- // Result will be 2 lines.
- // A to C : LINESTRING(-2 0,-1 0)
- // D to B : LINESTRING(1 0,2 0)
- BOOST_FOREACH(LINE const& l, output)
- {
- std::cout << boost::geometry::wkt(l) << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement