2014-10-21 137 views
-2

我開始使用CGAL使用以下代碼CGAL三角測量失敗

#include <iostream> 
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 
#include <CGAL/Delaunay_triangulation_2.h> 
#include <CGAL/Triangulation_vertex_base_with_info_2.h> 

typedef CGAL::Exact_predicates_inexact_constructions_kernel K; 
typedef CGAL::Triangulation_vertex_base_2<K> Vb; 
typedef CGAL::Triangulation_face_base_2<K> Fb; 
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds; 
typedef CGAL::Delaunay_triangulation_2<K,Tds> Triangulation; 

typedef Triangulation::Point Point; 
typedef Triangulation::Triangulation_data_structure tds; 


using namespace std; 


void main() 
{ 
    Triangulation t; 
    t.insert(Point(0,0)); 
    t.insert(Point(0,20)); 
    t.insert(Point(30,15)); 
    t.insert(Point(30,-15)); 

    Triangulation::Finite_faces_iterator fib = t.finite_faces_begin(), it; 
    Triangulation::Finite_faces_iterator fie = t.finite_faces_end(); 
    Triangulation::Triangle tri; 
    std::cout << "Triangular faces"<<endl; 
    for (it=fib; it!=fie; ++it) 
    { 
     tri = t.triangle(it); 
     std::cout<<tri[0]<<" "<<tri[1]<<" "<<tri[2]<<" "<<endl; 
    } 
    char c; 
    std::cin>>c; 
} 

這將打印面爲0,20 0,0 30,15和0,0 30,進行三角測量的點的集合 - 15 30,15。由於第一個三角形完全位於第二個三角形內,所以我對這個輸出結果不滿意。據我瞭解三角測量,它應該返回3個三角形,而不是2個覆蓋我的4個輸入點的複雜殼體,並且應該沒有重疊的三角形。有人能解釋我做錯了什麼嗎?

我的最終目標是在最小角度約束條件下對凸多邊形進行三角剖分(並通過將其他點添加到該集合中)。任何CGAL代碼示例將不勝感激。

感謝,

回答

0

我不認爲你很明白的幾何形狀會在這裏,或三角測量,所以我畫了一些照片。

這是你的設置:

enter image description here

下面是該Delaunay_Triangulation_2產生的第一個三角形:

(0,20),(0,0),(30,15)

enter image description here

而這裏的所產生的第二個三角形:

(0,0)(30,-15)(30,15)

enter image description here

顯然,既不三角形被包含在另一個內。此外,三角形的聯合,刪除共享邊,完美地創建點的凸包。

此外,考慮到你只有四個點總數,不可能構造一個三角形的三個三角形沒有重疊,因此只有2個被創建。

+0

謝謝,我交換了我的(20,0)點的座標,因此最近2個小時的混亂! – halberlinn 2014-10-21 21:41:42