Intersection between segment and polygon

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Intersection between segment and polygon

Pol Monsó Purtí
CGAL::intersect and do_intersect take segments, rays, squares... but not polygon_2. And the reverse for Polygon_2 intersection functions, who only takes polygons.

How do you usually solve this, iterating over the segments of the polygon + checking if the ends are inside? Or is there another method?

Cheers and thank you for your support.
Reply | Threaded
Open this post in threaded view
|

Re: Intersection between segment and polygon

teillaud
Administrator
On 28 Jul 2016, at 10:31, Pol Monsó Purtí <[hidden email]> wrote:

CGAL::intersect and do_intersect take segments, rays, squares... but not polygon_2.

Indeed, because intersect is in the CGAL Kernel(s), which only handle(s) constant-size objects, by definition. 

And the reverse for Polygon_2 intersection functions, who only takes polygons.

How do you usually solve this, iterating over the segments of the polygon + checking if the ends are inside? 

Sounds reasonable. 
Alternatively, if you want to use the intersection function of polygons, you can also create another polygon from the two vertices of the segment, then intersect the two polygons. Not sure about efficiency (I don’t precisely know how the intersection of 2 polygons is implemented). 

--
Monique Teillaud 
https://members.loria.fr/Monique.Teillaud/
INRIA Nancy - Grand Est, LORIA 
Institut National de Recherche en Informatique et Automatique 

Reply | Threaded
Open this post in threaded view
|

Re: Intersection between segment and polygon

Pol Monsó Purtí
I remember reading another post claiming a two point degenerate polygon had some issues since one of the latest cgal versions. I couldn't find it again thought, so I might be utterly wrong.

The issue is that I have rays as well, which I can't turn into a degenerate polygon. I'll just take the iteration approach then.

Efficiency is not really an issue, I don't have to perform the operation that many times.

Thanks nonetheless Monique. I think I'll try out turning the segment into a polygon for curiosity.

On Thu, Jul 28, 2016 at 11:02 AM, Monique Teillaud <[hidden email]> wrote:
On 28 Jul 2016, at 10:31, Pol Monsó Purtí <[hidden email]> wrote:

CGAL::intersect and do_intersect take segments, rays, squares... but not polygon_2.

Indeed, because intersect is in the CGAL Kernel(s), which only handle(s) constant-size objects, by definition. 

And the reverse for Polygon_2 intersection functions, who only takes polygons.

How do you usually solve this, iterating over the segments of the polygon + checking if the ends are inside? 

Sounds reasonable. 
Alternatively, if you want to use the intersection function of polygons, you can also create another polygon from the two vertices of the segment, then intersect the two polygons. Not sure about efficiency (I don’t precisely know how the intersection of 2 polygons is implemented). 

--
Monique Teillaud 
https://members.loria.fr/Monique.Teillaud/
INRIA Nancy - Grand Est, LORIA 
Institut National de Recherche en Informatique et Automatique