Advertisement
obernardovieira

polygon-polygon intersections

Oct 2nd, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.46 KB | None | 0 0
  1. /*Here is example to the extension of your original question you asked as a comment below Kirill's answer: Are intersections between polygons possible?
  2.  
  3. Yes, polygon-polygon intersections are supported by (http://trac.osgeo.org/ggl/)*/
  4.  
  5. #include <iostream>
  6. #include <vector>
  7. #include <boost/geometry/geometry.hpp>
  8. #include <boost/geometry/geometries/cartesian2d.hpp>
  9. #include <boost/geometry/geometries/adapted/c_array_cartesian.hpp>
  10.  
  11. using namespace boost::geometry;
  12.  
  13. int main(void)
  14. {
  15.     // Define a polygons and fill the outer rings.
  16.     polygon_2d a;
  17.     {
  18.         const double c[][2] = {
  19.             {160, 330}, {60, 260}, {20, 150}, {60, 40}, {190, 20}, {270, 130}, {260, 250}, {160, 330}
  20.         };
  21.         assign(a, c);
  22.     }
  23.     correct(a);
  24.     std::cout << "A: " << dsv(a) << std::endl;
  25.  
  26.     polygon_2d b;
  27.     {
  28.         const double c[][3] = {
  29.             {300, 330}, {190, 270}, {150, 170}, {150, 110}, {250, 30}, {380, 50}, {380, 250}, {300, 330}
  30.         };
  31.         assign(b, c);
  32.     }
  33.     correct(b);
  34.     std::cout << "B: " << dsv(b) << std::endl;
  35.  
  36.     // Calculate interesection
  37.     typedef std::vector<polygon_2d > polygon_list;
  38.     polygon_list v;
  39.  
  40.     intersection_inserter<polygon_2d>(a, b, std::back_inserter(v));
  41.     std::cout << "Intersection of polygons A and B" << std::endl;
  42.     for (polygon_list::const_iterator it = v.begin(); it != v.end(); ++it)
  43.     {
  44.         std::cout << dsv(*it) << std::endl;
  45.     }
  46.  
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement