Missing in RhinoCommon: ColorHSV



The SDK offers a whole selection of color classes (Color4f, ColorCMYK,Color HSL, ColorLAB, ColorLCH, ColorXYZ) and conversion methods (or appropriate constructors).

I wonder why there is no Rhino.Display.ColorHSV class? Especially since the color-dialogs in the Rhino-UI are offering RGB and HSV:

Note: HSL and HSV are different (but not too hard to convert, see http://codeitdown.com/hsl-hsb-hsv-color/).


(Dale Fugier) #2

Hi Fabian,

I’m not sure why there isn’t HSV support. I’ve added a to-do item for this.


– Dale


Hi Dale,

fantastic! It’ll be great to have this in a future library.
In case anyone else has this problem NOW, here’s my little python workaround.

def ColorRGBToHSV(colorRGB):
    """ converts RGB color to tuple of values for Hue, Saturation and Value
        by first converting it to HSL and then doing a bit of math.
            colorRGB -- RGB color
            tuple with hue, saturation and value, all [0,1]
    colorHSL = Rhino.Display.ColorHSL(colorRGB)
    H = colorHSL.H
    V = (2*colorHSL.L + colorHSL.S *(1- abs(2*colorHSL.L - 1))) / 2
    S = 2*(V-colorHSL.L)/V
    return (H,S,V)

def ColorHSVToRGB(colorHSV):
    """ converts HSV color tuple to RGB-color 
        by creating HSL-color based on HSV-values and then converting it to ARGB-Color
            tuple with hue, saturation and value, all [0,1]
            RGB color
    H = colorHSV[0]
    L = 0.5 * colorHSV[2] * (2- colorHSV[1])
    S = colorHSV[2] * colorHSV[1] / (1-abs(2*L-1))
    colorHSL = Rhino.Display.ColorHSL(H,S,L)
    return colorHSL.ToArgbColor()