poly2tri is a 2D constrained Delaunay triangulation library that implements the Sweep-line algorithm for constrained Delaunay triangulation described in V. Domiter and and B. Zalik
poly2tri is a contribution to poly2tri.java project: https://github.com/greenm01/poly2tri.java
Since there are no Input validation of the data given for triangulation you need to think about this.
-
Poly2Tri do not support multiple points with exact same Coordinate. (This is an issue when using constraints/polygons) a. So if you have a cyclic function that generates points make sure you don't add the same Coordinate twice. b. If you are given input and aren't sure same point exist twice you need to check for this yourself. Poly2Tri does a simple check if first and last point is same when you create a polygon but that is all the input validation.
-
Poly2Tri do not support intersecting constraints(yet) a. This means only simple polygons are supported
import org.poly2tri.Poly2Tri;
import org.poly2tri.geometry.polygon.Polygon;
import org.poly2tri.geometry.polygon.PolygonPoint;
import org.poly2tri.triangulation.delaunay.DelaunayTriangle;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
// Prepare input data
Polygon polygon = new Polygon(Arrays.asList(new PolygonPoint(0, 0, 0),
new PolygonPoint(10, 0, 1),new PolygonPoint(10, 10, 2),new PolygonPoint(0, 10, 3)));
// Launch tessellation
Poly2Tri.triangulate(polygon);
// Gather triangles
List<DelaunayTriangle> triangles = polygon.getTriangles();
}
}
You can include Poly2Tri in your project thanks to Sonatype repository.
To use the current snapshot add in the pom
<repository>
<id>orbisgis-snapshot</id>
<name>OrbisGIS sonatype snapshot repository</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
and the following dependency
<dependency>
<groupId>org.orbisgis</groupId>
<artifactId>poly2tri</artifactId>
<version>0.7.1-SNAPSHOT</version>
</dependency>