This is good stuff! Excellent suggestions!
Quote:
|
Originally Posted by Bongle
I always forget about lookup tables
I'm not sure how much code space the VEX controller has, but 360 floats in a table is 1440 bytes, which is quite a bit. Another idea in that vein would be to have a smaller table (45 entries) and just interpolate between them.
Code:
float GetSin(int degrees)
{
int subDegrees = degrees & 7; // gets the last 3 bits
int tableIndex = degrees / 8; // finds out the table entry we want
return ((8-subDegrees)*table[tableIndex] + subDegrees*table[tableIndex+1])/8;
}
This function is a very simple linear interpolation. But it would allow you to have a much smaller table taking up much less memory. Another improvement would be to only have a table for between -PI/2 and PI/2, then using the same techniques I posted in my first post to get answers for PI/2 and beyond. This would again cut table size in half.
|