Flu*_*der -1 python math pygame angle python-3.x
我想计算两点之间的角度。例如,假设我正在制作一个游戏,我想要一把枪指向鼠标光标,我得到将枪旋转到该角度所需的角度。
使用math库的atan2功能,
p1 = (2,2)
p2 = (-1,5)
# Difference in x coordinates
dx = p2[0] - p1[0]
# Difference in y coordinates
dy = p2[1] - p1[1]
# Angle between p1 and p2 in radians
theta = math.atan2(dy, dx)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4938 次 |
| 最近记录: |