hsv2rgb function wanted
with radians not degrees. in c. and brief.
Posted by: An anonymous kitty (some_kitten)
Posted at: October 17th, 2006 03:06 pm (UTC)

Don't think I can write one for you off the top of my head, but I'm very curious as to why.
Too much of my professional life lately has involved video encoding and different color schema. :P
Posted by: the coproduct of doom (oonh)
Posted at: October 17th, 2006 08:31 pm (UTC)

Look at the movies in my recent lj entries. I've decided it's time to add color to them. They consist of long linear sequences of points dribbled onto an array much as one would dribble syrup on pancakes. The color information will come from the angle at a point  last point/this point/next point > angle, then all angles in a slice of the object normal to the viewer added mod pi (I think group theoretically is more interesting than just averaging them).
Posted by: Matt McIrvin (mmcirvin)
Posted at: October 17th, 2006 04:47 pm (UTC)

Looking at the Wikipedia article, since the definition of HSV is this weird piecewise thing, I'm not sure you're going to get brief; the function will have to involve conditionals. But you can convert a function expressed in degrees to one expressed in radians by just multiplying the H value by 180/pi at the outset.
Posted by: Matt McIrvin (mmcirvin)
Posted at: October 17th, 2006 10:54 pm (UTC)

Reading your previous comment on intended purpose: If all you want is a way to convert something like HSV to RGB so you can represent hue as an angle, instead of representing the standard hexcone precisely, that's much easier.
Something like this (which I just pulled out of my buttoptimize and debug to taste) might do:
R = cos (0.75*theta);
if (R < 0.0) R = 0.0;
G = cos (0.75*(theta  2 * PI/3));
if (G < 0.0) G = 0.0;
B = cos (0.75*(theta + 2 * PI/3));
if (B < 0.0) B = 0.0;
(The idea here is to arrange all the constants so that each cosine function reaches zero exactly at the maximum of the next one, and they're evenly spaced in thirds around the unit circle; then clamp all the negative values to zero. If my math is wrong, i apologize in advance.)
Since you've already got brightness information, you'd then use all those as factors that you multiply by the brightness.
Posted by: Matt McIrvin (mmcirvin)
Posted at: October 17th, 2006 10:57 pm (UTC)

...and by the way, if you then replace those trig functions with linear triangular ones that reach zero precisely at the maximum of the next function, then you've got something more like standard HSV. But the trigonometric version is easier to write down.
Posted by: the coproduct of doom (oonh)
Posted at: October 23rd, 2006 01:27 am (UTC)

Okay, the state so far:
the test program is wonky
(this one uses your algorithm)
the real program remains incomplete.
Care to share with me, if you get one?