I have 3 Points (x,y) that represent mouse movement (from Point 1 over Point 2 to Point 3).

The angle between the two lines (line between p1 and p2 & line between p2 and p3) can be caluculated with

Calculate angle between vectors

where a = [(p1.x - p2.x), (p1.y - p2.y)] and b = [(p3.x - p2.x), (p3.y - p2.y)]

But the angle is just the inner angle and doesn't tell me if the line rotates / moves left, straight or right.

Here my problem in a example:

vector movement / rotation

I want to calculate that the movement from p1 to p3 over p2 has a right rotation and the movement from p1 to p4 over p2 has a left rotation. Both have the same angle.

In other words: If you follow the vector a longer than point p2 is p3/p4 on the line, left of the line or right of the line.

How can i calculate that?


You can use the vector product of two vectors $\vec x\times \vec y$. In $2D$ it writes as $\vec x\times \vec y = x_1y_2-x_2y_1$. If this quantity is positive, then the rotation is in positive direction (anticlockwise), if it is zero, then the vectors are colinear (or at least one of them is a zero vector), and if it is negative, then the rotation goes in negative direction (clockwise).

You might want to read the wiki article on vector product.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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