rksprst
rksprst

Reputation: 6631

How do I get the "reverse" tangent in objective-c?

I know that tan(angle) gets me the tangent. But how do I do the "reverse tangent" so that I can get the angle given the length of both sides of the right triangle?

I'm assuming there is a method for this in math.h?

Upvotes: 6

Views: 18774

Answers (3)

rmeador
rmeador

Reputation: 25696

As others have mentioned, atan() is what you're looking for. Generally, the operation is referred to as "inverse tangent" or "arc tangent", not "reverse tangent". The name "atan" comes from "arc tangent". There's also an atan2() function which takes both the X and the Y coordinates as separate paramters and will give you an angle relative to the 0 mark whereas atan() will leave figuring out the quadrant as an exercise for the developer. Beware, however, that the atan2() function on certain older MS environments (or maybe visual studio libraries?) doesn't work quite right...

Upvotes: 15

Chris Cudmore
Chris Cudmore

Reputation: 30151

use atan()

Upvotes: 1

Toon Krijthe
Toon Krijthe

Reputation: 53366

There should be an atan() function.

For example: http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.7.html

Upvotes: 9

Related Questions