2015-09-08 47 views
1

我對CGAL::do_intersect如何工作有點困惑。 如果兩個多邊形都有點,我認爲函數返回true。據我沒有錯誤in位於out,我應該看到true打印出來或我錯過了什麼?CGAL十字路口返回假結果

#include <CGAL/Point_2.h> 
#include <CGAL/Polygon_2.h> 
#include <CGAL/Exact_predicates_exact_constructions_kernel.h> 

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; 
typedef Kernel::Point_2 Point_2; 
typedef CGAL::Polygon_2<Kernel> Polygon_2; 
int main(int argc, char **argv) 
{ 
    Polygon_2 in, out; 
    in.push_back(Point_2(1,1)); 
    in.push_back(Point_2(1,2)); 
    in.push_back(Point_2(2,2)); 
    in.push_back(Point_2(2,1)); 

    out.push_back(Point_2(0,0)); 
    out.push_back(Point_2(3,0)); 
    out.push_back(Point_2(3,3)); 
    out.push_back(Point_2(0,3)); 

    std::cout << "IN intersect with OUT is " << (CGAL::do_intersect(in, out) ? "true":"false") << std::endl; 
    std::cout << "OUT intersect with IN is " << (CGAL::do_intersect(out, in) ? "true":"false") << std::endl; 
    std::cout.flush(); 
} 

回答

1

多邊形中的頂點需要逆時針。下面的代碼產生所需的輸出:

IN intersect with OUT is true 
OUT intersect with IN is true 

#include <CGAL/Point_2.h> 
#include <CGAL/Polygon_2.h> 
#include <CGAL/Exact_predicates_exact_constructions_kernel.h> 
#include <CGAL/Boolean_set_operations_2.h> 

typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; 
typedef Kernel::Point_2 Point_2; 
typedef CGAL::Polygon_2<Kernel> Polygon_2; 
int main(int argc, char **argv) 
{ 
    Polygon_2 in, out; 
    in.push_back(Point_2(1,1)); 
    in.push_back(Point_2(2,1)); 
    in.push_back(Point_2(2,2)); 
    in.push_back(Point_2(1,2)); 

    out.push_back(Point_2(0,0)); 
    out.push_back(Point_2(3,0)); 
    out.push_back(Point_2(3,3)); 
    out.push_back(Point_2(0,3)); 

    std::cout << "IN intersect with OUT is " << (CGAL::do_intersect(in, out) ? "true":"false") << std::endl; 
    std::cout << "OUT intersect with IN is " << (CGAL::do_intersect(out, in) ? "true":"false") << std::endl; 
    std::cout.flush(); 
} 
+0

感謝。我找不到任何文件記錄。 –