Skip to content

lchHueKmeans

lchHueKmeans<S>(entries, k, options?): KmeansCluster<number>[]

Defined in: packages/math-color/src/models/lch-hue-kmeans.ts:49

Weighted circular k-means on Lch hue.

Clusters entries by hue angle only — lightness and chroma are ignored during assignment. Coverage weights influence both k-means++ seeding (proportional to weight × d²) and the centroid update (weighted circular mean), so dominant palette entries carry more influence than minor ones.

Handles the 0°/360° wrap-around correctly: centroids are computed via atan2(Σ w·sin h, Σ w·cos h) rather than arithmetic mean.

Achromatic inputs (undefined hue) must be excluded before calling this function.

S extends string

HueEntry<S>[]

Lch colors with associated coverage weights.

number

Desired number of hue clusters; clamped to min(k, entries.length).

KmeansOptions

Optional k-means algorithm options (iterations, convergence, PRNG seed).

KmeansCluster<number>[]

Clusters; each centroid is a weighted circular mean hue in degrees [0, 360).