2015-10-05 34 views
2

當使用CGAL::Exact_predicates_inexact_constructions_kernel內核嘗試在3D空間內相交兩個三角形時,我遇到了一個非常奇怪的錯誤。基本上,我有兩個不應該相交的三角形。函數CGAL::do_intersect在測試時總是返回false,但函數CGAL::intersection根據三角形頂點的順序建立交點。3D三角形(CGAL)錯誤的不精確交集

當我使用CGAL::Exact_predicates_exact_constructions_kernel內核時,該錯誤消失,但我無法承受在真實情況下使用它。

下面是一個最小的代碼與錯誤。三角形B和C是相等的(到頂點的置換),並應與三角A.返回相同的路口

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> 
#include <CGAL/Intersections.h> 

#include <iostream> 
#include <vector> 

typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; 

typedef Kernel::Point_3  Point_3; 
typedef Kernel::Triangle_3 Triangle_3; 


int main(int argc, char *argv[]) 
{ 
    std::vector<Point_3> APoints(3); 
    std::vector<Point_3> BPoints(3); 

    APoints[0] = Point_3(2, 2, 0.9423616295572568); 
    APoints[1] = Point_3(0.9685134704003172, 2, 0.9678422992674797); 
    APoints[2] = Point_3(2, 1.124710354419025, 1.068692504586136); 

    BPoints[0] = Point_3(2.5, 2.5, 1.442361629557257); 
    BPoints[1] = Point_3(1.588259113885977, 2.5, 0.5); 
    BPoints[2] = Point_3(2.5, 1.624710354419025, 1.568692504586136); 

    Triangle_3 TriangleA(APoints[0],APoints[1],APoints[2]); 
    Triangle_3 TriangleB(BPoints[0],BPoints[1],BPoints[2]); 
    Triangle_3 TriangleC(BPoints[2],BPoints[1],BPoints[0]); 

    std::cout.precision(16); 
    std::cout << " - Tried to intersect: " << std::endl; 
    std::cout << " - Triangle (A) " << " : " 
       << "(" << TriangleA.vertex(0) << ") " 
       << "(" << TriangleA.vertex(1) << ") " 
       << "(" << TriangleA.vertex(2) << ") " << std::endl; 
    std::cout << " - Triangle (B) " << " : " 
       << "(" << TriangleB.vertex(0) << ") " 
       << "(" << TriangleB.vertex(1) << ") " 
       << "(" << TriangleB.vertex(2) << ") " << std::endl; 
    std::cout << " - Triangle (C) " << " : " 
       << "(" << TriangleC.vertex(0) << ") " 
       << "(" << TriangleC.vertex(1) << ") " 
       << "(" << TriangleC.vertex(2) << ") " << std::endl; 

    if(TriangleB.vertex(0)==TriangleC.vertex(2) && 
     TriangleB.vertex(1)==TriangleC.vertex(1) && 
     TriangleB.vertex(2)==TriangleC.vertex(0)) 
    { 
     std::cout << " - Triangles (B) and (C) have the same vertices " << std::endl; 
    } 

    bool bIntersectAB = CGAL::do_intersect(TriangleA,TriangleB); 
    bool bIntersectAC = CGAL::do_intersect(TriangleA,TriangleC); 

    bool bIntersectInexactAB = CGAL::intersection(TriangleA,TriangleB); 
    bool bIntersectInexactAC = CGAL::intersection(TriangleA,TriangleC); 

    if(bIntersectAB) 
    { 
     std::cout << " --> A and B are intersecting (exact) ..." << std::endl; 
    } 

    if(bIntersectAC) 
    { 
     std::cout << " --> A and C are intersecting (exact) ..." << std::endl; 
    } 

    if(bIntersectInexactAB) 
    { 
     std::cout << " --> A and B are intersecting (inexact) ..." << std::endl; 
    } 

    if(bIntersectInexactAC) 
    { 
     std::cout << " --> A and C are intersecting (inexact) ..." << std::endl; 
    } 

    return 0; 
} 

下面是輸出...

- Tried to intersect: 
    - Triangle (A) : (2 2 0.9423616295572568) (0.9685134704003172 2 0.9678422992674797) (2 1.124710354419025 1.068692504586136) 
    - Triangle (B) : (2.5 2.5 1.442361629557257) (1.588259113885977 2.5 0.5) (2.5 1.624710354419025 1.568692504586136) 
    - Triangle (C) : (2.5 1.624710354419025 1.568692504586136) (1.588259113885977 2.5 0.5) (2.5 2.5 1.442361629557257) 
    - Triangles (B) and (C) have the same vertices 
--> A and C are intersecting (inexact) ... 

...和一個帶有兩個三角形(A:頂點1,2,3; B:頂點11,12,13)和「交點」(段21-22)的圖形,使用該程序的類似版本找到。

enter image description here

出了什麼問題?我在OS X 10.10.5(Yosemite)上使用CGAL 4.6.1。提前致謝!

回答

1

我也將這個問題發送到CGAL的郵件列表,開發人員回答說這種行爲不是bug,儘管 這是不幸的。 intersection是一個通用函數,對所有CGAL內核都以相同的方式實現,它使用一個並不總是由不精確的內核正確處理的步驟 - 因此交集錯誤。據在CGAL的GitHub的頁面this線程,

爲了繼續使用非精確構造一個內核,我通常建議先致電do_intersect謂詞,然後使用調用使用EPECK交集功能上轉換的飛行元CGAL::Cartesian_converter。您必須使用另一個CGAL::Cartesian_converter轉換輸出。撥打do_intersect不是強制性的,通常取決於您的設置。