2015-12-31 119 views
0

我試着去計算邊界框的中心,這些給定的點如何計算邊界框的中心?

(50.607041876988994, -1.3187316344406208, 52.40735812301099, 1.5737316344406207) 

編輯解決:這是我的代碼在python做

from math import cos, sin, atan2, sqrt 

    def center_geolocation(geolocations): 
     """ 
     Provide a relatively accurate center lat, lon returned as a list pair, given 
     a list of list pairs. 
     ex: in: geolocations = ((lat1,lon1), (lat2,lon2),) 
      out: (center_lat, center_lon) 
     """ 
     x = 0 
     y = 0 
     z = 0 

     for lat, lon in geolocations: 
      lat = float(lat) 
      lon = float(lon) 
      x += cos(lat) * cos(lon) 
      y += cos(lat) * sin(lon) 
      z += sin(lat) 

     x = float(x/len(geolocations)) 
     y = float(y/len(geolocations)) 
     z = float(z/len(geolocations)) 

     return (atan2(y, x), atan2(z, sqrt(x * x + y * y))) 

謝謝:)

+0

你傳遞給函數的參數是什麼? –

+0

我試着通過我的計算邊框(50.607041876988994,-1.3187316344406208,52.40735812301099,1.5737316344406207) –

回答

0
from math import * 

def center_geolocation(geolocations): 
    """ 
    Provide a relatively accurate center lat, lon returned as a list pair, given 
    a list of list pairs. 
    ex: in: geolocations = ((lat1,lon1), (lat2,lon2),) 
     out: (center_lat, center_lon) 
""" 
x = 0 
y = 0 
z = 0 

for lat, lon in geolocations: 
    lat = float(lat) 
    lon = float(lon) 
    x += cos(lat) * cos(lon) 
    y += cos(lat) * sin(lon) 
    z += sin(lat) 

x = float(x/len(geolocations)) 
y = float(y/len(geolocations)) 
z = float(z/len(geolocations)) 

return (atan2(y, x), atan2(z, sqrt(x * x + y * y))) 


center_geolocation( 
((50.607041876988994, -1.3187316344406208), 
    (52.40735812301099, 1.5737316344406207))) 

你給出的例子中沒有float錯誤....我不喜歡輸出 - 但那不是th問題。

+0

感謝我意識到錯誤 –

+0

高興你排序問題 –

+1

的一個問題,它打印出來(-1.4093883217883079,0.6741482698408712)的這些座標的地方應該打印51.51608899635712,0.09891956707558282,你知道我可能出錯了嗎? –