Python 网格参考和轨迹

2024-04-26 00:21:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个用户给我两个网格参考,我可以找到距离,但我正在努力寻找角度(0-359)从北(北是正x)

X=北

Y=向上

z=东

import math
#Find distance between two points
print ("Travel From.")
x_1 = float(input("X_1:"))
y_1 = float(input("Y_1:"))
z_1 = float(input("Z_1:"))
print ("To")
x_2 = float(input("X_2:"))
y_2 = float(input("Y_2:"))
z_2 = float(input("Z_2:"))
#Find the Difference between the two coordinates.
x_dif = x_2 - x_1
y_dif = y_2 - y_1
z_dif = z_2 - z_1
print ("Location Difference:")
print ("X: %s" %x_dif)
print ("Y: %s" %y_dif)
print ("Z: %s" %z_dif)
#Squares the Difference
x_dif = x_dif * x_dif
y_dif = y_dif * y_dif
z_dif = z_dif * z_dif
#Adds the differences together
distance = x_dif + y_dif + z_dif
print ("Distance: sqr(%s)" %distance)
#Finds the Square root and thus the distance.
distance = distance ** 0.5
print ("Distance: %s" %distance)
distance = float('%.1g' % distance)
print ("Distance: %s" %distance)
#Tries to find the bearing from north (x+)
azimuth_1 = y_dif + z_dif
azimuth_1 = azimuth_1 ** 0.5
y_dif = y_2 - y_1
azimuth_1 =  x_dif/ azimuth_1
#Reverse Cosine
azimuth_1 = math.acos(azimuth_1)
#Converts into degrees from Radians
azimuth_1 = math.degrees(azimuth_1)
#Corrects for inverse:
x_dif = x_2 - x_1
y_dif = y_2 - y_1
z_dif = z_2 - z_1
if x_dif < 0:
    print ("azimuth_1:-%s" %azimuth_1)
elif x_dif > 0:
    print ("azimuth_1: %s" %azimuth_1)
elif x_dif == 0:
    print ("azimuth_1: %s" %azimuth_1)
else:
    print ("azimuth_1: %s" %azimuth_1)

在我这样做之后,我需要做相反的事情。然而,事实证明,这比我预想的要困难得多


Tags: thefrominputmathbetweenfindfloatdistance