Hemda
Hemda

Reputation: 13

How to make a polygon from from a shape that's a result of subtraction

How to make a polygon from from a shape that's a result of subtraction. It starts off with one polygon (poly1). Then another polygon is added (poly2) which intersects the first one. I subtract poly2 from poly1, which leaves me with an instance of Shape (remained). I would like to make a new polygon from what's left of poly1 after the subtraction (remained). Couldn't find a way to do it. Can you help please?

enter image description here

Polygon poly1, poly2; 
Shape remained;
…
remained = Shape.subtract(poly1, poly2);

Upvotes: 1

Views: 151

Answers (1)

mipa
mipa

Reputation: 10650

The result of this operation will in general be a Path and you can iterate over its elements like this and create a new Polygon from them.

    Path path = (Path)remained;
    for (PathElement pe : path.getElements()) {
        ...
    }

But you have to make sure that the result of this operation actually is a polygon because this may not be the case.

Upvotes: 1

Related Questions