Hi Felipe,
Filipe Nepomuceno wrote:
> very expensive solution though (if it works) because of the trig
> function calls
You can always just precompute the trig values into an array or use a
polynomial approximation. You just need to clamp the angle to the right
range in an accessor function in which you determine the right array
index to request.
get_cos(angle) {
clamp(&angle); // clamping to 0 to 2*PI range
index = (int)((angle/(2*PI))*array_size);
return cos_array[index];
}
This is much much faster than using the C trig functions. You can reduce
precomputations by storing only 0 to PI/2, but then the clamping logic
is messier.
-Bartek
--
To unsubscribe send a mail to [email protected]