Function triangulate

  • Triangulates the given shape definition by returning an array of triangles. A triangle is defined by three consecutive integers representing vertex indices.

    Example

    Earcut.triangulate(([10,0, 0,50, 60,60, 70,10]);
    // returns [1,0,3, 3,2,1]

    Returns

    A flat array of triangles where each group of three vertices indices forms a triangle.

    Parameters

    • vertices: number[]

      A flat array of vertex coordinates like [x0,y0, x1,y1, x2,y2, ...].

    • Optional holeIndices: number[]

      (Optional) An array of hole indices if any, (e.g. [5, 8] or a 12-vertex input would mean one hole with vertices 5–7 and another with 8–11).

    • Optional dim: number

      The number of coordinates per vertex in the input array. Default is 2.

    Returns Triangle[]