2012-01-24 27 views
9
var phi = (90-lat)*(Math.PI/180); 
var theta = (lng+180)*(Math.PI/180); 

marker_mesh.position.x = ((rad) * Math.sin(phi)*Math.cos(theta)); 
marker_mesh.position.z = ((rad) * Math.sin(phi)*Math.sin(theta)); 
marker_mesh.position.y = ((rad) * Math.cos(phi)); 

鑑於上述我的標記沒有翻譯成3D球體上的正確位置......思考?Lat長到X Y Z在JS ..的位置不工作

這是比較接近(在同一大洲),但接近:41.7307619 :\下面給出

...它應該在

LAT被渲染-71.276195

我的地球有boundRadius:500px的

的FUNC當前結果和灰是

X: -119.7801015013779

Y: 332.8157297895266

Z: 353.3927238766871

enter image description here

回答

16

你式從測地稍有不同,以ECEF計算。請參閱數學博士Latitude and Longitude, GPS Conversion和維基百科Geodetic to/from ECEF coordinates上的公式。這將緯度,經度投影到一個扁平的球體(即真實的地球不是完全球形的)。

var cosLat = Math.cos(lat * Math.PI/180.0); 
var sinLat = Math.sin(lat * Math.PI/180.0); 
var cosLon = Math.cos(lon * Math.PI/180.0); 
var sinLon = Math.sin(lon * Math.PI/180.0); 
var rad = 6378137.0; 
var f = 1.0/298.257224; 
var C = 1.0/Math.sqrt(cosLat * cosLat + (1 - f) * (1 - f) * sinLat * sinLat); 
var S = (1.0 - f) * (1.0 - f) * C; 
var h = 0.0; 
marker_mesh.position.x = (rad * C + h) * cosLat * cosLon; 
marker_mesh.position.y = (rad * C + h) * cosLat * sinLon; 
marker_mesh.position.z = (rad * S + h) * sinLat; 

在您的方案,因爲它似乎你開槍爲一個完美的球體,你將需要把F = 0.0,弧度= 500.0代替。這將導致C和S變爲1.0,因此,公式的簡化版本縮減爲:

var cosLat = Math.cos(lat * Math.PI/180.0); 
var sinLat = Math.sin(lat * Math.PI/180.0); 
var cosLon = Math.cos(lon * Math.PI/180.0); 
var sinLon = Math.sin(lon * Math.PI/180.0); 
var rad = 500.0; 
marker_mesh.position.x = rad * cosLat * cosLon; 
marker_mesh.position.y = rad * cosLat * sinLon; 
marker_mesh.position.z = rad * sinLat; 

N.B.我沒有驗證Java代碼示例的語法。

+0

親愛的寶貝耶穌我需要更好的數學才能閱讀這個 – samccone

+0

無論如何要幫我一下嗎? – samccone

+0

@samccone按要求,爲您提供了兩個Java片段。最簡單的一個可能更符合你的喜好。 –

相關問題