npm

Check out our latest tech talk, "JavaScript Supply Chain Security" presented by VP of Security, Adam Baldwin.Watch it here »

triangulate-contours

1.0.2 • Public • Published

triangulate-contours

stable

Triangulates a series of contours using Tess2.js. Returns a simplicial complex with { positions, cells }. Works with 2D and 3D coordinates, and contours can be in reverse winding order for holes.

var triangulate = require('triangulate-contours')
 
var contours = [
    [ [10,50], [55, 23], [15, 62], [23, 63], [63, 21], [11, -2] ],
    [ [50,50], [62,21], [24,52] ]
]
 
var results = triangulate(contours)
 
console.log(results)
/*
    { positions: [ ... ], cells: [ ... ] }
 */

positions are a series of points with the same number of components as the input, and cells is a list of faces with indices into the positions array.

Usage

NPM

triangulate(contours[, opts])

Triangulates an array of polylines, each polyline representing a contour. The options will be pushed into Tess2 constructor; but if no vertexSize is specified, it will be guessed based on the input array (i.e. 2-dimensional vs. 3-dimensional vectors).

Returns a simplicial complex, i.e. a simple object:

{ 
    positions: [ [x,y], .. ], 
    cells: [ [a,b,c], .. ] 
}

See Also

For more robust triangulation than Tess2, see the following:

License

MIT, see LICENSE.md for details.

install

npm i triangulate-contours

Downloadsweekly downloads

63

version

1.0.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability