尝试确定围绕某个点的运动矢量是顺时针还是逆时针
我正在为 iOS 设备编写一些触摸输入代码,需要确定滑动运动相对于屏幕中心是顺时针还是逆时针。
使用触摸的 position
和 deltaPosition
,我可以使用点积计算从屏幕中心到这些点的向量之间的角度,但这并没有给我一个有符号角度来决定是否是CW。
我如何知道滑动已围绕中心向哪个方向移动?
I'm writing some Touch input code for an iOS device and need to determine whether the movement of a swipe is clockwise or counterclockwise relative to the center of the screen.
Using the position
and deltaPosition
of the touch, I can calculate an angle between vectors from the center of the screen to those points using the dot product but that doesn't give me a signed angle to decide whether it's CW or not.
How can I tell which direction around the center the swipe has moved?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令 A 表示滑动向量,B 表示从滑动开始到屏幕中心的向量。然后,您可以计算 A 和 B 分量的行列式:
行列式的符号将告诉您是否 B em> 指向A 的右侧或左侧。
正如 @Jeremy W. Sherman 正确指出的那样,哪个符号对应哪个方向取决于屏幕坐标系的布局方式。如果x轴向右运行,y轴向下运行,则正值表示顺时针,负值表示逆时针(如果我的心算正确的话)。零始终意味着直接朝向或直接远离中心的运动。
Let A denote the swipe vector, and B the vector from the start of the swipe to the center of the screen. You can then calculate the determinant of the components of A and B:
The sign of the determinant will tell you whether B points to the right side or to the left side of A.
As @Jeremy W. Sherman correctly notes, which sign corresponds to which direction depends on how the coordinate system of the screen is laid out. If the x axis runs to the right and the y axis runs downward, positive means CW and negative means CCW (if I got the mental math right). Zero always means movement directly towards or directly away from the center.