polygon intersection possible issue

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

polygon intersection possible issue

joan
Hello,

I'm trying to compute the intersection of 2 polygons that should produce a 2 polygons result.

Unfortunately my result size is 0 and should be 2.
Do I have something wrong ?

Joan


This is the code used :

        typedef double coordinate_type;
        typedef boost::geometry::model::d2::point_xy<coordinate_type> point_type;
        typedef boost::geometry::model::polygon<point_type> polygon;
        typedef boost::geometry::model::multi_polygon<polygon> multipolygon;

        polygon green, blue;

        boost::geometry::read_wkt("POLYGON((0 0,4 0,4 4, 0 4, 0 0))", green);
        boost::geometry::read_wkt("POLYGON((-2 0, 2 1, -1 2, 2 3, -2 4, -2 0))", blue);

        multipolygon  result;
        boost::geometry::intersection(green, blue, result);

        // Investigate results
        create_svg("intersect_output.svg", green, blue, result);
        cout << result.size() << endl;
Reply | Threaded
Open this post in threaded view
|

Re: polygon intersection possible issue

joan
I got my mistake, polygons should be CW instead of CCW.
Works fine with CW polygons.

Joan
Reply | Threaded
Open this post in threaded view
|

Re: polygon intersection possible issue

Mateusz Loskot
Administrator
In reply to this post by joan
On 24 October 2013 09:57, joan <[hidden email]> wrote:
> Hello,
>
> I'm trying to compute the intersection of 2 polygons that should produce a 2
> polygons result.
> <http://boost-geometry.203548.n3.nabble.com/file/n4025686/Capture.png>
> Unfortunately my result size is 0 and should be 2.
> Do I have something wrong ?
>
>         typedef boost::geometry::model::polygon<point_type> polygon;

Specialize your polygon as CCW:

 typedef boost::geometry::model::polygon<point_type, false> polygon;

and you should get 2.

Best regards,
--
Mateusz  Loskot, http://mateusz.loskot.net
_______________________________________________
Geometry mailing list
[hidden email]
http://lists.boost.org/mailman/listinfo.cgi/geometry
--
Mateusz Loskot
http://mateusz.loskot.net