tan inverse

This is a discussion on tan inverse within the C Programming forums, part of the General Programming Boards category; I have an adjacent and opposite. I think I can use: tan(x) = opposite / adjacent but how do I ...

  1. #1
    Registered User
    Join Date
    Aug 2013
    Posts
    1

    tan inverse

    I have an adjacent and opposite. I think I can use: tan(x) = opposite / adjacent but how do I get the tangent inverse? Please help! <<snipped email>>

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, dwelliott!

    We don't email replies, however. The forum policy is YOU need to post up your attempt at a program code, and THEN we will attempt to answer your specific questions about the problem.

    Right here.

    I suspect if you Google for "inverse of a tangent", you'll have your answer in short order.

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,012
    The easiest way, I suppose, is to expand the inverse tangent function into a series.

    Just using wolfram alpha, you can re-write atan(x) into x - (x^3)/3 + (x^5)/5 - (x^7)/7 + ...

    So what you wanna do is, take your opposite over adjacent value and then plug it into that formula I just posted. The more terms the more accurate it is. Also, write an exponent routine because Idt C has one built into it. I think this gives you the answer in radians as well.

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    The inverse tangent is directly computed by atan() in math.h.

    Asking for the inverse tangent of x just means that you want a measure (in radians, in C) whose tangent is x. Arc tangent is just another name for this.

    https://www.khanacademy.org/math/tri...ctions--arctan

  5. #5
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,012
    Hmm... I'm pretty sure math.h's routine would use the expansion, wouldn't it? You easily decide the number of terms to keep based on data type, couldn't you?

    Otherwise, don't you have to have a look-up table of values?

  6. #6
    Registered User
    Join Date
    Oct 2011
    Posts
    826
    C99 and POSIX.1-2001 and later provide atan2(y,x), which yields the angle between the positive axis and (x,y), including the quadrant. If x>0, atan2(y,x) = atan(y/x).

    Many architectures do have an arctangent function built-in. Using the polynomial is quite rare; something like CORDIC atan2() is very simple and quite efficient, especially if you need to use software emulation for the result type. (If you need the full precision of the result type, you need extended precision for the temporaries, or some other way to correct the least significant bit(s) of the result.)

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    6,211
    Quote Originally Posted by Nominal Animal View Post
    C99 and POSIX.1-2001 and later provide atan2(y,x)
    It was specified in C before 1999. It was in C89 and, although I would hesitate to describe something as standard before there was actually a standard, atan2() also existed for a considerable time in the pre-standard C library.
    Right 98% of the time, and don't care about the other 3%.

  8. #8
    Registered User
    Join Date
    Oct 2011
    Posts
    826
    Quote Originally Posted by grumpy View Post
    It was in C89
    Good catch. Even the man page I linked to mentions that (for atan2(), for double argument and result); I should have checked and not relied on my memory!

    Quote Originally Posted by grumpy View Post
    also existed for a considerable time in the pre-standard C library.
    Right. They are also available on some very limited architectures, like GCC with emulated floating-point on ARM, where there is very little available RAM or ROM. The CORDIC implementations of sin, cos, atan and atan2 are simple enough and only need a table of about 64 values for full double support. As only substraction, addition, and bit shifts are needed, it's very easy to implement even for software-emulated numeric types.

    CORDIC itself is OLD; the first academic paper is from 1959 (Jack E. Volder, "The CORDIC Trigonometric Computing Technique," IRE Transactions on Electronic Computers, Vol. EC-8, pp.330-334, 1959.

  9. #9
    Registered User
    Join Date
    May 2013
    Posts
    66
    Quote Originally Posted by dwelliott View Post
    I have an adjacent and opposite. I think I can use: tan(x) = opposite / adjacent but how do I get the tangent inverse? Please help! <<snipped email>>
    one nice feature about programing in Linux is the use of man pages. If you are not programming in Linux, then hit up google and do a search for "man math.h" you will find your answer there.

    I add this for the simple reason that you can perform this task on many features in C then when you have done so and have some code, post the code here for further detailed help.

    There are some great folks in these forums that are very skilled at programming.

  10. #10
    Registered User
    Join Date
    Oct 2011
    Posts
    826
    No need to search; the Linux man-pages project lives at kernel org. There is even a nice list of all library function man pages. Even if the man pages are Linux-oriented, they do mention which standards define the functions, and whether the functions are part of C89 or C99, in the Conforming to section in each man page.

  11. #11
    Registered User
    Join Date
    May 2013
    Posts
    66
    Quote Originally Posted by Nominal Animal View Post
    No need to search; the Linux man-pages project lives at kernel org. There is even a nice list of all library function man pages. Even if the man pages are Linux-oriented, they do mention which standards define the functions, and whether the functions are part of C89 or C99, in the Conforming to section in each man page.
    yup, but that still requires a search to learn. im so new to C that i live by my man pages and getting help from here and other places.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. inverse Sin Cos Tan
    By headshot119 in forum C++ Programming
    Replies: 2
    Last Post: 09-21-2009, 12:50 PM
  2. Help with inverse...
    By Ervilha in forum C Programming
    Replies: 14
    Last Post: 10-29-2008, 08:08 PM
  3. Inverse
    By bumfluff in forum C++ Programming
    Replies: 2
    Last Post: 05-14-2006, 06:42 AM
  4. Inverse Tan
    By spidereen in forum C++ Programming
    Replies: 2
    Last Post: 03-04-2003, 07:55 AM
  5. ack, need help with inverse sin
    By Valerie in forum C++ Programming
    Replies: 4
    Last Post: 10-06-2002, 08:25 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21