-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCosSineTable.java
35 lines (30 loc) · 1006 Bytes
/
CosSineTable.java
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
public class CosSineTable {
private static int N = 36000;
private static int M = N/360;
private static double[] cos = new double[N+1];
private static double[] sin = new double[N+1];
private static CosSineTable table = new CosSineTable();
private CosSineTable() {
for (int i = 0; i <= N; i++) {
cos[i] = Math.cos(Math.toRadians(1.0*i/M));
sin[i] = Math.sin(Math.toRadians(1.0*i/M));
}
}
public static double getSine(double angle) {
double deg_angle = Math.toDegrees(angle);
while (deg_angle < 0) deg_angle += 360;
while (deg_angle > 360) deg_angle -= 360;
int angleCircle = (int)(deg_angle*M);
return sin[angleCircle];
}
public static double getCos(double angle) {
double deg_angle = Math.toDegrees(angle);
while (deg_angle < 0) deg_angle += 360;
while (deg_angle > 360) deg_angle -= 360;
int angleCircle = (int)(deg_angle*M);
return cos[angleCircle];
}
public static CosSineTable getTable() {
return table;
}
}