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).
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.
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 butt--optimize 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.
...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.
Comments 8
Reply
Too much of my professional life lately has involved video encoding and different color schema. :-P
Reply
Reply
Reply
Reply
Something like this (which I just pulled out of my butt--optimize 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.
Reply
Reply
Leave a comment