在Boost几何中创建实体多边形 [英] Create solid polygon in boost geometry
问题描述
我是Boost几何的新手,我用boost::geometry::assign_points()
创建了多边形.但是我只创建多边形的外部和内部为空.因此,我尝试在两个多边形A,B和A在B内的情况下测试boost::geometry::overlaps()
,结果不重叠.
I'm newbie at boost geometry, I have created polygon with boost::geometry::assign_points()
. But I only create outer and inner of that polygon is empty. So I try test boost::geometry::overlaps()
with two polygons A, B and A is inside B, result is not overlaps.
那么,我该怎么做才能创建实体多边形(仅知道多边形的外点和多边形的内部是有效的)?
So, What can I do to create solid polygon (only know outer point of polygon and inside of polygon is valid) ?
推荐答案
根据定义,多边形是 ,直到减去内环为止.从标准§6.1.11.1起:
Polygons are by definition solid until you subtract inner rings. From §6.1.11.1 from the standard¹:
多边形是由1个外部边界和0个或多个内部边界定义的平面.每个内部 边界定义了多边形中的孔.三角形是具有3个不同的非共线顶点且没有 内部边界. ¹
A Polygon is a planar Surface defined by 1 exterior boundary and 0 or more interior boundaries. Each interior boundary defines a hole in the Polygon. A Triangle is a polygon with 3 distinct, non-collinear vertices and no interior boundary. ¹
重叠并不意味着您认为的意思.
Overlapping doesn't mean what you think it means.
第6.1.15.3节(基于DE-9IM的命名空间关系谓词)
From §6.1.15.3 (Named spatial relationship predicates based on the DE-9IM)
- 交叉
- 在
-
重叠
- Crosses
- Within
Overlaps
它定义为
a.Overlaps(b) ⇔ ( dim(I(a)) = dim(I(b)) = dim(I(a) ∩ I(b)))
∧ (a ∩ b ≠ a) ∧ (a ∩ b ≠ b)
包含
Contains
a.Contains(b) ⇔ b.Within(a)
相交
Intersects
a.Intersects(b) ⇔ ! a.Disjoint(b)
在您的情况下,您可能正在寻找!disjoint
,within
,contains
或intersection
:
In your case you might be looking for !disjoint
, within
, contains
or intersection
:
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/geometries.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <iostream>
namespace bg = boost::geometry;
template <typename Geo> void debug(std::string name, Geo const& g) {
std::string reason;
std::cout << name << ": " << bg::dsv(g) << " " << bg::is_valid(g, reason) << ", '" << reason << "'\n";
}
template <typename Geo, typename F>
void both_ways(std::string name, Geo const& a, Geo const& b, F f) {
std::cout << name << "(a, b) -> " << f(a,b) << "\n";
std::cout << name << "(b, a) -> " << f(b,a) << "\n";
}
int main() {
std::cout << std::boolalpha;
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 }} };
debug("a", a);
debug("b", b);
#define TEST(algo) both_ways(#algo, a, b, [](auto& a, auto& b) { return bg::algo(a, b); })
TEST(overlaps);
TEST(intersects);
TEST(within);
//TEST(contains); // contains(a,b) ⇔ within(b,a)
//TEST(crosses); // not implemented for polygons
TEST(disjoint);
both_ways("intersection", a, b, [](auto& a, auto& b) {
Multi c;
bg::intersection(a, b, c);
return boost::lexical_cast<std::string>(bg::dsv(c));
});
}
哪些印刷品
a: (((0, 0), (0, 3), (3, 3), (3, 0), (0, 0))) true, 'Geometry is valid'
b: (((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))) true, 'Geometry is valid'
overlaps(a, b) -> false
overlaps(b, a) -> false
intersects(a, b) -> true
intersects(b, a) -> true
within(a, b) -> false
within(b, a) -> true
disjoint(a, b) -> false
disjoint(b, a) -> false
intersection(a, b) -> ((((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))))
intersection(b, a) -> ((((1, 1), (1, 2), (2, 2), (2, 1), (1, 1))))
¹ OGC简单功能/通用体系结构
这篇关于在Boost几何中创建实体多边形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!