Signed angle in plane

134 Views Asked by At

What is the formula to compute the signed angle between two vectors $u, v\in\mathbb{R}^2$ where positive angle is equivalent to a counter-clockwise rotation on the plane

In other words I would like to create a function $\angle(u, v)$ where

$$\angle(u, v) = -\angle(v, u)$$ $$\angle(u, v) = -\angle(u, -v)$$ $$\angle(u, v) = \angle(-u, -v)$$ $$\angle(u, v) = \pi + \angle(-u, v)$$

and I want that $\angle(e_1, e_2)=\frac{\pi}{2}$

1

There are 1 best solutions below

0
On

Just a small observation first, you will have some minor inconsistencies when the angle is either $\pi$ or $0$.

To calculate the angle, you can use the $\sin$ and $\cos$ function, at the same time. Using both will allow you to uniquely define the angle between $-\pi$ and $\pi$. The cosine of the angle is given by the scalar product:$$u\cdot v=|u||v|\cos\theta$$In $\mathbb R^2$ you can write the scalar product as $u\cdot v=u_xv_x+u_yv_y$.

You get the sine of the angle using cross product $$u\times v=|u||v|\sin\theta$$ In $\mathbb R^2$ you can write the cross product as $u\times v=u_xv_y-u_yv_x$.

Note that the ratio of the cross product and scalar product is the tangent of the angle. But the range of the $\arctan$ function is from $-\pi/2$ to $\pi/2$. Note however that there is a function $\mathrm{arctan2}$ or $\mathrm{atan2}$ in some programming languages that take the sine and cosine and give you the correct angle. See for example the definition on wikipedia Then $$\angle(u,v)=\mathrm{arctan2}(u\times v,u\cdot v)$$