I don't see what the issue is. I don't know how the Oblivion scripting works, but Taylor expansions should be extremely accurate, as long as the angle is between 0 and 360 degrees (and if you know that you're going to go over, just keep subtracting 360 from your angle until it does fit).
For the cos x, you should use the same script, except you'd change the line, "set SinResult to X - X2*X/6 + X5/120 - X7/5040 + X9/362880 - X9*X2/39916800 + X9*X4/6227020800 - X8*X7/1.307674368e12" with
set cosResult to -x2 / 2 + x4 / (4*3*2) - (x2*x4) / (6*5*4*3*2) + (x4*x4) / (8*7*6*5*4*3*2) - (x2*x4*x4) / (10*9*8*7*6*5*4*3*2) + (x4*x4*x4) / (12*11*10*9*8*7*6*5*4*3*2)
if that's not accurate enough, keep repeating the pattern. If you can create subroutines, you can easily adapt it as needed. Again, I don't know how Oblivion works, but in Java:
float power (int degree, int base) //Degree is a parameter based on what power you're looking for. Eg. x^2 is degree 2. Base is what you're multiplying, eg. in the phrase 2^x, 2 is the base
{
int xn = base * base;
for ( int i = 2; i > degree; i++) //This is a loop which starts at 2 and will increment by one until it hits degree
{
xn = base*xn;
}
return xn; //after the loop finishes, the service "power" will return xn ("x^n")
}
// you would need to specify which objects can use this. For example, if you have a class named Math, you would call "power" using Math.power(aDegree, aBase); Of course, Java already supports this...
float factorial (int numberToFactor) //numberToFactor is the number to be factored
{
int nFactorial = 1;
if ( nFactorial == 0 || nFactorial == 1) //0! is defined as equal to 1. 1! is 1 and is added here for convenience
{
return nFactorial;
}
else if nFactorial < 0; //Factorials are only defined for integers greater than or equal to 0. 0 and 1 included above
System.out.println ( "I can't let you do that, Dave" );
return nFactorial; //This will give you your number back so you don't break anything. You could set it as an error or return 0 or something else.
//Yes, the way I've set it up so far, you could combine the first and second conditions. I've left it like this so you can adjust it as needed. Plus, I like the quote
else
{
for ( int i = 2; i <= numberToFactor; i++) //This loop will increment from 2 to numberToFactor
{
nFactorial *= i; // *= is equivalent to nFactorial = nFactorial * i;
}
return nFactorial;
}
end if
}[/code]
Then, you could just define your functions to give you cos and sin:
[code]float cos(int aPower, int yourBase, int yourAngle) //These should be predefined or defined when called
{
int cumulativeCosX = 0;
for (i = 0; i < aPower; i++) //Loop increments from 0 to aPower - 1
{
int termCosX = this.power(2*i, -1)*this.power(i, yourBase) / this.factor(i);
cumulativeCosX += termCosX;
}
return cumulativeCosX;
}
float sin(int aPower, int yourBase, int yourAngle) //These should be predefined or defined when called
{
int cumulativeSinX = 0;
for (i = 0; i < aPower; i++) //Loop increments from 0 to aPower - 1
{
int termSinX = this.power(2*i+1, -1)*this.power(i, yourBase) / this.factor(i);
cumulativeSinX += termSinX;
}
return cumulativeSinX;
}
This gives you four widely used math functions. Unfortunately, from the little I've learned about Oblivion scripts, I don't know if it's possible to use these code snippets