Bentley-Ottmann算法是否有健壮的C ++实现? [英] Is there a robust C++ implementation of the Bentley-Ottmann algorithm?

查看:110
本文介绍了Bentley-Ottmann算法是否有健壮的C ++实现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Bentley-Ottoman算法可找到一组线段中的所有交叉点。对于一个众所周知的重要算法,Bentley-Ottmann算法的C ++实现似乎很奇怪。能够处理所有退化情况的实现(即,对扫掠线和交点的数量没有特殊假设,等等)根本不可用。我可以找到的唯一代码是此处,但它没有似乎无法处理一般情况

The Bentley-Ottoman algorithm finds all crossings in a set of line segments. For a well known and important algorithm, it seems quite weird that a C++ implementation of Bentley-Ottmann algorithm — the implementation that can handle all the degenerated cases (i.e., no special assumption on the sweeping line and the number of intersection points, and so on) — is simply not available. The only code I can found is here, but it doesn't seem to handle the generalized case.

是Bentley -Ottmann算法已经已在任何经过​​良好测试的库中实现,例如Boost或LEDA?如果是,我可以引用它吗?

Is Bentley-Ottmann algorithm already implemented in any well-tested library, such as Boost or LEDA? If yes, may I have the reference to it?

推荐答案

CGAL 具有与Bentley-Ottmann相同的复杂性, O((n + k)* log(n))其中, n 是路段数, k 是路口数(不确定使用的是哪种算法):

CGAL has something in there with the same complexity as Bentley-Ottmann, O((n + k)*log(n)) where n is the number of segments and k is the number of intersections (not sure which algorithm they used):

//! \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;
}

http://doc.cgal.org/latest/Sweep_line_2/index.html

这篇关于Bentley-Ottmann算法是否有健壮的C ++实现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆