tags:

views:

177

answers:

2

Once more something relatively simple, but confused as to what they want.

the method to find distance on cartesian coordinate system is distance=sqrt[(x2-x1)^2 + (y2-y1)^2]

but how do i apply it here?

    //Requires: testColor to be a valid Color
    //Effects: returns the "distance" between the current Pixel's color and  
    //         the passed color
    //         uses the standard method to calculate "distance"
    //         uses the same formula as finding distance on a
    //         Cartesian coordinate system
    double colorDistance(Color testColor) const;

The color class has defined colors: int red,green,blue

Do i define something like 'oldGreen' 'oldRed' 'oldBlue' and get the distance that way? The passed color being red,green,blue ?

http://pastebin.com/v9K30dc7

+4  A: 

I'm guessing they want you to use:

distance = sqrt[(r2-r1)^2 + (g2-g1)^2 + (b2-b1)^2]
Michael Mrozek
Where r, g, and b stand for red green and blue :)
Billy ONeal
Agreed - check out http://en.wikipedia.org/wiki/Euclidean_distance for the more general definition
James Kolpack
+2  A: 

break the color into it's red green and blue components, and use the same method, ie sqrt(sqr(delta red)+sqr(delta blue)+sqr(delta green))

note, this is not a really great method, as it doesn't allow for gamma or even the more complicated case of human perception. read http://en.wikipedia.org/wiki/Color_difference for more exotic methods.

steelbytes
good to know. in this case, they have us pretty limited, only using red,green,blue
codefail
That's not a fundamental problem: you can convert RGB to CIELAB, and then calculate the distance using the distance formula on Wikipedia. The RGB to CIELAB conversion is also on Wikipedia.
MSalters