Skip to content

d-rk/polygonclipping

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

polygon clipping

CircleCI Maven Central

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 Sample1 Sample1 Sample1 Sample1

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

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

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 Polygon with hole offset 1 Polygon with hole offset

About

polygon clipping library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages