twelvechairs
twelvechairs

Reputation: 3

cgal python intersection - trying to return a polygon more complex than a triangle

I'd like to intersect two shapes, returning the overlap between the two. This has to include where the overlap is quite a complex shape (i.e. not just a triangle). Ultimately I want to do this in 3D but I'm running into the same issue even when I simplify this down to 2D that I can't get the resulting shape back as it doesn't match any of the basic "is_foo" template functions for CGAL::Object.

Code is below. Note the two triangles used should return an irregular quadrilateral of ((0.75, 0.0), (0.25, 0.0), (0.0, 1.0), (0.8, 0.2))

from CGAL.CGAL_Kernel import Point_2
from CGAL.CGAL_Kernel import Triangle_2
import CGAL.CGAL_Kernel as CGAL_Kernel

tri1=Triangle_2( *[Point_2(*acoord) for acoord in [[0,0],[1,0],[0,1]] ] )
tri2=Triangle_2( *[Point_2(*acoord) for acoord in [[1,1],[0.5,-1],[0,1]] ] ) 

intersection=CGAL_Kernel.intersection(tri1,tri2)

print(intersection.empty()) ### FALSE
print(intersection.is_Point_2()) ### FALSE
print(intersection.is_Triangle_2()) ### FALSE
print(intersection.is_Segment_2()) ### FALSE
print(intersection.is_Line_2()) ### FALSE
print(intersection.is_Ray_2()) ### FALSE

Is there a way to get the quadrilateral out that I am not understanding? Am I approaching this the wrong way? Thanks in advance

Upvotes: 0

Views: 283

Answers (1)

mgimeno
mgimeno

Reputation: 726

Check out the documentation for intersections. Your intersection is actually a std::vector. In c++ you can get it with

if (const std::vector<Point_2>* res = boost::get<std::vector<Point_2> > 
(&*result)) {
  std::cout << res.size() << std::endl;
}

but in python I don't think you can, in the currently available versions.

Upvotes: 0

Related Questions