【问题标题】:Why boost::geometry::union_ can't give result for axis-aligned-box?为什么 boost::geometry::union_ 不能给出轴对齐框的结果?
【发布时间】:2017-04-21 18:49:52
【问题描述】:

当多边形是轴对齐框“POLYGON((0 0,1 0,1 1,0 1))”时,union_() 不会给出正确的结果,只是空输出。实际上,任何多边形的 union_() 都不应该为空。

但是,如果将多边形绿色从轴对齐框更改为“POLYGON((2 1.3,2.4 1.7,2.8 1.8))”,则输出有意义(非空)。

是boost union_()的bug吗?

非常感谢

int main()
{
    typedef boost::geometry::model::polygon<boost::geometry::model::d2::point_xy<double> > polygon;

    polygon green, blue;

    boost::geometry::read_wkt(
        "POLYGON((0 0,1 0,1 1,0 1))",
        green);

    boost::geometry::read_wkt(
        "POLYGON((2 1.3,2.4 1.7,2.8 1.8))",
        blue);

    std::deque<polygon> output;
    boost::geometry::union_(green, blue, output);

    int i = 0;
    std::cout << "green && blue:" << std::endl;
    BOOST_FOREACH(polygon const& p, output)
    {
        std::cout << i++ << ": " << boost::geometry::area(p) << std::endl;
    }

    return 0;
}

【问题讨论】:

  • 看来我得到了答案。但我必须验证它。只需为每个多边形调用 boost::geometry::correct() 。然后 boost 将为 uion_() 和 intersection() 提供正确的结果。等一下。让我测试一下。

标签: boost union polygon intersection boost-geometry


【解决方案1】:

关于它有一个类似的问题。该算法需要一些先决条件。 1)多边形必须是顺时针的。 2) 多边形已经闭合,即最后一个点正好与第一个点重合。

所以要纠正原始多边形数据中的问题,调用 boost::geometry::correct() 使数据符合规则。该算法将接受多边形并给出正确的结果。

Why boost::geometry::intersection does not work correct?

【讨论】:

    猜你喜欢
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 1970-01-01
    相关资源
    最近更新 更多