找到两个像素颜色之间的"距离"

cod*_*ail 4 c++

再一次相对简单的事情,但他们想要什么困惑.

在笛卡尔坐标系上求距离的方法是距离= sqrt [(x2-x1)^ 2 +(y2-y1)^ 2]

但我怎么在这里申请?

    //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;
Run Code Online (Sandbox Code Playgroud)

颜色类定义了颜色:int红色,绿色,蓝色

我是否定义了类似'oldGreen''oldRed''oldblue'的东西,并获得那种距离?通过的颜色是红色,绿色,蓝色?

http://pastebin.com/v9K30dc7

Mic*_*zek 6

我猜他们想要你用:

distance = sqrt[(r2-r1)^2 + (g2-g1)^2 + (b2-b1)^2]
Run Code Online (Sandbox Code Playgroud)