【问题标题】:Taking intersections of convex hulls in boost::geometry在 boost::geometry 中取凸包的交点
【发布时间】:2014-06-03 03:45:02
【问题描述】:

在多次尝试使用浮点数后,由于舍入问题导致异常异常,我认为使用整数算术作为解决方法可以解决问题。但是,现在我遇到了完全相同的问题。

我正在尝试计算各种点集的凸包的交集:

#include <iostream>
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/geometries/point_xy.hpp>
#include <boost/geometry/multi/geometries/multi_point.hpp>
#include <boost/geometry/geometries/polygon.hpp>

int main()
{
    typedef boost::geometry::model::d2::point_xy<int> Point;
    typedef boost::geometry::model::multi_point<Point> MultiPoint;
    typedef boost::geometry::model::ring<Point> Polygon;

    MultiPoint mp0, mp1;
    boost::geometry::read_wkt("MULTIPOINT((54 74),(54 75),(54 75),(62 75),(86 75),(94 75),(118 75),(124 75),(13 50),(13 51),(147 130),(281 51),(281 50))", mp0);
    boost::geometry::read_wkt("MULTIPOINT((52 74),(54 75),(135 90),(175 74),(54 74),(52 74))", mp1);

    Polygon hull0, hull1;
    boost::geometry::convex_hull(mp0, hull0);
    boost::geometry::convex_hull(mp1, hull1);

    std::vector<Polygon> results;
    boost::geometry::intersection(hull0, hull1, results);

    assert(results.size() == 1);

    // This results in the exception.
    assert(!boost::geometry::detail::overlay::has_self_intersections(results[0]));

    return EXIT_SUCCESS;
}

boost::geometry::overlay_invalid_input_exception 失败。

凸包hull0hull1 如下所示:

我做错了什么吗?我真的不想自己实现计算凸包和交叉点,这似乎是很多不必要的容易出错的工作。

【问题讨论】:

  • has_self_intersections 只能返回false 或者抛出异常。它可能不适合一般用途,因为它隐藏在 detail 命名空间中。
  • @Cubbi,是的,许多函数都使用它来检查底层数据的一致性。因此,如果失败,下次使用results[0] 时就会出错。

标签: c++ boost convex-hull set-intersection boost-geometry


【解决方案1】:

用例看起来没问题。

我们进行了一些数值稳健性升级,但尚未发布(Boost 1.55)。如果您想测试它们或提出一些更详细的问题,我建议您通过 Boost.Geometry 邮件列表与我们联系:http://lists.boost.org/mailman/listinfo.cgi/geometry

【讨论】:

  • 我提交了这个错误报告:svn.boost.org/trac/boost/ticket/9934 这个错误可以用我认为包含健壮性升级的当前 git 存储库重现?
  • 不,它们在分支 rescale_to_integer 中。请记住,它正在进行中。对于未来的读者:这个分支可能不再存在,更新可能会与开发和/或主合并。
  • 谢谢,我现在解决了这个问题,方法是将所有内容转换为 boost::polygon 多边形,在那里相交,然后将其转换回 boost::geometry。我需要生产环境中的代码,因此不能真正使用正在进行的代码库。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-12-05
  • 2015-08-09
  • 2017-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-27
相关资源
最近更新 更多