math docs
    Preparing search index...

    Function triangulatePolygon2

    • Triangulates a simple polygon by ear clipping, writing triangle indices into out as [i0, i1, i2, i3, i4, i5, ...], where each index refers to a vertex of the input polygon. Either winding is accepted (normalised internally).

      out must have room for at least 3 * (n - 2) indices. A complete triangulation returns exactly n - 2 triangles; a smaller count indicates the polygon could not be fully triangulated (e.g. degenerate input).

      Parameters

      • out: number[]

        output array of triangle indices

      • vertices: number[]

        polygon vertices as a flat array [x0, y0, x1, y1, ...]

      • n: number

        number of vertices to read from vertices

      Returns number

      the number of triangles written