All Projects → mapbox → Delaunator

mapbox / Delaunator

Licence: isc
An incredibly fast JavaScript library for Delaunay triangulation of 2D points

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Delaunator

Delaunator Cpp
A really fast C++ library for Delaunay triangulation of 2D points
Stars: ✭ 244 (-85.13%)
Mutual labels:  algorithm, 2d, computational-geometry, triangulation
Cavaliercontours
2D polyline library for offsetting, combining, etc.
Stars: ✭ 135 (-91.77%)
Mutual labels:  algorithm, 2d, computational-geometry
Kdbush
A fast static index for 2D points
Stars: ✭ 412 (-74.89%)
Mutual labels:  algorithm, computational-geometry, fast
Tinfour
Delaunay and Constrained Delaunay Triangulations in Java, providing high-performance utilities for modeling surfaces with support for Lidar LAS files, Digital Elevation Models (DEM), finite element analysis, path planning, natural neighbor interpolation, and other applications of Triangulated Irregular Networks (TIN)
Stars: ✭ 119 (-92.75%)
Mutual labels:  triangulation, computational-geometry, delaunay
Geokdbush
The fastest spatial index for geographic locations in JavaScript
Stars: ✭ 251 (-84.7%)
Mutual labels:  algorithm, computational-geometry, fast
Polysnap
A work in progress polygon operations library with integer snap-rounding
Stars: ✭ 14 (-99.15%)
Mutual labels:  algorithm, computational-geometry, fast
Earcut
The fastest and smallest JavaScript polygon triangulation library for your WebGL apps
Stars: ✭ 1,359 (-17.18%)
Mutual labels:  algorithm, computational-geometry, triangulation
Procedural-Shape-Generation
An Unity package, enabling user to generate shapes by scripting.
Stars: ✭ 19 (-98.84%)
Mutual labels:  triangulation, 2d
rtriangulate
A Rust implementation of the Bourke Delaunay triangulation algorithm.
Stars: ✭ 20 (-98.78%)
Mutual labels:  triangulation, delaunay
Delaunay Triangulation
C++ version the delaunay triangulation
Stars: ✭ 339 (-79.34%)
Mutual labels:  algorithm, triangulation
Earcut.hpp
Fast, header-only polygon triangulation
Stars: ✭ 447 (-72.76%)
Mutual labels:  algorithm, triangulation
Ahocorasickdoublearraytrie
An extremely fast implementation of Aho Corasick algorithm based on Double Array Trie.
Stars: ✭ 695 (-57.65%)
Mutual labels:  algorithm, fast
Turf
A modular geospatial engine written in JavaScript
Stars: ✭ 6,659 (+305.79%)
Mutual labels:  algorithm, computational-geometry
delaunay-triangulation-algorithm
Delaunay Triangulation
Stars: ✭ 25 (-98.48%)
Mutual labels:  triangulation, delaunay
DelaunayVoronoi
C# implementation of the Bowyer–Watson algorithm for Delaunay triangulation
Stars: ✭ 131 (-92.02%)
Mutual labels:  triangulation, delaunay
Computational Geometry
Computational Geometry Unity library with implementations of intersection algorithms, triangulations like delaunay, voronoi diagrams, polygon clipping, bezier curves, ear clipping, convex hulls, mesh simplification, etc
Stars: ✭ 325 (-80.2%)
Mutual labels:  computational-geometry, triangulation
SplashGeom
Open-source C++ library for geometry and linear algebra
Stars: ✭ 22 (-98.66%)
Mutual labels:  triangulation, computational-geometry
weaver
A spider tapestry weaver
Stars: ✭ 72 (-95.61%)
Mutual labels:  triangulation, delaunay
Geometry2d
Unity3D: A set of helper classes for 2D geometric calculations.
Stars: ✭ 40 (-97.56%)
Mutual labels:  2d, triangulation
Polytri
🔺 Fast and simple polygon triangulation library.
Stars: ✭ 37 (-97.75%)
Mutual labels:  computational-geometry, triangulation

Delaunator Build Status

An incredibly fast and robust JavaScript library for Delaunay triangulation of 2D points.

Delaunay triangulation example

Projects based on Delaunator

  • d3-delaunay for Voronoi diagrams, search, traversal and rendering (a part of D3).
  • d3-geo-voronoi for Delaunay triangulations and Voronoi diagrams on a sphere (e.g. for geographic locations).

Example

const coords = [168,180, 168,178, 168,179, 168,181, 168,183, ...];

const delaunay = new Delaunator(coords);
console.log(delaunay.triangles);
// [623, 636, 619,  636, 444, 619, ...]

Install

Install with NPM (npm install delaunator) or Yarn (yarn add delaunator), then import as an ES module:

import Delaunator from 'delaunator';

To use as a module in a browser:

<script type="module">
    import Delaunator from 'https://cdn.skypack.dev/[email protected]';
</script>

Or use a browser UMD build that exposes a Delaunator global variable:

<script src="https://unpkg.com/[email protected]/delaunator.min.js"></script>

API Reference

new Delaunator(coords)

Constructs a delaunay triangulation object given an array of point coordinates of the form: [x0, y0, x1, y1, ...] (use a typed array for best performance).

Delaunator.from(points[, getX, getY])

Constructs a delaunay triangulation object given an array of points ([x, y] by default). getX and getY are optional functions of the form (point) => value for custom point formats. Duplicate points are skipped.

delaunay.triangles

A Uint32Array array of triangle vertex indices (each group of three numbers forms a triangle). All triangles are directed counterclockwise.

To get the coordinates of all triangles, use:

for (let i = 0; i < triangles.length; i += 3) {
    coordinates.push([
        points[triangles[i]],
        points[triangles[i + 1]],
        points[triangles[i + 2]]
    ]);
}

delaunay.halfedges

A Int32Array array of triangle half-edge indices that allows you to traverse the triangulation. i-th half-edge in the array corresponds to vertex triangles[i] the half-edge is coming from. halfedges[i] is the index of a twin half-edge in an adjacent triangle (or -1 for outer half-edges on the convex hull).

The flat array-based data structures might be counterintuitive, but they're one of the key reasons this library is fast.

delaunay.hull

A Uint32Array array of indices that reference points on the convex hull of the input data, counter-clockwise.

delaunay.coords

An array of input coordinates in the form [x0, y0, x1, y1, ....], of the type provided in the constructor (or Float64Array if you used Delaunator.from).

delaunay.update()

Updates the triangulation if you modified delaunay.coords values in place, avoiding expensive memory allocations. Useful for iterative relaxation algorithms such as Lloyd's.

Performance

Benchmark results against other Delaunay JS libraries (npm run bench on Macbook Pro Retina 15" 2017, Node v10.10.0):

  uniform 100k gauss 100k grid 100k degen 100k uniform 1 million gauss 1 million grid 1 million degen 1 million
delaunator 82ms 61ms 66ms 25ms 1.07s 950ms 830ms 278ms
faster‑delaunay 473ms 411ms 272ms 68ms 4.27s 4.62s 4.3s 810ms
incremental‑delaunay 547ms 505ms 172ms 528ms 5.9s 6.08s 2.11s 6.09s
d3‑voronoi 972ms 909ms 358ms 720ms 15.04s 13.86s 5.55s 11.13s
delaunay‑fast 3.8s 4s 12.57s timeout 132s 138s 399s timeout
delaunay 4.85s 5.73s 15.05s timeout 156s 178s 326s timeout
delaunay‑triangulate 2.24s 2.04s OOM 1.51s OOM OOM OOM OOM
cdt2d 45s 51s 118s 17s timeout timeout timeout timeout

Papers

The algorithm is based on ideas from the following papers:

Robustness

Delaunator should produce valid output even on highly degenerate input. It does so by depending on robust-predicates, a modern port of Jonathan Shewchuk's robust geometric predicates, an industry standard in computational geometry.

Ports to other languages

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].