I am a computer programmer trying to find if the movement of mouse was in clockwise or anticlock wise direction when user moves the mouse in circles, i am using this formulae to find the if direction was clockwise or anti clockwise.

((b.x ‐ a.x)(c.y ‐ a.y) ‐ (b.y ‐ a.y)(c.x ‐ a.x))

where b = First click

c = second click

a = Mid point of the circle

How can i get the values for point a.


The formula you give requires three points to determine the center, otherwise it is indeterminate (and could be any of infinitely many circles).

If you're just wanting to know whether it is clockwise or anticlockwise, suppose you have three points on the path, $p_1$, $p_2$, and $p_3$, and consider vectors $v_1=p_2-p_1$ and $v_2=p_3-p_2$. Let $R$ be the rotation matrix for the angle 90 degrees anticlockwise. Compute the number $a=(Rv_1)\cdot v_2$, where the dot is dot product. If this number $a$ is positive, the points are along an anticlockwise path, and if it is negative, the points are along a clockwise path. This formula represents projecting the second vector onto a vector perpendicular to the first, then seeing in which direction that projection goes.

Just to be more concrete, suppose $v_1=(x_1,x_2)$ and $v_2=(y_1,y_2)$. Then $a=x_1y_2-x_2y_1$. (This is the third component of a cross product of $v_1$ and $v_2$ as if they were 3D vectors.)

  • $\begingroup$ i tried your formula but it keeps giving me both negative and positive values. $\endgroup$ – sumit kang Oct 5 '15 at 7:57
  • $\begingroup$ p1 = vPrevPosition1, p2 = vPrevPosition.x, p3 = vCurrentPosition, vector1.x = vPrevPosition.x - vPrevPosition1.x, vector1.y = vPrevPosition.y - vPrevPosition1.y, vector2.x = vPrevPosition.x - vCurrentPosition.x, vector2.y = vPrevPosition.y - vCurrentPosition.y $\endgroup$ – sumit kang Oct 5 '15 at 7:58
  • $\begingroup$ I'm not exactly sure what you are doing, but this might be a sampling problem: make sure the three points are far enough away from each other. Or you might consider summing up this number $a$ along the whole path and seeing whether the result is positive or negative (this amounts to a line integral). $\endgroup$ – Kyle Miller Oct 5 '15 at 17:02
  • $\begingroup$ Here's a rough implementation: tmp.kylem.net/turning/path.html (The turning number is implemented in tmp.kylem.net/turning/path.js as turningNumber at the top. It will output a number which is roughly how many times the path looped around, positive meaning anticlockwise.) $\endgroup$ – Kyle Miller Oct 5 '15 at 21:33
  • $\begingroup$ yes the points are very close to each other $\endgroup$ – sumit kang Oct 8 '15 at 4:39

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.