Some basic math??

Discussion in 'Mac Programming' started by mdeh, Feb 10, 2010.

  1. mdeh macrumors 6502

    Joined:
    Jan 3, 2009
    #1
    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.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    As far as I can tell, yes.
     
  3. Sander macrumors 6502

    Joined:
    Apr 24, 2008
    #3
    Yes.
     
  4. mdeh thread starter macrumors 6502

    Joined:
    Jan 3, 2009
    #4
    Good...thanks.
     
  5. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #5
    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
     
  6. jared_kipe macrumors 68030

    jared_kipe

    Joined:
    Dec 8, 2003
    Location:
    Seattle
    #6
    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
     

Share This Page