19 Kasım 2017 Pazar

geometry intersects metodu

Giriş
Şu satırı dahil ederiz
#include <boost/geometry.hpp>
Örnek - linestring + linestring
Şöyle yaparız.
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/linestring.hpp>
#include <boost/geometry/geometries/point_xy.hpp>

#include <iostream>

namespace bg = boost::geometry;
namespace bgm = bg::model;


using P = bgm::d2::point_xy<double>;
P pt11{ 118.8031, 32.10011 };
P pt12{ 118.80297, 32.10016 };
P pt13{ 118.80284, 32.10021 };
bgm::linestring<P> line1{ pt11, pt12, pt13 };
bgm::linestring<P> line2{ pt11, pt12, pt13 };
std::string reason;
cout << std::boolalpha;
cout << "line1 valid? " << bg::is_valid(line1, reason) << " (" << reason << ")\n";
cout << "line2 valid? " << bg::is_valid(line2, reason) << " (" << reason << ")\n";
cout << "line1 intersects line2? : " << bg::intersects(line1, line2) << endl;
Çıktı olarak şunu alırız
line1 valid? true (Geometry is valid)
line2 valid? true (Geometry is valid)
line1 intersects line2? : true
Örnek - polygon + polygon
Şöyle yaparız.
using Pt = bg::model::d2::point_xy<int>;
using Poly = bg::model::polygon<Pt>;
using Multi = bg::model::multi_polygon<Poly>;

Poly const a {{ { 0,0 }, { 0,3 }, { 3,3 }, { 3,0 }, { 0,0 }} };
Poly const b {{ { 1,1 }, { 1,2 }, { 2,2 }, { 2,1 }, { 1,1 }} };

return bg::intersects(a, b);

Hiç yorum yok:

Yorum Gönder