android Dividing circle into N equal parts and know the coordinates of each dividing point

后端 未结 2 1582
温柔的废话
温柔的废话 2020-12-31 02:56

I have requirement that a circle should be divided into N equal parts based on number(2,3...n. But I want the coordinates of dividing points.

I have a circle whose <

2条回答
  •  忘掉有多难
    2020-12-31 03:12

    I have already accepted answer... the formula works perfectly. Here is the solution coded in Java. It will help other developers.

        private int x[];  // Class variable
        private int y[];  // Class variable
    
        private void getPoints(int x0,int y0,int r,int noOfDividingPoints)
        {
    
            double angle = 0;
    
            x = new int[noOfDividingPoints];
            y = new int[noOfDividingPoints];
    
            for(int i = 0 ; i < noOfDividingPoints  ;i++)
            {
                angle = i * (360/noOfDividingPoints);
    
                x[i] = (int) (x0 + r * Math.cos(Math.toRadians(angle)));
                y[i] = (int) (y0 + r * Math.sin(Math.toRadians(angle)));
    
            }
    
            for(int i = 0 ; i < noOfDividingPoints  ;i++)
            {
                Log.v("x",""+i+": "+x[i]);
                Log.v("y",""+i+": "+y[i]);
    
            }
        }
    

    Where x0 and y0 are co ordinates of circle's centre.and r is radius.

    In my case:

    Input x0 = 0 , y0 = 0 and r = 150 , noOfDividingPoints = 5

    output

    point1: (150,0)

    point2: (46,142)

    point3: (-121,88)

    point4: (-121,-88)

    point5: (46,-142)

提交回复
热议问题