C++ 三维三角形(CGAL)之间错误的不精确相交
在使用C++ 三维三角形(CGAL)之间错误的不精确相交,c++,cgal,C++,Cgal,在使用CGAL::精确谓词\u不精确构造\u内核内核时,试图在3D空间中相交两个三角形时,我遇到了一个非常奇怪的错误。基本上,我有两个不应该相交的三角形。当测试它们时,函数CGAL::do_intersect总是返回false,但是函数CGAL::intersection根据三角形顶点的顺序建立一个交点 当我使用CGAL::Exact\u谓词\u Exact\u构造\u内核kernel时,这个bug就消失了,但我负担不起在实际场景中使用它 下面是一个带有bug的最小代码。三角形B和C相等(直到顶
CGAL::精确谓词\u不精确构造\u内核内核时,试图在3D空间中相交两个三角形时,我遇到了一个非常奇怪的错误。基本上,我有两个不应该相交的三角形。当测试它们时,函数CGAL::do_intersect
总是返回false
,但是函数CGAL::intersection
根据三角形顶点的顺序建立一个交点
当我使用CGAL::Exact\u谓词\u Exact\u构造\u内核
kernel时,这个bug就消失了,但我负担不起在实际场景中使用它
下面是一个带有bug的最小代码。三角形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;
}
。。。以及一个带有两个三角形(a:顶点1、2、3;B:顶点11、12、13)和“交点”(线段21-22)的图形,使用该程序的类似版本找到
有什么不对劲吗?我在OSX10.10.5(约塞米蒂)上使用CGAL4.6.1。提前谢谢 我也向CGAL的邮件列表发送了这个问题,开发人员回答说,虽然
这是不幸的intersection
是一个通用函数,对所有CGAL内核都以相同的方式实现,它使用的一个步骤并不总是由不精确内核正确处理,因此产生了交叉错误。根据CGAL的GitHub页面上的线程
为了继续使用具有不精确构造的内核,我通常建议首先调用do_intersect
谓词,然后使用EPECK
对使用CGAL::Cartesian_converter
动态转换的原语调用交集函数。您必须使用另一个CGAL::Cartesian_转换器
转换输出。调用do\u intersect
不是强制性的,它通常取决于您的设置
- 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) ...