Created
July 20, 2018 20:13
-
-
Save micycle1/4a63ab9449f087557164986cf6727259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static double[] table = null; | |
static double step; | |
static double invStep; | |
static int size = 0; | |
static | |
{ | |
size = 10000; | |
table = new double[size]; | |
step = 2d * Math.PI / size; | |
invStep = 1.0f / step; | |
for (int i = 0; i < size; ++i) | |
{ | |
table[i] = Math.sin(step * i); | |
} | |
} | |
/** Find a linear interpolation from the table | |
* | |
* @param ang | |
* angle in radians | |
* @return sin of angle a | |
*/ | |
private final static double pi2 = PI * 2; | |
final public static double sin(double ang) | |
{ | |
double t = ang % pi2; | |
int indexA = (int) (t / step); | |
int indexB = indexA + 1; | |
if (indexB >= size) return table[indexA]; | |
double a = table[indexA]; | |
return a + (table[indexB] - a) * (t - (indexA * step)) * invStep; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment