let factorialize = function (num) {
if (num === 0 || num === 1)
return 1;
for (let i = num - 1; i >= 1; i--) {
num *= i;
}
return num;
}
let FACT_2 = 1 / factorialize(2);
let FACT_3 = 1 / factorialize(3);
let FACT_4 = 1 / factorialize(4);
let FACT_5 = 1 / factorialize(5);
let FACT_6 = 1 / factorialize(6);
let FACT_7 = 1 / factorialize(7);
const HALF_PI = Math.PI * 0.5;
const DOUBLE_PI = Math.PI * 2;
var mysin = function (angle)
{
let pow2 = angle * angle;
let pow4 = pow2 * pow2;
let pow6 = pow4 * pow2;
return 1 - pow2 * FACT_2 + pow4 * FACT_4 - pow6 * FACT_6;
}
var mycos = function (angle)
{
return mysin(angle + HALF_PI);
}
var fastSin = function (x)
{
if (x < -Math.PI)
x += DOUBLE_PI;
else if (x > Math.PI)
x -= DOUBLE_PI;
if (x < 0)
return 1.27323954 * x + 0.405284735 * x * x;
else
return 1.27323954 * x - 0.405284735 * x * x;
}
var fastCos = function (x)
{
return fastSin(x + HALF_PI);
}