问题描述
我有一个MFC应用程序,用户必须用拖动动作在圆形圆周上移动鼠标.在此鼠标拖动旋转"过程中,我需要获取度数,我需要知道它是顺时针还是逆时针.
I have an MFC appplication where the user have to move the mouse around a circle circonference with a dragging mouvement. I need to retrieve the number of degrees during this mouse drag "rotation" and I need to know if it's clockwise or counterclockwise.
首先,为了确定旋转方向,我在当前鼠标位置和用户单击以启动拖动的鼠标位置之间比较了x坐标.在用户旋转180度之前,效果很好.
At first, to determine the rotation direction, I was comparing x-coordinnate between the current mouse position and the mouse position where the user clicked to initiate the dragging. That works well until the user rotate over 180 degrees.
我如何处理圆圈的另一半?
How can I handle the other half of the circle?
推荐答案
您至少需要三个有序点,才能确定某人是随时间顺时针还是逆时针移动.只有两点,例如某个人旋转90度或-270度,这并不明显.因此,简单地采用起点和终点的叉积是行不通的.
You'll need at least three ordered points to determine whether someone is moving clockwise or counterclockwise over time. With only two points, it isn't obvious whether (for instance) someone rotated 90 degrees or -270 degrees. So simply taking the cross product of the start and end won't work.
尝试在拖动过程中对鼠标进行采样以获得所需的其他信息,然后在每对连续点之间获取增量叉积.那会告诉你你想知道什么.但是,您需要足够快地进行采样,以使不会发生超过180度的旋转;否则,您将再次陷入歧义.
Try sampling the mouse during the dragging to get the additional information you need, and then taking incremental cross products between each pair of consecutive points. That will tell you what you want to know. However, you'll need to sample fast enough that no rotation of more than 180 degrees could have occurred; otherwise you'll wind up in an ambiguous situation again.
这篇关于如何确定鼠标是顺时针还是逆时针移动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!