Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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?

share|improve this question
    
The two-argument arctangent would be very useful here. –  J. M. 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. –  J. M. 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

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.