# Calculating Travel Direction of two coordinates

Maths isn't my strong point and i've been stuck here for hours trying to figure out how do to this (it's probably gona be very easy to do now as well) but it's driving me crazy so i'm going to ask for a little help..

I need to calculate what way the user is rotating an object... I have 3 coordinates.. 1 is the center of the object and the other 2 are the previous and the new touch locations...

I am already using the three coordinates to calculate the angle of change since the last update and that I can do ok..

However I am now at the point where I need to figure out if the user is rotating the object clockwise or anticlockwise... This is what I thought would be easy but i've been stuck here for hours now (maybe I just need a break?).

At the moment I am creating two triangles from the center to both the previous and new coordinate then using the hypotenuse from each one and then joining the previous coordinate with the new one to create another triangle where I can then use the cosine and sine rule to calculate the angle between the previous and new coordinate in relation to the center coordinate however as I said I'm useless at maths and after sitting here so long, all i can think of is ridiculously long (truth table approach but this could have 30 different equations)

Is there something simple i'm missing?

Thanks

Liam

-

I'm not completely sure I understand your setup.

If you just need to determine the direction of rotation, you can use the cross product.

Suppose the object is at $p=(p_x,p_y)$, that the first touch point is $t^1=(t_x^1,t_y^1)$, and the second touch point is $t^2=(t_x^2,t_y^2)$. Then the rotation will be clockwise if $(t^1-p)\times (t^2-p) >0$, ambiguous if equal to $0$ and anticlockwise if negative.

In coordinates: $$(t^1-p)\times (t^2-p) =(t_x^1-p_x)(t_y^2-p_y)-(t_y^1-p_y)(t_x^2-p_x)$$

This is essentially using the fact that if $\theta \in (0,\pi)$, then $\sin \theta >0$, and if $\theta \in (-\pi,0)$, then $\sin \theta <0$. The computation of $\sin$ comes indirectly from the cross product.

-
Thanks for the response! Can't test right now but you do understand me correctly... Will check this out tomorrow and let you know how it goes. Liam –  L14M333 May 2 '12 at 19:00
Just tested.. works great! thank you so much –  L14M333 May 3 '12 at 10:29