1
0

29_pointinpoly.cpp 773 B

123456789101112131415161718192021222324252627
  1. #include <boost/geometry.hpp>
  2. #include <boost/geometry/geometries/point_xy.hpp>
  3. #include <boost/geometry/geometries/polygon.hpp>
  4. #include <iostream>
  5. using namespace boost::geometry;
  6. using namespace std;
  7. int main()
  8. {
  9. typedef model::d2::point_xy<double> pointtype;
  10. pointtype point1(3, 3);
  11. pointtype point2(2, 12.1);
  12. model::polygon<pointtype> poly;
  13. pointtype points[] = {pointtype(0, 0), pointtype(0, 10), pointtype(5, 15),
  14. pointtype(10, 10), pointtype(10, 0), pointtype(0, 0)};
  15. append(poly, points);
  16. cout << wkt(point1) << " is "
  17. << (within(point1, poly) ? "inside" : "outside of") << " the "
  18. << wkt(poly) << endl;
  19. cout << wkt(point2) << " is "
  20. << (within(point2, poly) ? "inside" : "outside of") << " the "
  21. << wkt(poly) << endl;
  22. return 0;
  23. }