There are no modules declared in this project.
polygon clipping
![Maven Central](https://camo.githubusercontent.com/b08306a9e5caa12d22c780cf6177d63d30f1c8e1adb36d392c39c7fa8e96fc59/68747470733a2f2f6d6176656e2d6261646765732e6865726f6b756170702e636f6d2f6d6176656e2d63656e7472616c2f636f6d2e6769746875622e72616e646f6d2d6477692f706f6c79676f6e2d636c697070696e672f62616467652e737667)
Description
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)
Features
- Boolean operations on polygons with double precision
- Supports complex polygons with holes
Maven Dependency
<dependency>
<groupId>com.github.random-dwi</groupId>
<artifactId>polygon-clipping</artifactId>
<version>1.0.1</version>
</dependency>
Examples
Apply boolean operation
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](https://github.com/random-dwi/polygonclipping/raw/master/images/sample_1.png) |
![Sample1](https://github.com/random-dwi/polygonclipping/raw/master/images/sample_1_intersection.png) |
![Sample1](https://github.com/random-dwi/polygonclipping/raw/master/images/sample_1_difference.png) |
![Sample1](https://github.com/random-dwi/polygonclipping/raw/master/images/sample_1_union.png) |
![Sample1](https://github.com/random-dwi/polygonclipping/raw/master/images/sample_1_xor.png) |
Create polygons
Simple polygon
Code
double[][] points = {{2.5,7.5}, {5.0, 5.0}, {7.5, 7.5}, {5.0, 10.0}};
Polygon p = Polygon.from(points);
Result
![Simple Polygon](https://github.com/random-dwi/polygonclipping/raw/master/images/create_polygon.png)
Polygon with holes
Code
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));
Result
![Polygon with holes](https://github.com/random-dwi/polygonclipping/raw/master/images/create_polygon_with_holes.png)
Polygon Offset
Code
Polygon polygon = new Polygon(new File("/polygons/samples/polygonwithhole"));
Polygon offset = PolygonOffset.createOffsetPolygon(polygon, 0.05);
Result
Offset=0.05 |
Offset=0.1 |
Offset=0.2 |
![Polygon with hole offset](https://github.com/random-dwi/polygonclipping/raw/master/images/polygon_with_hole_offset.png) |
![Polygon with hole offset 1](https://github.com/random-dwi/polygonclipping/raw/master/images/polygon_with_hole_offset_1.png) |
![Polygon with hole offset](https://github.com/random-dwi/polygonclipping/raw/master/images/polygon_with_hole_offset_2.png) |