Calculate the angle of a vector in compass (360) direction Given a vector described by X and Y components
$x=4$
$ y=-2$
I get the direction of the vector by using $\arctan{-\frac 24}$. 
$\theta= -0.4636 \text{ rad}$
$\theta=  -26.565^{\circ}$
My initial confusion was that I assumed the degrees in theta referred to a compass direction as would be measured with a protractor. But a vector of 4,-2 ends up in the 2nd quadrant somewhere between 90 and 180, so I know -26 is not my true compass direction of the vector. 
So my question is, how do you convert the theta direction of a vector to a compass bearing (0-360 degrees)
 A: If you are working solely in degrees, the following equation will transform your angle from polar coordinates (0 at x, 0 going CCW) to compass angle (0 at 0, y going CW)
(450 - θ) % 360
where % is the modulus function
A: $0^\circ$ for $\arctan$ is to the right, along the $+x$ axis increasing counterclockwise. $(4,-2)$ is in the $4$th quadrant, at $-26$ degrees.  On a compass $0^\circ$ is North, straight up increasing clockwise. Compass $=90^\circ-\arctan(+180^\circ)$, but you need to account for a sign ambiguity, which is expressed by the $(+180)$.  To avoid that problem, you can use $atan2(x,y)$, which returns the mathematical angle and keeps track of the quadrant for you.
A: The tangent function has period $180^\circ.$ Hence, for any integer $n$, we have $\tan(\arctan(x)+180n^\circ)=x$. The arctangent function gives values in the degree interval $(-90,90)$. In particular, then, if $\arctan(x)<0^\circ,$ and you want a positive angle whose tangent is $x,$ then you need only look at $\arctan(x)+180^\circ$ and $\arctan(x)+360^\circ,$ choosing the one that puts you in the correct quadrant.
A: A formula that give the compass direction .
Start 0 degrees from the north and increasing clockwise from 0 to 360 degrees.
f(x,y)=180/pi()* (pi()-pi()/2*(1+sign(y))* (1-sign(x^2))-pi()/4*(2+sign(y))*sign(x)
   -sign(x*y)*atan((abs(y)-abs(x))/(abs(y)+abs(x))))

The formula is working for any value of x and y.
For x=y=o the result is undefined.
