Fixed the Sin, Cos and Tan functions so they actually work outside the realm of -90 | +90.

Later I will add the realm outside -90 and +360.
This commit is contained in:
HKS_cp 2011-08-19 18:19:25 +00:00
parent fc6cb9b4ea
commit 6bd7f593dc

View file

@ -262,11 +262,23 @@ namespace Cosmos.System.Plugs.System
#region Sin
public static double Sin(double a)
{
bool signSwitch = false;
double result = 0;
//TO radians
double radians = a * (Math.PI / 180);
if (radians > Math.PI)
{
radians = radians - Math.PI;
signSwitch = true;
}
else if (radians > Math.PI / 2)
{
radians = radians - Math.PI;
signSwitch = true;
}
//Temp function to increase precision make more factorial calculations
result = (radians) - (Math.Pow(radians, 3) / Factorial(3));
result += (Math.Pow(radians, 5) / Factorial(5)) - (Math.Pow(radians, 7) / Factorial(7)) + (Math.Pow(radians, 9) / Factorial(9));
@ -284,36 +296,17 @@ namespace Cosmos.System.Plugs.System
sign++;
}*/
return result;
if (signSwitch)
return result * -1;
else
return result;
}
#endregion
#region Cos
public static double Cos(double a)
{
double result = 0;
//TO radians
double radians = a * (Math.PI / 180);
result = 1 - (Math.Pow(radians, 2) / Factorial(2));
result += (Math.Pow(radians, 4) / Factorial(4)) - (Math.Pow(radians, 6) / Factorial(6)) + (Math.Pow(radians, 8) / Factorial(8));
//HARD FIX! Delete when doubles are working!
result *= -1;
/* USE WHEN Modulus Works
int sign = 0;
for (int i = 2; i < 20; i += 2)
{
if (sign % 2 == 0)
result += -Math.Pow(radians, i) / Factorial(i);
else
result += Math.Pow(radians, i) / Factorial(i);
sign++;
}*/
return result;
return Sin(90 - a);
}
#endregion