Trig lookup table
Posted on 2006-04-08
I've created a class which uses a lookup table to improve the speed that I can find the cos, sin and tan, of any angle.
What my program does, is it creates a float array, which stores the cos of each angle from 0 up to 90.
Then, when my program is given an angle, it casts it to an int, and can then use the information within this 91 element array to find the cosine of that angle.
Then, for calculating the sin and tan of an angle, I make use of the following identities, in order to use the cos lookup table to find them:
sin a = cos (90 - a)
tan a = sin a / cos a
This all works very very nicely; I get a result which is certainly accurate enough for what I'm doing at least, and it returns the value at least 3 times faster than the native methods can calculate them. So, it's all good.
Now however, I wish to do the same sort of thing, but for the inverse functions — acos, asin, and atan.
But, I haven't a clue how I'd do this... I'm happy to create another one or two lookup tables if necessary for this...
<Points will go up to 500 if this can be done...>