在使用CGAL::Exact_predicates_inexact_constructions_kernel内核尝试在3D空间内相交两个三角形时,我遇到了一个非常奇怪的错误。本质上,我有两个不应相交的三角形。测试时,函数CGAL::do_intersect始终返回false,但是函数CGAL::intersection会根据三角形的顶点顺序建立一个交集。

当我使用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),使用该程序的类似版本找到。

c&#43;&#43; - 错误的3D三角形之间的不精确交点(CGAL)-LMLPHP

有什么事吗我在OS X 10.10.5(Yosemite)上使用CGAL 4.6.1。提前致谢!

最佳答案

我也将此问题发送到了CGAL的邮件列表中,并且开发人员回答说,尽管这种行为不是错误,但是
这是不幸的。 intersection是一种通用函数,对所有CGAL内核都以相同的方式实现,并且它使用的一步并不总是由不精确的内核正确处理,因此会出现交集错误。根据CGAL的GitHub页面上的this线程,

关于c++ - 错误的3D三角形之间的不精确交点(CGAL),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32951886/

10-12 22:54