Did you ever take a class where you had to convert from rectangular coordinates (x, y) to circular (r, theta)? That's basically what you're doing with RGB->HSV but it's in three dimensions. I tend to think of RGB as a cube, where the R, G and B coordinates might be (x, y, z) respectively. HSV/HSL as cones or cylinders (I suppose cylinders is easiest for coordinate transformation). Hue is the angle (theta), saturation is the radius and value/luminosity the height.

Then you're just applying transformations to the coordinates, similar to how you do

Code:

r = sqrt(x*x + y*y)
theta = inverse_tan(y / x)
// or in reverse
x = r cos(theta)
y = r sin(theta)

It's the same concept for HSV <-> RGB, but a bit more complicated.