Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdeh

macrumors 6502
Original poster
Jan 3, 2009
345
2
Hi to all the math whizzes :)

In one of Hillegass's methods ( p 333) he takes 2 rgb colors ( in the same ColorSpace) and tries to find a closest match. ( Well...what is really happening, is that one of the colors is passed into the method as an argument, converted to the correct colorSpace, and the other color is from an "Apple" NSColorList). Each color is "decomposed" into it's basic components, with one set of colors represented as "r","g","b", and the other color as "red", "green", "blue" in the code below.

The line of code that has me a little curious is this.( not what "pow" means, but why the construct a = x(squared) + y(squared) + z(squared) is used)

Code:
float dist = pow(red-r,2) + pow(green -g,2) + pow( blue -b, 2)


Is this just an extension of the simple "square on the hypotenuse" but applied in 3 axes?

Anyway, thanks for taking a look.
 
I'm not mathematician (or geomotrist), but I think you'd need to take the square root of that to get an actual distance, unless it's cool that the scale is the square of the distance.

-Lee
 
Is this just an extension of the simple "square on the hypotenuse" but applied in 3 axes?

Anyway, thanks for taking a look.

Yes, there is distance in 3d space. There is even effective distance in 3d space+1d time as well. (spacetime interval)

You do NOT have to take the square root if you are simply comparing/minimizing distance. With one caveat: distancesSquared less than one are smaller than the distance. But still comparing distance squared will put it in order.

x^2 > x for x>1 AND x<0
x^2 < x for x<1
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.