簡體   English   中英

在增強幾何中創建實體多邊形

[英]Create solid polygon in boost geometry

我是Boost幾何的新手,我用boost::geometry::assign_points()創建了多邊形。 但是我只創建多邊形的外部和內部為空。 因此,我嘗試在B內部測試帶有兩個多邊形A,B和A的boost::geometry::overlaps() ,結果不重疊。

那么,我該怎么做才能創建實體多邊形(僅知道多邊形的外部點和多邊形的內部有效)?

根據定義,多邊形是實心的,直到減去內環為止。 從標准§6.1.11.1起:

多邊形是由1個外部邊界和0個或多個內部邊界定義的平面。 每個內部邊界在“多邊形”中定義一個孔。 三角形是具有3個不同的非共線頂點且沒有內部邊界的多邊形。 ¹

重疊並不意味着您認為的意思。

從§6.1.15.3起(基於DE-9IM的命名空間關系謂詞)

  • 十字架 在此處輸入圖片說明
  • 在此處輸入圖片說明
  • 重疊 在此處輸入圖片說明

    定義為

     a.Overlaps(b) ⇔ ( dim(I(a)) = dim(I(b)) = dim(I(a) ∩ I(b))) ∧ (a ∩ b ≠ a) ∧ (a ∩ b ≠ b) 
  • 包含

     a.Contains(b) ⇔ b.Within(a) 
  • 相交

     a.Intersects(b) ⇔ ! a.Disjoint(b) 

在你的情況,你可能會尋找!disjointwithincontainsintersection

生活在Coliru

#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簡單功能 /通用架構

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM