![Maven Central](https://camo.githubusercontent.com/ee15cf6a0c9ff9e918b976aa2976c4cfe34a7f0693ec63ce3222981823e9c09f/68747470733a2f2f6d6176656e2d6261646765732e6865726f6b756170702e636f6d2f6d6176656e2d63656e7472616c2f636f6d2e6769746875622e72616e646f6d2d6477692f706f6c79676f6e2d636c697070696e672f62616467652e737667)
A library for polygon clipping written in Java.
It implements the algorithm described in the paper F. Martínez, A.J. Rueda, F.R. Feito. A new algorithm for computing Boolean operations on polygons. Computers & Geosciences, 35 (2009)
- Boolean operations on polygons with double precision
- Supports complex polygons with holes
<dependency>
<groupId>com.github.random-dwi</groupId>
<artifactId>polygon-clipping</artifactId>
<version>1.0.1</version>
</dependency>
Polygon subject = new Polygon(new File("/polygons/samples/rectangle1"));
Polygon clipping = new Polygon(new File("/polygons/samples/triangle2"));
Polygon result1 = BooleanOperation.INTERSECTION(subject, clipping);
Polygon result2 = BooleanOperation.DIFFERENCE(subject, clipping);
Polygon result3 = BooleanOperation.UNION(subject, clipping);
Polygon result4 = BooleanOperation.XOR(subject, clipping);
ORIGINAL |
INTERSECTION |
DIFFERENCE |
UNION |
XOR |
![Sample1](/d-rk/polygonclipping/raw/master/images/sample_1.png) |
![Sample1](/d-rk/polygonclipping/raw/master/images/sample_1_intersection.png) |
![Sample1](/d-rk/polygonclipping/raw/master/images/sample_1_difference.png) |
![Sample1](/d-rk/polygonclipping/raw/master/images/sample_1_union.png) |
![Sample1](/d-rk/polygonclipping/raw/master/images/sample_1_xor.png) |
double[][] points = {{2.5,7.5}, {5.0, 5.0}, {7.5, 7.5}, {5.0, 10.0}};
Polygon p = Polygon.from(points);
![Simple Polygon](/d-rk/polygonclipping/raw/master/images/create_polygon.png)
double[][] outerContour = {{0.0,0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}};
double[][] hole1 = {{0.5,0.5}, {4.0, 0.5}, {2.0, 4.0}};
double[][] hole2 = {{2.5,7.5}, {5.0, 5.0}, {7.5, 7.5}, {5.0, 10.0}};
Polygon p = Polygon.from(Contour.from(outerContour), Contour.from(hole1), Contour.from(hole2));
![Polygon with holes](/d-rk/polygonclipping/raw/master/images/create_polygon_with_holes.png)
Polygon polygon = new Polygon(new File("/polygons/samples/polygonwithhole"));
Polygon offset = PolygonOffset.createOffsetPolygon(polygon, 0.05);
Offset=0.05 |
Offset=0.1 |
Offset=0.2 |
![Polygon with hole offset](/d-rk/polygonclipping/raw/master/images/polygon_with_hole_offset.png) |
![Polygon with hole offset 1](/d-rk/polygonclipping/raw/master/images/polygon_with_hole_offset_1.png) |
![Polygon with hole offset](/d-rk/polygonclipping/raw/master/images/polygon_with_hole_offset_2.png) |