CGAL बेंटले-Ottmann, 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;
}
- - http://doc.cgal.org/latest/Sweep_line_2/index.html
क्षमा करें, एक/(थोड़ा) तेज एल्गोरिदम का संदर्भ नहीं मिल रहा है।
स्रोत
2010-12-11 13:57:43
Ngu, मैं एक बार जावा में बेंटले-Ottmann जो सभी कोने मामलों संभालती क्रियान्वित किया है। इसका उत्पादन उत्पादन कोड (AFAIK) में उपयोग नहीं किया गया है, लेकिन मैंने इसके लिए यूनिट परीक्षणों की एक सभ्य राशि लिखी है। तो यदि आप रुचि रखते हैं, तो मैं अपनी छोटी पुस्तकालय में एक लिंक पोस्ट कर सकता हूं जिसमें यह एल्गोरिदम है। –
तथ्य यह है कि बूस्ट और एलईडीए बेंटले-ओटमैन प्रदान नहीं करते हैं क्योंकि एल्गोरिदम हैं जो बेंटले-ओटमैन को बाहर करते हैं। AFAIK, बेंटले-ओटमैन "आसान" एल्गोरिदम में से एक है जो लाइन सेगमेंट के सेट से सभी चौराहे ढूंढता है। –
@ बार्ट, अगर आप मुझे जावा लिंक प्रदान कर सकते हैं तो मैं आभारी रहूंगा। इसके अलावा, बूस्ट में लागू किए गए अन्य लाइन चौराहे वाले एल्गोरिदम क्या हैं जो बेंटले-ओटमैन से बेहतर प्रदर्शन करते हैं? – Graviton