一个极其快速的 JavaScript 库,用于 2D 点的 Delaunay 三角化
一个极其快速且稳健的 JavaScript 库,用于对二维点进行 Delaunay 三角剖分。
const coords = [377,479, 453,434, 326,387, 444,359, 511,389,
586,429, 470,315, 622,493, 627,367, 570,314];
const delaunay = new Delaunator(coords);
console.log(delaunay.triangles);
// [4,3,1, 4,6,3, 1,5,4, 4,9,6, 2,0,1, 1,7,5,
// 5,9,4, 6,2,3, 3,2,1, 5,8,9, 0,7,1, 5,7,8]使用 NPM(npm install delaunator)或 Yarn(yarn add delaunator)安装,然后作为 ES 模块导入:
import Delaunator from 'delaunator';要在浏览器中作为模块使用:
<script type="module">
import Delaunator from 'https://cdn.skypack.dev/[email protected]';
</script>或者使用浏览器 UMD 构建版本,它会暴露一个 Delaunator 全局变量:
<script src="https://unpkg.com/[email protected]/delaunator.min.js"></script>根据点坐标数组构造德劳内三角剖分对象,坐标数组格式为:
[x0, y0, x1, y1, ...](使用类型化数组可获得最佳性能)。
根据点数组(默认为 [x, y])构造德劳内三角剖分对象。
getX 和 getY 是可选函数,形式为 (point) => value,用于自定义点格式。
重复的点会被跳过。
一个 Uint32Array 数组,包含三角形顶点索引(每三个数字组成一个三角形)。
所有三角形均为逆时针方向。
暂无开放 Issues,或尚未同步最近议题。