# Angle between 2 vectors using the determinant

I have a polygon like this:

I basically want to find the angles $\alpha$, inside the polygon, between the vectors. I'm using the determinant to calculate the angle alpha:

$det(\vec V2, \vec V2 ) = ||V2|| * ||V1|| * \sin \theta$

So $\theta$ will be the arcsin. But my problem is that in this particular case, the angle that is calculated is not $\alpha$ but it's 180- $\alpha$ and I don't understand why.

This is my code in C:

TSMV_Point2D vecteur1, vecteur2;
vecteur1.x = p1.x - pC.x;
vecteur1.y = p1.y - pC.y;
vecteur2.x = p2.x - pC.x;
vecteur2.y = p2.y - pC.y;

float determinant = vecteur2.x * vecteur1.y - (vecteur1.x * vecteur2.y);
float normeVec1 = sqrt(vecteur1.x * vecteur1.x + vecteur1.y * vecteur1.y);
float normeVec2 = sqrt(vecteur2.x * vecteur2.x + vecteur2.y * vecteur2.y);

float division = determinant / (normeVec1 * normeVec2);
float angle = asin(division) * 180 / M_PI;


Can someone help me understand?

• I put the "Hello" in front of the paragraph but whenever I edit it, my Hello keeps been deleted. – user3314570 Jun 19 '14 at 11:46

Because the formula you have is not correct. The dot product of two vectors equals the product of the norms of the vectors times cosine of the angle.

$$\mathbf{V_1} \cdot \mathbf{V_2}=||\mathbf{V_1}||\cdot ||\mathbf{V_2}|| \cdot \cos\theta$$

• I am not using the dot product but the determinant. But I understood why it's not the right angle, it's because the arcsin function is only betwen $-\pi/2 \pi/2$ – user3314570 Jun 19 '14 at 13:07
• That's why people usually use dot product to calculate the angle between two vectors. Arccos gives value between $0$ and $\pi$. – Badoe Jun 19 '14 at 13:14
• Also, two vectors with angle $\alpha$ and two vectors with angle $\pi-\alpha$ will give you the same sine value. How do you determine if the angle is $\alpha$ or $\pi - \alpha$? – Badoe Jun 19 '14 at 13:23

Well, usually angles between two vectors are considered to be lying in $[0,\pi]$ and so choosing a formula with $\arccos$ in it is a better choice, as @Badoe mentioned.

However, in your particular case, keep in mind that $\arcsin$ is defined over $\left[-\frac{\pi}{2},\frac{\pi}{2}\right]$, so, it is very possible that the angle you would like to get is actually larger than $90^\circ$ and, hence, $\arcsin$ moves is back into $\left[-\frac{\pi}{2},\frac{\pi}{2}\right]$, resulting to giving you the complementary angle of what you've been looking for.

But, the above is just a speculation, it would be more helpful if someone could enlight us on how is $\arcsin$ implemented in $C$. Till then, you can always use the formula: $$\theta=\arccos\frac{\vec{v}\cdot\vec{u}}{\lVert \vec{v}\rVert\lVert \vec{u}\rVert}$$