Contribution to poly2tri project: https://github.com/greenm01/poly2tri.java
This is a temporary fork, in order to add various features.
Based on the paper "Sweep-line algorithm for constrained Delaunay triangulation" by V. Domiter and and B. Zalik
Officially supported langs: C++, Java
Community based langs (unsupported):
* AS3
* C
* C#, C#(basic)
* Go
* Haxe
* Javascript
* Python, Python3
* Ruby
Try it out online: click me or me!
Video poly2tri-java
If you want to triangulate complex or weak polygons you will need to prepare your data
with a polygon clipping library like:
Clipper (C++, C#, Delphi)
Javascript Clipper
Java Clipper
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();
}
}