I am trying to divide the circle into n equal parts using straight lines. Idea is to get the coordinates of the end points on the circumference of the circle and then to draw the line.
to find coodrinates I am using following code:
static void getPoints(int x0,int y0,int r)
{
double angle = 0;
double angleToRadian = 0;
for(int i = 0 ; i < noOfDividingPoints ;i++)
{
angle = i * (360/noOfDividingPoints);
angleToRadian = ( angle * 3.141 ) / 180;
APP_LOG(APP_LOG_LEVEL_DEBUG, "LOG: Angle: %lf, AngleToRadian: %lf", angle, angleToRadian );
x[i] = (int) (x0 + r * cos_lookup(angleToRadian));
y[i] = (int) (y0 + r * sin_lookup(angleToRadian));
APP_LOG(APP_LOG_LEVEL_DEBUG, "LOG: i: %d, x[i]: %d, y[i]: %d", i, (int)x[i], (int)y[i] );
}
}
Using this getPoints method I am filling the array x[] and y[] and then iterate over these arrays to draw lines between x[i] and y[i]
However, the values calculated from the above code comes out to be weird, below are the logs printing the contents of x[] and y[]
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:57] WatchFace.c:45> LOG: i: 0, x[i]: 4587522, y[i]: 84
[14:18:57] WatchFace.c:36> LOG: Angle: 90
[14:18:57] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 1, x[i]: 4587522, y[i]: 84
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 2, x[i]: 4587452, y[i]: 504
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 3, x[i]: 4587452, y[i]: 924
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 4, x[i]: 4587452, y[i]: 1344
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 5, x[i]: 4587452, y[i]: 1344
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 6, x[i]: 4587452, y[i]: 1834
[14:18:58] WatchFace.c:36> LOG: Angle: 90
[14:18:58] WatchFace.c:41> LOG: Angle: f, AngleToRadian: f
[14:18:58] WatchFace.c:45> LOG: i: 7, x[i]: 4587452, y[i]: 2254
Please point out what I am missing here.
Thanks.