2

まず、この簡単な質問を投稿して申し訳ありません。おそらく、2点間の角度と距離を計算するモジュールがあります。

  • A =(560023.44957588764,6362057.3904932579)
  • B =(560036.44957588764,6362071.8904932579)
4

2 に答える 2

7

与えられた

ここに画像の説明を入力してください

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ので、内積式よりも使いやすいです)。

于 2012-11-24T18:06:16.130 に答える
4

確かに、mathモジュールにはatan2math.atan2(y, x)に対する角度(0, 0)です(x, y)

までmath.hypot(x, y)の距離形式もあります。(0, 0)(x, y)

于 2012-11-24T18:07:44.927 に答える