2011-07-20 169 views
3

閱讀關於它之後,我得出這樣的:CGAL:找到一個點屬於哪個面/三角形?

#include <vector> 
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 
#include <CGAL/Delaunay_triangulation_2.h> 

typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 
typedef CGAL::Delaunay_triangulation_2<K>     Delaunay;  
typedef K::Point_2           Point; 

void load_points(std::vector<Point>& points) 
{ 
    points.push_back(Point(1., 1.)); 
    points.push_back(Point(2., 1.)); 
    points.push_back(Point(2., 2.)); 
    points.push_back(Point(1., 2.));  
} 

int main() 
{ 
    std::vector<Point> points; 
    load_points(points); 
    Delaunay dt; 
    dt.insert(points.begin(), points.end()); 
    std::cout << dt.number_of_vertices() << std::endl; 

    typedef std::vector<Delaunay::Face_handle> Faces; 
    Faces faces; 
    std::back_insert_iterator<Faces> result(faces); 
    result = dt.get_conflicts (Delaunay::Point(1.5, 1.5), 
           std::back_inserter(faces)); 

    return 0; 
} 

這應該查找其外接圓的麪包含點。之後,我不得不採取這些三角形,並使用一種方法來測試點是否在他們的內部,我認爲(CGAL是否這樣做?我知道它很容易實現)。

無論如何,我怎樣才能從臉上得到三角形?

答案是

CGAL::Triangle_2<K> f = dt.triangle(faces[0]); 
std::cout << dt.triangle(faces[0]) << std::endl; 
std::cout << dt.triangle(faces[1]) << std::endl; 

我不知道如何使用三角類很好,但它至少是一個開始。

我正在做一個實際的答案,但stackoverflow不允許我這樣做。

回答

3

您應該使用locate成員函數,該文檔可以找到here

相關問題