geom-triangulate
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

geom-triangulate

Splits quad or polygon faces into triangles.

Implemented using naive face triangulation - builds a triangle fan anchored at the first face vertex.

Installation

npm install geom-triangulate

Usage

import triangulate from "geom-triangulate";

const faces = [
  [0, 1, 2, 3],
  [3, 2, 5, 4],
  // ...
];

// Compute cells
const triangulatedCells = triangulate(faces); // [[0, 1, 2], [0, 2, 3], ...]

API

triangulate(faces): cells

Parameters

  • faces: TypedArray | Array | Array<[x, y, z]> – list of face indices new Array([a, b, c, d], [a, b, c, d], ...)

Note: if faces is a TypedArray (eg. new Uint32Array([a, b, c, d, a, b, c, d, ...]) or a flat array of positions (eg. new Array(a, b, c, d, a, b, c, d, ...)), we assumes faces are triangles so a copy will be returned.

Returns

  • cells: Array<[x, y, z]> – simplicial complex geometry cells (new Array([a, b, c], [a, b, c], ...))

License

MIT. See license file.

Package Sidebar

Install

npm i geom-triangulate

Weekly Downloads

8

Version

2.0.1

License

MIT

Unpacked Size

50.1 kB

Total Files

18

Last publish

Collaborators

  • vorg