Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Latest commit

 

History

History
62 lines (45 loc) · 2.46 KB

README.md

File metadata and controls

62 lines (45 loc) · 2.46 KB

Poly2Tri

Contribution to poly2tri project: https://github.com/greenm01/poly2tri.java

This is a temporary fork, in order to add various features.

A 2D constrained Delaunay triangulation library

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

BSD 3-Clause License

How to use

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();
  }
}