Thread: Calculating inverse tangent

  1. #1

    Calculating 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.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    http://mathworld.wolfram.com/InverseTangent.html
    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;
    }
    For values >2pi or <-2pi you have to do some more calculations.

    BTW: That link was the first link on a google search of inverse tangent

  3. #3
    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.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    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
    Last edited by Thantos; 02-24-2004 at 07:07 PM.

  5. #5
    I'm using the Microchip PIC18F8520

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681

  7. #7
    Registered User
    Join Date
    May 2003
    Posts
    195
    Umm can't u use sequences and series (taylor maclaren) from calculus to find inverse tan

  8. #8
    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.

  9. #9
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Once you get done I'd be interested in the code. BTW I wasn't trying to be an ass, it just comes naturally.

  10. #10
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,138
    Originally posted by KneeGrow
    Umm can't u use sequences and series (taylor maclaren) from calculus to find inverse tan
    Exactly my idea.

    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...

  11. #11
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Of course if you wanted speed over size you could just do a table lookup

  12. #12
    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.

  13. #13
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Use binary search in conjunction with a lookup table and it'll be fairly quick. Its all a matter of space vs speed

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to inverse a trig?
    By Diablo02 in forum C# Programming
    Replies: 4
    Last Post: 11-07-2007, 10:11 PM
  2. Calculating : high numbers
    By MiraX33 in forum C++ Programming
    Replies: 9
    Last Post: 06-08-2006, 11:08 PM
  3. calculating sin, cos, and tangent function
    By rcastel2 in forum C++ Programming
    Replies: 12
    Last Post: 02-23-2006, 01:32 PM
  4. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  5. Inverse Tangent
    By Quantrizi in forum C++ Programming
    Replies: 31
    Last Post: 05-09-2004, 04:56 PM