View Single Post
  #2   Spotlight this post!  
Unread 17-02-2007, 20:28
gnirts gnirts is offline
Suspicious pointer conversion
AKA: Robinson Levin
FRC #1648 (The Gearbox Gangstaz)
Team Role: Programmer
 
Join Date: Jan 2006
Rookie Year: 2005
Location: ATL
Posts: 116
gnirts will become famous soon enough
Re: Trig Lookup Table

Quote:
Originally Posted by michniewski View Post
Code:
l_upper_squared = arm.length_upper^2;
l_lower_squared = arm.length_lower^2;

[...]

temp_R_squared = (arm.height^2) + (temp_o_d^2);
The ^ operator is bitwise XOR, there is no power operator in C. You need to use the pow() function or one of its brothers or just square it manually (which would be better if they are fixed point):
Code:
#include <math.h>
double pow(double x, double y);
long double powl(long double x, long double y);
float powf(float x, float y);
Example of new code:
Code:
temp_R_squared = pow(arm.height,2) + pow(temp_o_d,2);
temp_R_squared = arm.height*arm.height + temp_o_d*temp_o_d;
Be sure you type-cast correctly.

Quote:
I've tried to keep all the trig functions the same (so they're all arccos, or inverse cosine).
This is a good way to keep it fast if you go with the lookup table solution.
Quote:
The arccos in the code should be (and now is) acos, right?
Yes, if you are using <math.h>. But I thought you were going to use a lookup table for inverse cosine, no? In which case you would have to name it to not conflict with the definition in <math.h> which you will need for sqrt(), eg. acos_lookup().

Also, if arm.length_upper, arm.length_lower, arm.offset_front, arm.distance are all constant consider doing the math on them ahead of time. And if all of these are floating point variables (which they need to be if you put them into functions like sqrt() and acos() then you are probably not going to get done quick enough. Consider making a lookup table for the whole operation (if possible) or just casting to floats for the <math.h> calls.

Good luck,
Robinson

Last edited by gnirts : 17-02-2007 at 20:53. Reason: to put this message here...