I need to write a small program which to test whether a line (position vector) does strictly clockwise or CCLW movement. I tried to use atand to find the angle, but it could jump from negative to positive value when it pass thought 90 deg, it will have the same thing if I use slope method.
However, the motion does not have to cut at 90 deg, it could jump from 89 to 91. Then a big slope jump could happen. Any idea please
Thanks
One way to do this would be to calculate the cross-product of consecutive position vectors. If all the cross-products are positive then the line moved with a strictly clockwise. Similarly, if they are all negative then the line moved counter-clockwise. If the signs are mixed then the line did not move strictly in one angular direction:
Create some random position vectors on
-10<=x<=10and-10<=y<=10and test rotation:>> pos = 20 * rand([10, 2]) - 10 pos = -8.28968405819912 9.26177078573826 -4.75035530603335 0.936114374779359 6.02029245539477 0.422716616080031 -9.41559444875707 -5.36811226582952 8.57708278956089 -0.222045121596661 4.60661725710906 2.48120176347379 -0.227820523928417 3.58271081731495 1.57050122046878 -2.08969568662814 -5.25432840456957 -2.65126702911047 -0.823023436401378 9.75964006323266 >> checkRotation(pos) No strict rotation directionCreate position vectors that move only CCW and test:
and similarly for CW rotation:
Note that the success of rotation detection is limited by your sampling rate. If the line rotates counter-clockwise by more than 180 degrees in successive samplings of the line position, it is indistinguishable from a rotation less than 180 degrees in the clockwise direction. This is an example of aliasing.