Search code examples
c++vectorangle

Angle from 2D unit vector?


Given unit vector (0.5, 0.5) how could I find the angle (its direction)?

Is it cos(x) + sin(y)?


Solution

  • Given y and x, the angle with the x axis is given by:

    atan2(y, x) // note that Y is first
    

    With (0.5, 0.5) the angle is:

    radians:

    In [2]: math.atan2(0.5, 0.5)
    Out[2]: 0.7853981633974483
    

    degrees:

    In [3]: math.atan2(0.5, 0.5)*180/math.pi
    Out[3]: 45.0