我有一个Python代码应用程序,它记录鼠标活动(按规则间隔记录的点,时间等待),然后处理数据以输出鼠标移动的角度(Y轴为0)和它移动的速度。
目前我的输出是东0度,南-90度,西180度,北90度,这不是我的预期输出。我不确定三角法或其他计算中是否有问题,所以希望对这方面的任何帮助。
i = 0
angles = []
speeds = []
#positions is an array of coordinates taken 0.1 seconds apart from each other
for point in positions:
if i is not 0:
pointY = 2500 - point[1] #invert position of X and assign variable
deltaX = point[0]-pointXP # difference is current pointX minus PointXPast
deltaY = pointY-pointYP
dist = math.sqrt(deltaX**2 + deltaY**2) #distance is the hypotenuse
if dist is 0: #if the mouse has not moved
continue
speed = dist/timeWait # speed is distance/time
angle = math.degrees(math.atan2(deltaY,deltaX)) #angle using Tan
angles.append(angle)
speeds.append(speed)
pointXP = point[0]
pointYP = pointY
else: #this is only for the first iteration
i = 1
pointXP = point[0]
pointYP = 2500 - point[1]
continue
再次感谢您的帮助,特别是关于我的角度被关闭。谢谢。