Bentley-Ottoman算法在一组线段中找到所有的交叉点.对于一个著名而重要的算法来说,一个Bentley-奥特曼算法的C++实现--能够处理所有退化情况的实现(即,对扫线和交点数等没有特殊假设,等等)--根本无法实现,这似乎很奇怪。我能找到的唯一代码是这里,但它似乎不处理广义情形。
本特利-奥特曼算法是否已经在任何经过良好测试的库中实现,如Boost或LEDA?如果是,我可以参考一下吗?
发布于 2010-12-11 13:57:43
CGAL的复杂性与Bentley- O((n + k)*log(n))相同,其中n是段的数目,k是交叉点的数目(不确定他们使用的是哪种算法):
//! \file examples/Arrangement_on_surface_2/sweep_line.cpp
// Computing intersection points among curves using the sweep line.
#include <CGAL/Cartesian.h>
#include <CGAL/MP_Float.h>
#include <CGAL/Quotient.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Sweep_line_2_algorithms.h>
#include <list>
typedef CGAL::Quotient<CGAL::MP_Float> NT;
typedef CGAL::Cartesian<NT> Kernel;
typedef Kernel::Point_2 Point_2;
typedef CGAL::Arr_segment_traits_2<Kernel> Traits_2;
typedef Traits_2::Curve_2 Segment_2;
int main()
{
// Construct the input segments.
Segment_2 segments[] = {Segment_2 (Point_2 (1, 5), Point_2 (8, 5)),
Segment_2 (Point_2 (1, 1), Point_2 (8, 8)),
Segment_2 (Point_2 (3, 1), Point_2 (3, 8)),
Segment_2 (Point_2 (8, 5), Point_2 (8, 8))};
// Compute all intersection points.
std::list<Point_2> pts;
CGAL::compute_intersection_points (segments, segments + 4,
std::back_inserter (pts));
// Print the result.
std::cout << "Found " << pts.size() << " intersection points: " << std::endl;
std::copy (pts.begin(), pts.end(),
std::ostream_iterator<Point_2>(std::cout, "\n"));
// Compute the non-intersecting sub-segments induced by the input segments.
std::list<Segment_2> sub_segs;
CGAL::compute_subcurves(segments, segments + 4, std::back_inserter(sub_segs));
std::cout << "Found " << sub_segs.size()
<< " interior-disjoint sub-segments." << std::endl;
CGAL_assertion (CGAL::do_curves_intersect (segments, segments + 4));
return 0;
}2/index.html
发布于 2010-12-11 14:58:35
CGAL实现了一个Bently算法.您可以在手册的平面曲线的二维扫描线部分找到更多关于它的信息。
发布于 2014-01-08 12:57:56
intersect-3.html讨论了宾利-奥特曼和沙摩斯-霍伊算法及其相互关系.它以基于二叉树的C++实现结束。有趣的参考资料,如果你不想链接到CGAL或boost。
https://stackoverflow.com/questions/4407493
复制相似问题