2015-02-06 18 views
3

i'm與three.js所JavaScript的經緯度爲XYZ地球上(threejs)

我想呈現對一個更大的領域特定的地理座標的對象,i'm相當接近的解決方案角落找尋玩,但位置我不明白,從緯度經度正確的XYZ位置

我已成立上的jsfiddle測試的情況下,有兩個座標

latlons = [[40.7142700,-74.0059700], [52.5243700,13.4105300]]; 

其紐約和柏林

這是我的函數從緯度經度和半徑

function calcPosFromLatLonRad(lat,lon,radius){ 

// Attempt1 
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 = radius; 
y = rad * cosLat * sinLon; 
x = rad * cosLat * cosLon; 
z = rad * sinLat; 

// Attempt2 
// x = radius * Math.sin(lat) * Math.cos(lon) 
// y = radius * Math.sin(lat) * Math.sin(lon) 
// z = radius * Math.cos(lat) 


// Attempt3 
// latitude = lat * Math.PI/180 
// longitude = lon * Math.PI/180 
// x = -radius * Math.cos(latitude) * Math.cos(longitude) 
// y = radius * Math.sin(latitude) 
// z = radius * Math.cos(latitude) * Math.sin(longitude) 


// Attempt4 
// var phi = (90-lat)*(Math.PI/180); 
// var theta = (lng+180)*(Math.PI/180); 
// x = ((rad) * Math.sin(phi)*Math.cos(theta)); 
// z = ((rad) * Math.sin(phi)*Math.sin(theta)); 
// y = ((rad) * Math.cos(phi)); 



    console.log([x,y,z]); 
    return [x,y,z]; 
} 

calc下XYZ但所有的嘗試都返回不同的XY,而且都是不正確(z是總是正確的)。

有人請求指導我以正確的方式嗎? 我不知道什麼可能是錯誤的

繼承人的小提琴與

UPDATE: working jsfiddle

+0

HMN爲什麼我唯一的傢伙在看這個? – 2015-02-06 13:44:05

+0

你超前你的時間:) – coblr 2016-05-09 01:47:40

回答

8

不幸的是我不能進一步解釋上場,但圍繞這一上場後就像一個迷人:)

function calcPosFromLatLonRad(lat,lon,radius){ 

    var phi = (90-lat)*(Math.PI/180) 
    var theta = (lon+180)*(Math.PI/180) 

    x = -((radius) * Math.sin(phi)*Math.cos(theta)) 
    z = ((radius) * Math.sin(phi)*Math.sin(theta)) 
    y = ((radius) * Math.cos(phi)) 

    return [x,y,z] 

} 

是的,這是非常酷的不是嗎? 而i'm仍然有興趣到一些短式

working fiddle

+0

你還有這個地方的工作版本?檢查小提琴,但它看起來像three.js沒有加載。我想做同樣的事情。 – Brian 2017-05-20 05:18:29

+0

查看我添加到此答案的鏈接,它在這裏工作! – 2017-05-20 09:26:50

+0

沒有半徑的公式嗎?謝謝。 – hamzox 2017-10-31 10:45:48