まず、この簡単な質問を投稿して申し訳ありません。おそらく、2点間の角度と距離を計算するモジュールがあります。
- A =(560023.44957588764,6362057.3904932579)
- B =(560036.44957588764,6362071.8904932579)
まず、この簡単な質問を投稿して申し訳ありません。おそらく、2点間の角度と距離を計算するモジュールがあります。
与えられた
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)
これは
0.839889619638 # radians
19.4743420942
(編集:平面内の点を扱っているatan2
ので、内積式よりも使いやすいです)。
確かに、math
モジュールにはatan2
。math.atan2(y, x)
に対する角度(0, 0)
です(x, y)
。
までmath.hypot(x, y)
の距離形式もあります。(0, 0)
(x, y)