Skip to Content.
Sympa Menu

cgal-discuss - [cgal-discuss] Bug in assign?

Subject: CGAL users discussion list

List archive

[cgal-discuss] Bug in assign?


Chronological Thread 
  • From: Bernhard Kornberger <>
  • To:
  • Subject: [cgal-discuss] Bug in assign?
  • Date: Fri, 09 Jul 2010 17:25:54 +0200

Hello,

I need to compute the intersection of two triangles in 3D, and
the assign function does not work as expected. Here is a minimal
example: http://geom.at/test_intersection.zip


#include <stdio.h>
#include <iostream>
using namespace std;
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Triangle_3 Triangle_3;
typedef K::Point_3 Point_3;
typedef K::Line_3 Line_3;
typedef K::Segment_3 Segment_3;

int main(int,char**)
{
Point_3 a(10,-30,0);
Point_3 b(-10,-30,0);
Point_3 c(-10,30,0);

Point_3 d(0,50,50);
Point_3 e(0,50,0);
Point_3 f(0,0,0);


// Two input triangles: We want to compute their intersection segment or point
Triangle_3 t1(a,b,c);
Triangle_3 t2(d,e,f);

// If we exchange t1 and t2 we have no problem
// swap(t1,t2);

cout << t1<<endl;
cout << t2<<endl;

// Let's assume that t1 and t2 are not coplanar. Compute the intersection 'pl1_pl2' of their supporting planes.
assert(do_intersect(t1,t2));
CGAL::Object pl1_pl2=CGAL::intersection(t1.supporting_plane(),t2.supporting_plane());
Line_3 lin;
if(CGAL::assign(lin,pl1_pl2)) cout << "The intersection of the supporting planes is a line: "<<lin<<endl;

// We compute the intersection 't1_lin' of the line with the first triangle
assert(do_intersect(t1,lin));
CGAL::Object t1_lin=CGAL::intersection(t1,lin);
Segment_3 tempSegment;
Segment_3 finalSegment;
Point_3 finalPoint;

// ...and if 't1_lin' is a segment
if(CGAL::assign(tempSegment,t1_lin))
{
cout<<"tempSegment is: "<<tempSegment<<endl;
CGAL::Object
t2_tempSegment=CGAL::intersection(t2,tempSegment);
if(CGAL::assign(finalSegment,t2_tempSegment))
{
cout << "The final intersection of t1 and t2 is this segment: "<<finalSegment<<endl;
if(finalSegment.source()==finalSegment.target()) cout << "source and target are the same point"<<endl;
else cout << "The squared distance between source and target is: "<<squared_distance(finalSegment.source(),finalSegment.target())<<endl;
}
else if(CGAL::assign(finalPoint,t2_tempSegment))
{
cout << "The intersection is a single point:
"<<finalPoint<<endl;
}
}
else
{
if(CGAL::assign(finalPoint,t1_lin))
{
cout << "The intersection is a single point (as
expected)"<<endl;
}
else
{
cout << "Oops"<<endl;
}
}
}

The output is:

> ./intersect
10 -30 0 -10 -30 0 -10 30 0
0 50 50 0 50 0 0 0 0
The intersection of the supporting planes is a line: -0 -0 -0 -0 -3e+06 -0
tempSegment is: -0 -0 -0 -0 -30 -0
The final intersection of t1 and t2 is this segment: -0 -0 -0 0 0 0
source and target are the same point


So we get a segment from (0,0,0) to (0,0,0) instead of a Point(0,0,0).


CGAL 3.6.0 on a 64bit machine running Ubuntu:
2.6.32-23-generic #37-Ubuntu SMP Fri Jun 11 08:03:28 UTC 2010 x86_64 GNU/Linux


Best
Bernhard





Archive powered by MHonArc 2.6.16.

Top of Page