Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 centre(x,y) and radius(150) are known.

Question:

Is there any formula which gives me the coordinates of dividing points as shown in figure. Can anyone please tell me the formula. I want to implement it in Java.

Circle image for refrence:

image

like image 523
TheFlash Avatar asked Sep 04 '13 09:09

TheFlash


People also ask

How do you divide a circle into 13 equal parts?

For dividing a circle into 13 equal parts (construction method is valid for dividing a circle in any equal parts) draw two perpendicular diameters. Vertical diameter is divided into many parts we wish to divide the circle, in this case in 13 parts.


1 Answers

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)

like image 89
TheFlash Avatar answered Sep 22 '22 17:09

TheFlash