-1

I know I can get given angle's trigonometric functions by math.h. I was wondering, if it can be done in reversed direction.

Let's say there's a vector with two coordinates. I have its x and y values, so tangent can be easily calculated

float tg;
if(x != 0)
{
    tg = y/x
}
else
{
    //vector is vertical and it doesn't have a tangent
    //handle this somehow
}

However, I see no way of doing it reversely. I need a way to get angle between 0 and 2pi based on it's tangent.

Maciej Dziuban
  • 386
  • 2
  • 17

1 Answers1

6

Use the function angle = atan2(y, x) Here's a link to more info: http://www.cplusplus.com/reference/cmath/atan2/

OR

http://en.cppreference.com/w/cpp/numeric/math/atan2

Kendel
  • 1,680
  • 2
  • 14
  • 32
  • 2
    I would recommend to link the reference proposed in [Alan Stokes comment](http://stackoverflow.com/questions/27749475/how-to-get-angle-based-on-trigonometric-function-in-c#comment43910258_27749475) – πάντα ῥεῖ Jan 02 '15 at 22:46