I need to compute inverse tangents, and I can't find any information on the net on how to do this. I am using C.

Printable View

- 02-24-2004bludstayneCalculating inverse tangent
I need to compute inverse tangents, and I can't find any information on the net on how to do this. I am using C.

- 02-24-2004Thantos
http://mathworld.wolfram.com/InverseTangent.html

Quote:

In the GNU C library, it is implemented as atan(double x).

Code:`#include <stdio.h>`

#include <math.h>

int main(void)

{

double x, y;

x = 1.0;

y = tan(x);

printf ("Remember this is in Radians\n%f\n%f\n", x, y);

printf ("%f\n", atan(y) );

return 0;

}

BTW: That link was the**first**link on a google search of inverse tangent - 02-24-2004bludstayne
No, I can't use the standard library, I have to code my own. My robot controller doesn't have any math functions in it's standard library.

- 02-24-2004Thantos
Might want to specify something like that next time. Which robot type? GCC is able to port out a lot of code to other platforms includeing some embedded ones.

Just spoke with my instructor. He has done quite a bit of embedded programming and does a robot course here at the college. What I got from him is that once GCC gets done making the executable it is self contained as far as the code. So as long as the processor can proform the basic operations and you set the correct flags for the platform it should run.

Behold the power that is GCC - 02-25-2004bludstayne
I'm using the Microchip PIC18F8520

- 02-25-2004Thantos
Download http://www.microchip.com/download/li...ecs/39583b.pdf and read page 304

- 02-25-2004KneeGrow
Umm can't u use sequences and series (taylor maclaren) from calculus to find inverse tan

- 02-26-2004bludstayne
We got it working at about 1:00 AM last night. All I have left to code is the rotation code and I'll have autonomous going for our robot.

- 02-26-2004Thantos
Once you get done I'd be interested in the code. BTW I wasn't trying to be an ass, it just comes naturally.

- 02-27-2004golfinguy4Quote:

*Originally posted by KneeGrow*

**Umm can't u use sequences and series (taylor maclaren) from calculus to find inverse tan**

Add up all of the following for an approximation. The more terms you use, the more accurate your result.

x-x^3/3+x^5/5-x^7/7... - 02-27-2004Thantos
Of course if you wanted speed over size you could just do a table lookup :)

- 02-27-2004bludstayne
If we did a table lookup we would have over 2000 values in it. That is what our original plan was until we realized that.

- 02-27-2004Thantos
Use binary search in conjunction with a lookup table and it'll be fairly quick. Its all a matter of space vs speed :)