문제

ive는 훌륭한 직업을하는 지오파이 패키지를 사용하고 있지만, 내가 얻는 결과 중 일부는 일치하지 않거나 상대적으로 큰 변위를 가지고 있거나, 문제가 내 베어링 계산에 거주하는 것으로 의심됩니다.

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
.

나는 베어링을 계산해야합니다, s.t.CENTER_X 및 CENTER_Y는 피벗입니다.그런 다음 GPS 좌표를 리버스 엔지니어링으로 지오파이를 사용합니다.

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

누구든지 내가 무엇을 잘못 할 수 있는지 지적 할 수 있습니까?

도움이 되었습니까?

해결책

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

다른 팁

I'm not quite sure what you're trying to do in your code,but I do see some oddities that may need to be cleaned up.

  1. You test for dy<=0 after you test for dy>=0 in the conditional before. What should your code do if dy==0 and dx==0.
  2. Your test ((dy>=0)and((dx>0)or(dx<0))) is equivalent to (dy>=0 and dx!=0), is this what you intended?
  3. You are basically doing the same thing in all of your conditionals. Couldn't return math.degrees(math.atan2(dy,dx))+360)%360 work in every scenario? In that case, you wouldn't need to use your if statements anyway.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top