-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsector_to_rads.c
52 lines (39 loc) · 1.1 KB
/
sector_to_rads.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdio.h>
#include <math.h>
double arc_length(double pitch, double theta)
{
double x = sqrt(1.0 + (theta * theta));
return (0.5 * pitch * ((theta * x) + log(theta + x)));
}
double search_theta(double pitch, double length)
{
int min = 0;
int max = 1 << 18;
double middle;
double guess;
while(min < (max - 1))
{
middle = (max + min) / 2.0;
guess = arc_length(pitch, middle);
if(guess < length)
min = middle;
else
max = middle;
}
return middle;
}
int main(int argc, char *argv[])
{
int sector_number = strtol(argv[1], NULL, 16);
double correct_arc = 17.33 * sector_number;
double radians, rotations;
double pitch = 1.5 / 1000.0;
double search_length;
pitch = pitch / (2.0 * M_PI);
double null_length = arc_length(pitch, 25.0 / pitch);
printf("whole length: %lf\n", arc_length(pitch, 58.0 / pitch) / 1000.0);
search_length = search_theta(pitch, correct_arc + null_length);
printf("theta: %lf (%x), r: %lf\n",
search_length, (int)(search_length / (2.0 * M_PI)),
search_length * pitch);
}