0

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.

Paul R
  • 208,748
  • 37
  • 389
  • 560
user3013172
  • 1,637
  • 3
  • 15
  • 26
  • why dont you push `green_container` instead of `green` as `vector` and after that you make `polygon green = green_container[0];` – Luka Rahne Jun 02 '14 at 18:32
  • 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 want – user3013172 Jun 02 '14 at 18:37
  • Let's see some polygon definitions. I have the suspicion that the polygon in the rist picture is actually filled and therefore the difference looks okay? – sehe Jun 02 '14 at 18:42
  • i dont know what you mean – user3013172 Jun 02 '14 at 18:43
  • 1
    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 Jun 02 '14 at 20:22
  • it is a polygon. i create it by adding points one by one that i have stored in memory – user3013172 Jun 02 '14 at 21:13
  • 1
    @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 Jun 03 '14 at 06:23
  • 1
    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 Aug 18 '15 at 17:34

1 Answers1

1

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().

Dig-Doug
  • 91
  • 8