#### Archived

This topic is now archived and is closed to further replies.

# Simple math question about Sin, Cos, Tan

## Recommended Posts

Hi, That''s a pretty easy question. I have a triangle, i got the two lenght of the sides, but not the hypotenuse. I try to find the angle. Like this: The formula : tan (ang) = long1 / long2 The answer : ang = tan-1 (long1 / long2) It''s tan at power -1... So i can i code this Line in c/c++ ?! c dont have any tan-1 fnc. Thanks for your help ?! LowRad

##### Share on other sites
What you''re looking for for is arctan(), that''s the inverse cosine function, as is arcsin, etc.

ByteMe95::~ByteMe95()

##### Share on other sites
I too had the same problem. But it''s easy to solve
use 1/tan(Same with Sin, Cos). It''s the same as tan-1

##### Share on other sites
I beg to differ:

cos(90 degrees) = 0
cos-1(0) = 90 degrees
1/cos(90 degrees) = divide by zero error

plus it''s not right non-general rule anyway. Where did you study maths? And don''t claim it works in radians because it doesn''t.

##### Share on other sites
Mindwipe, that''s completely wrong, where did you come up with that???

Just use arccos()

ByteMe95::~ByteMe95()

##### Share on other sites
I think mindwipe read "tan()-1" as "tan() to the -1 power" which is 1/tan() of course

##### Share on other sites
arctan(x) isn't the same as 1/tan(x). arctan(x) means: "the inverse function of tan", it's not the "inverse result of tan(x)".
To find the angle use:

theta = arctan(length_y/length_x);

Do not invert the sides. length_y is the opposite side, and length_x is the adjacent side.

Edited by - blazter on July 21, 2000 5:43:38 PM

##### Share on other sites
Anonymous Poster> Yup that was what I ment. I''ve actally used it. And it works. Well, I no master on math. Due to lack of knowledge.

Just wanted to try to help

##### Share on other sites
Umm, are we assuming this is a right triangle? Those trig identities only work for a right triangle, don''t they? I''ve almost got an AA in Math on accident ...

##### Share on other sites
I don't know what is a right triangle in English. Do you mean that one of the angles must be 90 degrees ?
If so, yes it's right. These trig. functions only work on orthogonal coord. and on right triangles. By the way only a triangle with a angle of 90 degrees can have a hypotenuse.

Edited by - blazter on July 24, 2000 1:20:30 PM

##### Share on other sites
If you''re in C/C++, use atan2(x,y). It automatically
deals with special cases like x=0 y=1, where
regular atan(t) causes a divide by 0 error or
returns NaN, inf, or some other floating point code.
I''m sure any other language you use will have a
similar function.

##### Share on other sites
interestingly no-one seems to have mentioned that tan^-1 is how arctan is represented in mathematics.

##### Share on other sites
quote:
Original post by remo

interestingly no-one seems to have mentioned that tan^-1 is how arctan is represented in mathematics.

Lets clear some things up here...

tan(x) to the POWER of -1 is 1/tan(x) - which is the same as cotan(x) - in mathematics.

tan(x) with -1 superscript in mathematics is the inverse of tan(x). Which is arctan(x) in C++.

Now, if you ever need to do stuff with a non-right angled triangle, you can use either the sine rule or cosine rule, dependant on which is more useful. (these both work with right angled triangles too)

this is where:

a,b, and c are lengths of the sides of the triange.

A, B and C are the angles opposite to its corresponding side. Doesnt matter what its measured in (degrees, radians or quadrants (sp?) if you're weird like that) as long as all they're all the same.

sine rule:

a/sin(A) = b/sin(B) = c/sin(C)

cosine rule:

a^2 = b^2 + c^2 - 2bc . cos(A)

or b^2 = a^2 + c^2 - 2ac . cos(B)

or c^2 = a^2 + b^2 - 2ab . cos(C)

Of course, all of these can be rearranged to whatever you need it to do.

jumble
-----------
Microsoft patents ones and zeroes - remind you of Hasbro?

Edited by - jumble on July 24, 2000 2:45:06 PM

• ### Forum Statistics

• Total Topics
628333
• Total Posts
2982139

• 9
• 24
• 9
• 9
• 13