4

I'm currently working on a private project which depends on some operations on polygons using the Boost C++ Libraries.

I'm currently trying to work with the inner polygon/negative polygon concept.

What I need to do now is to join three polygons where two of them have a positive (counterclockwise) outer polygon and an negative (clockwise) inner polygon.

The third one is a negative polygon a new polygon object with a negative area - points in clockwise direction. And this is the point where I'm not fully sure how to handle the situation.

Here's a picture of those three polygons. The middle one which connects the left upper polygon with the right lower one is the negative one.

Polygons including the negative one

Now what I would like to do is to join all three polygons through the union function. What I expect union to do is to cut away the positive parts of the polygons 1 and 3 (the positive polygons) and return the remaining two polygons of 1 and 3.

What I actually get are my polygons 1 and 3 untouched as there would be no negative polygon 2.

Any help will be appreciated.

Edit:

What I need to get is a vector not a bitmap or a picture or whatever. These Picture are just used to better visualize what I have and what I need.

Those three Polygons are actually not more than an vector of x and y points.

Here's a picture of what I would expect to be the correct result of union of all three polygons:

Edit2: Corrected the result

Result

3
  • Can you add a picture of intended output?
    – Daniel
    Commented Dec 5, 2012 at 16:42
  • 1
    Your expected result does not look right. Are these polygons? If so, why is the boundary looks so strange? I thought your original polygons were square "donuts". In that case the negative polygon should just bite the pieces out of those donuts, turning them into C-shaped polygons. Commented Dec 6, 2012 at 8:38
  • You are a 100% right. I corrected my picture now and that should be what I actually expect...
    – Evils
    Commented Dec 6, 2012 at 8:55

2 Answers 2

0

How do you want unions to work? Usually a union of polygons 1 and 2 would result in polygon 3, but I suspect for your use case you want it to result in polygon 4. If that's the case, you can simply do a union of all the clockwise paths, then do a union of the counterclockwise paths, then take the difference of the former from the latter. If you want the union to result in polygon 3, then I don't think there's a consistent way to do what you want.

-1

Good plan is to consider your polygons as a bitmap (of booleans): Every polygon will be blit to a bitmap of type (R,R)->bool. Once it's in bitmap format, negative polygons are just andnot-operations on the booleans:

class Bitmap { virtual bool Map(float x, float y) const=0; };
class AndNot : public Bitmap {
public:
   AndNot(Bitmap &bm1, Bitmap &bm2) : bm1(bm1), bm2(bm2) { }
   bool Map(float x, float y) const {
      return b1.Map(x,y) && !b2.Map(x,y);
   }
private:
   Bitmap &bm1, &bm2;
};
1
  • Sorry, but I don't think this will help me as I don't need bitmaps neither bool's
    – Evils
    Commented Dec 7, 2012 at 13:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.