Python:是否存在已经找到角度和两点之间距离的模块?

标签 python math geometry trigonometry

首先,我很抱歉提出这个简单的问题。可能有一个模块可以计算两点之间的角度和距离。

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

最佳答案

给定

enter image description here

您可以计算角度、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 比使用点积公式更容易)。

关于Python:是否存在已经找到角度和两点之间距离的模块?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13543977/

相关文章:

Python:找到字符串后读取行

math - 您如何解释FFT输出产生的频率

python - 使用第二个矩阵选择三维元素,将 3D 数组展平为 2D 数组

python - 为什么最大索引比行数低这么多?

math - ARM 汇编浮点变量

c++ - 半空间到点测试

actionscript-3 - ActionScript 3 中的锥形效果

r - 在 map 中绘制半径为定义距离的圆

python - 以特定格式将 "dictionary of dictionaries"写入 .csv 文件

c - 问题打印矩阵值