EarCut针对Polygon进行三角剖分支持多边形内含有洞

polygon triangulation

如果你想对一个封闭的区域进行三角剖分

譬如一个省份的行政区域进行三角剖分

譬如你想对一个省份进行三角剖分,但是又需要排除点该省的某一个市的区域 那么你需要用到Earcut

维基百科地址:

https://en.wikipedia.org/wiki/Polygon_triangulation

Usage

/**
 * Triangulates the given polygon
 *
 * @param data        is a flat array of vertice coordinates like [x0,y0, x1,y1, x2,y2, ...].
 * @param holeIndices is an array of hole indices if any (e.g. [5, 8] for a 12-vertice input would mean one hole with vertices 5–7 and another with 8–11).
 * @param dim         is the number of coordinates per vertice in the input array
 * @return List containing groups of three vertice indices in the resulting array forms a triangle.
 */
var triangles = earcut(double[] data, int[] holeIndices, int dim);

 

 //sample useage for triangulating a polygon

var triangles = earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]
// triangulating a polygon with 3d coords
earcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3);
// triangulating a polygon with a hole
earcut([0,0, 100,0, 100,100, 0,100,  20,20, 80,20, 80,80, 20,80], [4]);
// [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2]

[4]的意思是这8个顶点中 从第4个开始是hole的顶点,前面的是polygon的顶点

https://github.com/mapbox/earcut (Javascript)

https://github.com/mapbox/earcut.hpp (C++11)

https://github.com/the3deers/earcut-java (Java)

https://github.com/oberbichler/earcut.net (C#)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值