【发布时间】: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 失败。
凸包hull0 和hull1 如下所示:
我做错了什么吗?我真的不想自己实现计算凸包和交叉点,这似乎是很多不必要的容易出错的工作。
【问题讨论】:
-
has_self_intersections只能返回false或者抛出异常。它可能不适合一般用途,因为它隐藏在detail命名空间中。 -
@Cubbi,是的,许多函数都使用它来检查底层数据的一致性。因此,如果失败,下次使用
results[0]时就会出错。
标签: c++ boost convex-hull set-intersection boost-geometry