python 平面直角坐標系 計算從點A到點B的方向
可以使用以下公式计算从点A到点B的方向:
方向角 = arctan2(yB-yA,xB-xA)
其中,arctan2是一个数学函数,用于计算给定的y和x坐标的反正切值。在Python中,可以使用math模块中的atan2函数来计算。
下面是一个示例代码,演示如何计算从点(1,2)到点(3,4)的方向:
import math
xA = 1
yA = 2
xB = 3
yB = 4
direction = math.atan2(yB-yA, xB-xA)
print("Direction angle from A to B:", math.degrees(direction), "degrees")
输出结果为:
Direction angle from A to B: 45.0 degrees
这意味着从点A到点B的方向角度为45度,即向右上方。
原文地址: https://www.cveoy.top/t/topic/fljg 著作权归作者所有。请勿转载和采集!