Search code examples
c#colors

Dominant wavelength calculator from chromaticity coordinates


is there any function, or library, preferably in c#, that could calculate the dominant wavelength of a color, using ONLY the x and y coordinates as input? I have learned how the process goes, that you need to draw a line from the white point (0.33, 0.33), through my point to the violet edge, and that interception is the dominant wavelength, but all the libraries I have found require that the interception coordinates are already calculated. If someone can please give me a library, or piece of code, how to calculate the dominant wavelength using ONLY the x and y coordinates I would be extremely grateful.

enter image description here


Solution

  • Unicolour, a colour library for I've developed for .NET, has recently been updated with this functionality.

    var chromaticity = new Chromaticity(0.1, 0.8);
    var hyperGreen = new Unicolour(chromaticity);
    var dominantWavelength = hyperGreen.DominantWavelength;
    

    It calculates the intercept coordinates for you, though since it's open source you can see how it works by looking at the Spectral class.