两点之间的轴承 [英] Bearing between two points

查看:208
本文介绍了两点之间的轴承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用geopy软件包,它做得很好,但是我得到的一些结果不一致,或者出现了相对较大的位移,我怀疑问题出在我的方位计算上:
$ b

  def gb(x,y,center_x,center_y):
dx = x-center_x
dy = y-center_y $ b ((dy> = 0)和((dx> 0)或(dx <0))):
返回math.degrees(math.atan2(dy,dx))
elif( (math.degrees(math.atan2(dy,dx))+ 360)
else:$ b(dy <= 0)和((dx> 0)或(dx <0)):
return $ b return(math.degrees(math.atan2(dy,dx))+ 360)%360

我需要计算轴承,st center_x和center_y是关键。然后我使用geopy对gps坐标进行逆向工程:

  latlon = VincentyDistance(miles = dist).destination(Point(lat1, lon1),bearing)

任何人都可以指出我可能做错了什么?

解决方案


任何人都可以指出我可能做错了什么?

blockquote>


  1. 没有显示您的不一致或具有相对较大位移结果或预期结果的示例;因此回答者必须依靠猜测。

  2. 没有说明你的输入(x,y等)被测量的单位,以及如何得到 dist 用于目标计算中。我假设(在计算 bearing2 下面)时,正x以英里为单位,正y以英里为北。如果你想编辑你的问题来修正(1)和(2),这将会非常有帮助。 一种编码风格不会非常有利于让民众想要阅读它...看看


  3. 在学校三角学中,角度从X轴(东)逆时针测量。在导航中,从Y轴(北)顺时针测量轴承。见下面的代码。有关轴承的使用示例,请按照此链接,向下滚动到给定距离和从起始点开始的目的地点部分,请注意,该示例正在讨论的轴承约为96或97度,然后点击查看地图,您会注意到航向稍微偏东(东部是90度)。




  4. 代码:

    从数学导入度,atan2 
    def gb(x,y,center_x,center_y):
    angle =度数(atan2(y - center_y,x - center_x))
    bearing1 =(angle + 360)%360
    bearing2 =(90 - angle)%360
    printgb:x =%2d y =%2d angle =%6.1f bearing1 =在((0,1),(1,1),(1,0),(1,1),(1,1)轴承2 =%5.1f%(x,y,角度,轴承1,轴承2)

    ) (1,-1),(0,-1),( - 1,-1),( - 1,0),( - 1,1)):
    gb(pt [0],pt [ 1],0,0)

    输出:



    pre $ $ c $ g gb:x = 0 y = 1 angle = 90.0 bearing1 = 90.0 bearing2 = 0.0
    gb:x = 1 y = 1角度= 45.0轴承1 = 45.0轴承2 = 45.0
    gb:x = 1 y = 0角度= 0.0轴承1 = 0.0轴承2 = 90.0
    gb:x = 1 y = -1角度= -45.0轴承1 = 315.0轴承2 = 135.0
    gb:x = 0 y = -1角度= -90.0轴承1 = 270.0轴承2 = 180.0
    gb:x = -1 y = -1角度= -135.0轴承1 = 225.0轴承2 = 225.0
    gb:x = -1 y = 0 angle = 180.0 bearing1 = 180.0 bearing2 = 270.0
    gb:x = -1 y = 1 angle = 135.0 bearing1 = 135.0 bearing2 = 315.0


    Ive been using the geopy package , which does a great job, however some of the results i get are inconsistant or come with a relatively large displacement, i suspect that the problem resides with my bearing calculation:

    def gb(x,y,center_x,center_y):
    dx=x-center_x
    dy=y-center_y
    if ((dy>=0)and((dx>0)or(dx<0))):
        return math.degrees(math.atan2(dy,dx))
    elif (dy<=0)and((dx>0)or (dx<0)):
        return (math.degrees(math.atan2(dy,dx))+360)
    else:
        return (math.degrees(math.atan2(dy,dx))+360)%360
    

    I need to calculate the bearing, s.t. center_x and center_y are the pivot. afterwards i use geopy to reverse engineer the gps coordinate:

    latlon = VincentyDistance(miles=dist).destination(Point(lat1, lon1), bearing)
    

    Can anyone point me to what might i be doing wrong?

    解决方案

    Can anyone point me to what might i be doing wrong?

    1. Not showing an example of your "inconsistant or come with a relatively large displacement" results nor your expected results; consequently answerers must rely on guesswork.

    2. Not saying what units your input (x, y, etc) is measured in, and how you get the dist used in the destination calculation. I'm assuming (in calculating bearing2 below) that positive x is easting in miles and positive y is northing in miles. It would help greatly if you were to edit your question to fix (1) and (2).

    3. A coding style that's not very conducive to making folk want to read it ... have a look through this.

    4. In school trigonometry, angles are measured anticlockwise from the X axis (East). In navigation, bearings are measured clockwise from the Y axis (North). See code below. For an example of bearing in use, follow this link, scroll down to the "Destination point given distance and bearing from start point" section, notice that the example is talking about bearings of about 96 or 97 degrees, then click on "view map" and you will notice that the heading is slightly south of east (east being 90 degrees).

    Code:

    from math import degrees, atan2
        def gb(x, y, center_x, center_y):
            angle = degrees(atan2(y - center_y, x - center_x))
            bearing1 = (angle + 360) % 360
            bearing2 = (90 - angle) % 360
            print "gb: x=%2d y=%2d angle=%6.1f bearing1=%5.1f bearing2=%5.1f" % (x, y, angle, bearing1, bearing2)
    
        for pt in ((0, 1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1),(-1, 0),(-1,1)):
            gb(pt[0], pt[1], 0, 0)
    

    Output:

    gb: x= 0 y= 1 angle=  90.0 bearing1= 90.0 bearing2=  0.0
    gb: x= 1 y= 1 angle=  45.0 bearing1= 45.0 bearing2= 45.0
    gb: x= 1 y= 0 angle=   0.0 bearing1=  0.0 bearing2= 90.0
    gb: x= 1 y=-1 angle= -45.0 bearing1=315.0 bearing2=135.0
    gb: x= 0 y=-1 angle= -90.0 bearing1=270.0 bearing2=180.0
    gb: x=-1 y=-1 angle=-135.0 bearing1=225.0 bearing2=225.0
    gb: x=-1 y= 0 angle= 180.0 bearing1=180.0 bearing2=270.0
    gb: x=-1 y= 1 angle= 135.0 bearing1=135.0 bearing2=315.0
    

    这篇关于两点之间的轴承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆