Gia*_*ear 2 python math geometry trigonometry
首先,我很抱歉发布这个简单的问题.可能有一个模块来计算两点之间的角度和距离.
特定

您可以使用以下方法计算角度,theta以及A和B之间的距离:
import math
def angle_wrt_x(A,B):
"""Return the angle between B-A and the positive x-axis.
Values go from 0 to pi in the upper half-plane, and from
0 to -pi in the lower half-plane.
"""
ax, ay = A
bx, by = B
return math.atan2(by-ay, bx-ax)
def dist(A,B):
ax, ay = A
bx, by = B
return math.hypot(bx-ax, by-ay)
A = (560023.44957588764, 6362057.3904932579)
B = (560036.44957588764, 6362071.8904932579)
theta = angle_wrt_x(A, B)
d = dist(A, B)
print(theta)
print(d)
Run Code Online (Sandbox Code Playgroud)
产量
0.839889619638 # radians
19.4743420942
Run Code Online (Sandbox Code Playgroud)
(编辑:由于您正在处理平面中的点,因此它atan2比点积公式更容易使用).