Skip to content

Instantly share code, notes, and snippets.

@sloriot
Created January 24, 2019 08:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sloriot/4815f629b4051299b3665f202aa68617 to your computer and use it in GitHub Desktop.
Save sloriot/4815f629b4051299b3665f202aa68617 to your computer and use it in GitHub Desktop.
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Interval_nt.h>
typedef CGAL::Interval_nt<> FT;
typedef CGAL::Simple_cartesian<FT> K;
typedef K::Point_2 Point_2;
typedef K::Triangle_2 Triangle_2;
int main()
{
double t = 0.1;
Point_2 p1(FT(0-t,0+t), FT(0-t, 0+t));
Point_2 p2(FT(1-t,1+t), FT(0-t, 0+t));
Point_2 p3(FT(1-t,1+t), FT(1-t, 1+t));
Point_2 p4(FT(0-t,0+t), FT(1-t, 1+t));
Triangle_2 t1(p1,p2,p3), t2(p4,p3,p2);
try{
CGAL::Uncertain<bool> res = CGAL::do_intersect(t1,t2);
if (CGAL::possibly(res))
std::cout << "Triangles might intersect\n";
else
std::cout << "Triangles cannot intersect\n";
}
catch(CGAL::Uncertain_conversion_exception&)
{
std::cout << "Result is unknown\n";
}
Point_2 p5(FT(10-t,10+t), FT(20-t, 20+t));
Point_2 p6(FT(11-t,11+t), FT(20-t, 20+t));
Point_2 p7(FT(11-t,11+t), FT(21-t, 21+t));
Triangle_2 t3(p5,p6,p7);
try{
CGAL::Uncertain<bool> res = CGAL::do_intersect(t1,t3);
if (CGAL::possibly(res))
std::cout << "Triangles might intersect\n";
else
std::cout << "Triangles cannot intersect\n";
}
catch(CGAL::Uncertain_conversion_exception&)
{
std::cout << "Result is unknown\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment