Convert a Lab color to an LCH color
Turn a and b into chroma and hue degrees.
function labToLch([l, a, b]) { return [l, Math.hypot(a, b), ((Math.atan2(b, a) * 180) / Math.PI + 360) % 360]; }
Input & expected output
Input
[
52,
40,
30
]Expected output
[
52,
50,
36.86989764584405
]The edge case
Input
[
50,
0,
-10
]Expected output
[
50,
10,
270
]Know the limits
- Hue is normalized to 0–360°; the original could return negative hues, as the edge case would.
- Assumes CIE Lab input; it does not convert from sRGB.
The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.
Source & maintenance
Based on Convert a LAB color to an LCH color from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.
Uses Math.hypot and normalizes hue to 0–360 degrees. Original MDX retained as inert source evidence.
Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.
Keep exploring
- Convert Celsius to Fahrenheit — Apply the temperature conversion without rounding the result.
- Convert hex to RGB — Expand #rgb if needed and read the red, green and blue channels.
- Convert URL parameters to object — Read a query string into an object; repeated keys become arrays.