You can approximate sin very well between -PI/2 and PI/2 with the function f(theta) = theta - theta
3/6 + theta
5/120.
Once you've got that approximation, you can basically compute any sin value by using the periodic properties of sin.
sin(x) = sin(PI - x) between PI/2 and 3PI/2 (this recursively uses the bit we can accurately approximate)
sin(x) = sin(x - 2PI) between 3PI/2 and 2PI.
Here's the code for sin:
Code:
#define PI 3.14159
float ApproxSin(float theta)
{
while(theta > (3*PI)/2)
{
theta -= 2*PI;
}
while(theta < -PI/2)
{
theta += 2*PI;
}
// theta is now between -PI/2 and 3*PI/2
if(theta > -PI/2 && theta <= PI/2) // basic approximation
{
return theta - theta*theta*theta/6 + theta*theta*theta*theta*theta/120;
}
else if(theta > PI/2 && theta < 3*PI/2)
{
return ApproxSin(PI - theta);
}
}
An approximation for cos is f(x) = 1 - x
2/2 + x
4/24, you can do the same thing with it, more or less.