Skip to Content.
Sympa Menu

cgal-discuss - possible bug in CGAL::intersection

Subject: CGAL users discussion list

List archive

possible bug in CGAL::intersection


Chronological Thread 
  • From:
  • To:
  • Subject: possible bug in CGAL::intersection
  • Date: Thu, 4 Oct 2007 23:54:10 +0200

i found a possible bug in CGAL::intersection when i try to intersect two
objects of type Triangle_2. in the case where the intersection should be a
triangle something doesn't work properly, the result is that i the function
returns no object.

i'm using CGAL version 3.1, but as far as i can see from the list of changes
this problem hasn't been resolved in version 3.3

i use microsoft visual c++ compiler.

the following code should return a Triangle_2 when i try intersecting the
triangles {(0,0),(1,0),(0,1)} and {(0.1,0.1),(1.1,0.1),(0.1,1)}.



#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/intersections.h>
#include <CGAL/Polygon_2.h>

#include <fstream>

struct K : CGAL::Exact_predicates_inexact_constructions_kernel {};

typedef K::Point_2 Point;

int main()
{
CGAL::Triangle_2<K> aTri,aTri2,inters_tri;
CGAL::Object result;
Point inters_pt;
CGAL::Segment_2<K> inters_seg;
CGAL::Polygon_2<K> aPoly;
std::vector<Point> intersections,inters_pts;

aTri = CGAL::Triangle_2<K>(Point(0,0),Point(1,0),Point(0,1));
aTri2 =
CGAL::Triangle_2<K>(Point(0.1,0.1),Point(1.1,0.1),Point(0.1,1));
std::cout<<"Triangle 1: "<<aTri<<" Triangle 2: "<<aTri2<<std::endl;
result = CGAL::intersection(aTri2,aTri);
if (CGAL::assign(inters_pt, result)){
std::cout<<"Point\n";
}else if (CGAL::assign(inters_pts,result)){
std::cout<<"multiple Points\n";
}else if (CGAL::assign(inters_seg,result)){
std::cout<<"Segment\n";
}else if (CGAL::assign(inters_tri,result)){
std::cout<<"Triangle\n";
}else{
std::cout<<"No intersection\n";
}

return 0;
}


as a fix i made a change to the file triangle_2_triangle_2_intersection.c
such that the case when a triangle should be returned is treated as if it
would be a polygon (in which case a vector of points is returned). around
line 380 i made the following change:


case is_t::TRIANGLE: {
/* typename K::Triangle_2 itr;
ispair.intersection(itr);
return make_object(itr);
*/ typedef std::vector<typename K::Point_2> Container;
Container points(ispair.vertex_count());
for (int i =0; i < ispair.vertex_count(); i++) {
points[i] = ispair.vertex(i);
}
return make_object(points);
}

unless this issue is a result of a problem in my code (e.g. type of
'inters_tri') i believe this is a bug in version 3.1.

best regards
matthias preisig



Archive powered by MHonArc 2.6.16.

Top of Page