def hsv_to_rgb(h, s, v):
    """
    Convert a color specified by a point in HSV color space to the
    corresponding point in RGB color space.

    Parameters:
       h - Hue value in [0,360] (ie degrees), may be None (when s is 0)
       s - Saturation value in [0,1]
       v - Value value in [0,1]

    Retrun value:
       (r, g, b) tuple corresponding to the h,s,v supplied.
       Each of r,g,b is in [0,1]

    Raises exceptions:
       ValueError if s is 0 but h is not None

    This is an implementation of the procedure given in
    Foley and van Dam (1982) "Fundamentals of Interative Computer Graphics"
    (Addison-Wesley) p. 616.
    See also the wikipedia "HSL Color Space" entry (which cites the above book).
    """
    assert(0.0 <= h <= 360.0)
    assert(0.0 <= s <= 1.0)
    assert(0.0 <= v <= 1.0)
    
    if s == 0:
        if h == None:
            r = v
            g = v
            b = v
        else:
            raise ValueError('hsv_to_rgb: if S is 0 then H is undefined')
    else:
        if h == 360:
            h = 0
        h = h / 60.0
        i = int(h)
        f = h - i
        p = v * (1.0 - s)
        q = v * (1.0 - s*f)
        t = v * (1.0 - s*(1.0 - f))
        if i == 0:
            (r, g, b) = (v, t, p)
        elif i == 1:
            (r, g, b) = (q, v, p)
        elif i == 2:
            (r, g, b) = (p, v, t)
        elif i == 3:
            (r, g, b) = (p, q, v)
        elif i == 4:
            (r, g, b) = (t, p, v)
        elif i == 5:
            (r, g, b) = (v, p, q)
        else:
            assert(False)
    return (r, g, b)