简体   繁体   English

通过HSV颜色计算圆点

[英]Calculate Point in circle by HSV color

I have a color circle where the user can choose a color from. 我有一个色环,用户可以从中选择一种颜色。 The color is calculated with this method 用这种方法计算颜色

public int getColorForPoint(int x, int y, float[] hsv) {
        x -= fullCircleRadius;
        y -= fullCircleRadius;
        double centerDist = Math.sqrt(x * x + y * y);

        hsv[0] = (float) (Math.atan2(y, x) / Math.PI * 180f) + 180;
        hsv[1] = Math.max(0f, Math.min(1f, (float) (centerDist / innerCircleRadius)));

        return Color.HSVToColor(hsv);
    }

Now I need the reversed method to calculate the x and y coordinate by a given color (hsv array). 现在,我需要反向方法以给定的颜色(hsv数组)计算x和y坐标。 To be more specific: The user can save a color and the indicator in the color circle should "jump" to the saved color on the circle. 更具体地说:用户可以保存颜色,色环中的指示器应“跳转”到该圆上保存的颜色。 But I'm quite lost with this mathematics. 但是我对这种数学很迷茫。

Looking at the way you calculate centerDist - I can tell your circle centre is at the origin (0,0). 查看您计算centerDist的方式-我可以告诉您圆心在原点(0,0)。

Basically HSV is a polar co ordinate, all you need is to convert a polar co ordinate to cartesian co ordinate. HSV基本上是一个极坐标,您所需要做的就是将一个极坐标转换为笛卡尔坐标。 which is done as follows. 如下进行。

public double[] getHSVtoCartesian(double[] hsv) {

    double [] xy;

     double theta = hsv[0];
     double r = hsv[1];

    xy[0] = r * Math.cos(theta);
    xy[1] = r * Math.sin(theta);

    return xy;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM