How to determine if a mouse moves clockwise or counterclockwise?

I have an MFC application in which the user needs to move the mouse around a circular circle using drag and drop. I need to get the number of degrees during this “drag” mouse drag, and I need to know clockwise or counterclockwise.

First, to determine the direction of rotation, I compared the x-coordination between the current mouse position and the mouse position where the user clicked to initiate a drag. This works well until the user rotates 180 degrees.

How can I process the other half of the circle?

+3
source share
3 answers

You will need at least three ordered items to determine if someone is moving clockwise or counterclockwise over time. Having only two points, it is unclear (for example) someone turned 90 degrees or -270 degrees. Thus, a simple cross product of the beginning and the end will not work.

Try to select the mouse while dragging to get the additional information you need, and then take incremental cross-products between each pair of consecutive points. This will tell you what you want to know. However, you will need to try fast enough so that there is no turning more than 180 degrees; otherwise, you will again encounter an ambiguous situation.

+6
source

Read cross products . Calculation of the cross product between the vectors X and Y (differences from the starting point) will always reliably give the direction of rotation.

+1
source

Source: https://habr.com/ru/post/1704804/


All Articles