0
votes

i am trying to substract one polygon from another with boost::geometry::difference.

First of all i create 2 polygons, lets call them red and blue. I know the polygons are created correctly because y plotted them.

Now, if i compute the difference between those polygons like so:

    boost::geometry::difference( blue, red,green);

Where green should be the result of the substraction.

I then get the points from green with green.outer() (i know that green is actually a containter, but given that i know that i will only get one polygon as a result i wanted to simplify my example) and plot them.

This is the result i get:

enter image description here

That is not the result i want to get. How could i make boost return the blue polygon minus the red one? like this:

enter image description here

EDIT: I tried computing the intersection between those polygons and i get what i want. Thats odd. don't know if i am doing something wrong or boost people don't know math.

1
why dont you push green_container instead of green as vector<polygon> and after that you make polygon green = green_container[0];Luka Rahne
thats what i said i do, but didnt write it here because it was easier to understand. Funny thing, if i compute the intersection, i get what i wantuser3013172
I mean the varying width of the blue "path" suggests to me that it's actually not the contour (outline) of a polygon, but rather a closed polygon describing the shape that, itself, surrounds an "inverted space" that is not part of the polygon. (Also, rist* should have been first in my previous comment)sehe
@user3013172 I never disputed that it was /a/ polygon. I just said that we would like to see the polygon. I'm voting to close because there isn't enough information to reproduce the issue.sehe
As mentioned above the last parameter should be either a vector of Polygons or a MultiPolygon. Furthermore, without seing actual data I can only say that the input must be valid, i.e. the points order and closure of polygons must be the same as the one defined by traits for Polygon type. E.g. by default if not explicitly set bg::model::polygon<> must contain clockwise and closed polygon data. If you're not sure about the order you may call bg::correct() function.Adam Wulkiewicz

1 Answers

1
votes

I had a very similar issue. I found that some of my difference operations worked properly while others did not.

In my case, it was due to incorrect vertex winding as Adam suggested in the comments. I fixed it using boost::geometry::correct().