# Find the Angle ( as Measured in Counter Clock Wise Direction) Between Two Edges

This is a similar question to this one, but slightly different.

The question is given two edges ($e_1$ and $e_2$, with the vertex coordinates known), how to find the angles from $e_1$ to $e_2$, with the angles measured in anti clock wise direction?

A diagram is shown below:

One way I can think of is to compute the cross and dot product of the two edge's unit vector

$$\sin\,\theta=\frac{|e_1\times e_2|}{|e_1||e_2|}$$ $$\cos\,\theta=\frac{e_1\cdot e_2}{||e_1|| ||e_2||}$$

And try to find the $\theta$, taken into account of whether $sin\theta$ and $cos\theta$ is $>0$ or $<0$. But this is very, very tedious and error prone. Not to mention I'm not too sure whether the angle I get is always measured in counter clock wise direction or not.

Is there a single, clean formula that allows me to do what I want to do?

-
The two-argument arctangent would be very useful here. –  Ｊ. Ｍ. Dec 22 '10 at 7:41
@J.M, would you like to post your comment as answer so that I can accept it? –  Graviton Dec 29 '10 at 12:29
Gimme a few minutes; my comment as it stands is not a proper answer. –  Ｊ. Ｍ. Dec 29 '10 at 12:44
@J.M., it's enough to point me into the right direction and find the solution. –  Graviton Dec 29 '10 at 12:44

The way to get the smaller angle spanned by $\mathbf e_1=(x_1,y_1)$ and $\mathbf e_2=(x_2,y_2)$ is through the expression
$\min(|\arctan(x_1,y_1)-\arctan(x_2,y_2)|,2\pi-|\arctan(x_1,y_1)-\arctan(x_2,y_2)|)$
where $\arctan(x,y)$ is the two-argument arctangent.