Results 1 to 6 of 6

Thread: Inverse Tan in C++

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    17

    Inverse Tan in C++

    Does anybody know the function for "inverse tangent" in C++?
    I'm rendering my apartment and have writen a function to build entire walls given it's starting (x,y) and ending (x,y) coordinates, along with other info such as window and door positions. I need to find Theta of the wall so I can rotate it and translate it to it's position. So I need to do "inverse tan(deltaY/deltaX)".

    Is it in math.h? or another *.h?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Apr 2011
    Posts
    288

    Re: Inverse Tan in C++

    In VC++, there are
    atan and atan2

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    17

    Re: Inverse Tan in C++

    Originally posted by Coconut:

    In VC++, there are
    atan and atan2

    What are the param's for atan and atan2.
    I'm just passing in a single float.
    I'm not lazy, I just won't be able to look at math.h for another 3 hours.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Apr 2011
    Posts
    288

    Re: Inverse Tan in C++

    atan takes one parameter
    atan2 takes two.

    In your case, you can either do

    atan(deltay/deltax) or
    atan2(deltay, deltax)

    I suppose atan2 returns value within the whole circle (-PI, PI) while atan returns half circle (-PI/2, PI/2)??

  5. #5
    Guest

    Re: Inverse Tan in C++

    Common newbie mistake:

    atan(deltay/deltax)

    This will NOT always give an accurate answer. The range of the atan function is NOT [0, 2pi], and since different triangles with different values of deltax and deltay can have the same tangent and can produce the same result--you should avoid this using some basic trig. Use the absolute value of deltax and deltay so that you will always get a reference angle on [0, pi/2).

    Then, using the signs for the original deltax and deltay, you can add/subtract from 0 or pi to get the actual angle.

  6. #6
    Junior Member Newbie
    Join Date
    Oct 2001
    Posts
    17

    Re: Inverse Tan in C++

    Thanks, but I won't need to do any adjustments. At the very most my theta will fall in the range of [+PI,-PI]. It has worked perfectly for all test cases. Using my program's createWall function I was able to render my entire appartment in 15 min with no angle screw-ups.

Similar Threads

  1. inverse()
    By Itun.itu in forum OpenGL: GLSL
    Replies: 1
    Last Post: 04-28-2011, 05:40 PM
  2. matrix inverse
    By powerpad in forum OpenGL: GLSL
    Replies: 2
    Last Post: 06-07-2005, 02:43 AM
  3. The inverse of a quaternion.
    By lgc_ustc in forum OpenGL: General
    Replies: 2
    Last Post: 01-26-2004, 12:54 PM
  4. inverse matrix
    By DarkFX in forum OpenGL: General
    Replies: 2
    Last Post: 01-08-2004, 03:04 AM
  5. inverse cos
    By haust in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-17-2000, 08:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean