
public static final float PI = 3.1415927f;
public static final float TWO_PI = PI * 2;
public static final float HALF_PI = PI / 2;
public static final float ONE_AND_HALF_PI = PI + HALF_PI;
public static final double DTWO_PI = Math.PI * 2;

private static final int SIN_BITS = 14;
private static final int SIN_MASK = ~(-1 << SIN_BITS);
private static final int SIN_COUNT = SIN_MASK + 1;
private static final float[] SIN_TABLE = new float[SIN_COUNT];

private static final float radFull = TWO_PI;
private static final float degFull = 360;
private static final float radToIndex = SIN_COUNT / radFull;
private static final float degToIndex = SIN_COUNT / degFull;

public static final float RAD_TO_DEG = 180 / PI;
public static final double DRAD_TO_DEG = 180 / Math.PI;
public static final float DEG_TO_RAD = PI / 180;
public static final double DDEG_TO_RAD = Math.PI / 180;

static {
for(int i = 0; i < SIN_COUNT; i++) {
SIN_TABLE[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull);
}

for(int i = 0; i < 360; i += 90) {
SIN_TABLE[(int) (i * degToIndex) & SIN_MASK] = (float) Math.sin(i * DEG_TO_RAD);
}
}

/**
* Gets the sine of an angle.
* @param radians Measure of the angle.
* @return The sine of the angle.
*/
public static float sin(float radians) {
return SIN_TABLE[(int) (radians * radToIndex) & SIN_MASK];
}

/**
* Gets the cosine of an angle.
* @param radians Measure of the angle.
* @return The cosine of the angle.
*/
public static float cos(float radians) {
return SIN_TABLE[(int) ((radians + PI / 2) * radToIndex) & SIN_MASK];
}