var points = [[10, 20], [30, 12.5], ...]; var polygon = concaveman(points);
concaveman(points[, concavity = 2, lengthThreshold = 0])
pointsis an array of
concavityis a relative measure of concavity.
1results in a relatively detailed shape,
Infinityresults in a convex hull. You can use values lower than
1, but they can produce pretty crazy shapes.
lengthThreshold: when a segment length is under this threshold, it stops being considered for further detalization. Higher values result in simpler shapes.
The algorithm is based on ideas from the paper A New Concave Hull Algorithm and Concaveness Measure for n-dimensional Datasets, 2012 by Jin-Seo Park and Se-Jong Oh.
This implementation dramatically improves performance over the one stated in the paper
r is a number of output points, to
O(n log n))
by introducing a fast k nearest points to a segment algorithm,
a modification of a depth-first kNN R-tree search using a priority queue.
TypeScript type definitions
are available trough
npm install --save @types/concaveman.