within - 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);
within - franklin
Açıklaması şöyle.
"If a point is located exactly on the border of a geometry, the result depends on the strategy. The default strategy (Winding (coordinate system agnostic)) returns false in that case."
franklin tam üst üste gelen noktalar için true döner. Şöyle yaparız.
Şu satırı dahil ederiz.
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/strategies/cartesian/point_in_poly_franklin.hpp>
Elimizde bir polygon olsun.
typedef boost::geometry::model::d2::point_xy<double> point_type;
typedef boost::geometry::model::polygon<point_type> polygon_type;
typedef boost::geometry::model::segment<point_type> seg;
typedef boost::geometry::strategy::within::franklin
<point_type, point_type, void> fran;
Bu polygon'u dolduralım.
polygon_type poly;
boost::geometry::read_wkt("POLYGON((2 1.3,2.4 1.7,2.8 1.8,3.4 1.2,...))", poly);
point_type p(4, 1);
Şöyle
yaparız.
fran fran_;
cout << "within: " << (boost::geometry::within(p, poly,fran_) ? "yes" : "no");
within metodu ile covered_by sanırım aynı şeyi yapıyorlar.
cout << "within: " << (boost::geometry::covered_by(p, poly) ? "yes" : "no");
Örnek
Şöyle
yaparız.
bool is_inside(const polygon& convex_polygon, const point p) noexcept
{
const auto n = convex_polygon.size();
const auto sense = determine_side(line{convex_polygon[n - 1], convex_polygon[0]}, p);
if(sense == side::center)
{
return false;
}
for(auto i = 0u; i + 1 < n; ++i)
{
auto new_sense = determine_side(line{convex_polygon[i], convex_polygon[i + 1]}, p);
if(new_sense != sense)
{
return false;
}
}
return true;
}