java Earcut
java Earcut
Maven dependency:
<dependency> <groupId>io.github.earcut4j</groupId> <artifactId>earcut4j</artifactId> <version>2.2.2</version> </dependency>
使用案例:
import java.util.List; import earcut4j.Earcut; public class Test1 { public static void main(String[] args) { // triangulating a polygon with a hole List<Integer> triangles1 = Earcut.earcut(new double[] { 0, 0, 100, 0, 100, 100, 0, 100, 20, 20, 80, 20, 80, 80, 20, 80 }, new int[] { 4 }, 2); // [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2] System.out.println(triangles1); // triangulating a polygon with 3d coords List<Integer> triangles2 = Earcut.earcut(new double[] { 10, 0, 1, 0, 50, 2, 60, 60, 3, 70, 10, 4 }, null, 3); // [1,0,3, 3,2,1] System.out.println(triangles2); } }
输出:
[3, 0, 4, 5, 4, 0, 3, 4, 7, 5, 0, 1, 2, 3, 7, 6, 5, 1, 2, 7, 6, 6, 1, 2]
[1, 0, 3, 3, 2, 1]
参考:https://github.com/earcut4j/earcut4j
############################3
QQ 3087438119