View Full Version : Inverse Tan in C++

drummerboy_2002

07-31-2002, 08:27 AM

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?

Coconut

07-31-2002, 08:34 AM

In VC++, there are

atan and atan2

drummerboy_2002

07-31-2002, 08:36 AM

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.

Coconut

07-31-2002, 09:21 AM

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)??

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.

drummerboy_2002

08-01-2002, 07:31 AM

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.

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.