Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Float2 SinCos(Float angle)
- {
- // Map Value to y in [-pi,pi], x = 2*pi*quotient + remainder.
- Float quotient = InvPiX2 * angle;
- if(angle >= 0.0f) { quotient = (float)((int)(quotient + 0.5f)); } else { quotient = (float)((int)(quotient - 0.5f)); }
- Float y = angle - PiX2 * quotient;
- // Map y to [-pi/2,pi/2] with sin(y) = sin(Value).
- Float sign;
- if(y > PiDiv2)
- {
- y = Pi - y;
- sign = -1.0f;
- }
- else if(y < -PiDiv2)
- {
- y = -Pi - y;
- sign = -1.0f;
- }
- else
- {
- sign = +1.0f;
- }
- float y2 = y * y;
- // Sin gets an 11-degree minimax approximation
- // Cosine gets a 10-degree minimax approximation
- Float2 result;
- result.x = (((((-2.3889859e-08f * y2 + 2.7525562e-06f) * y2 - 0.00019840874f) * y2 + 0.0083333310f) * y2 - 0.16666667f) * y2 + 1.0f) * y;
- result.y = (((((-2.6051615e-07f * y2 + 2.4760495e-05f) * y2 - 0.0013888378f) * y2 + 0.041666638f) * y2 - 0.5f) * y2 + 1.0f) * sign;
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement