2016-01-20 266 views
0

我使用此代碼將lonlat轉換爲x,y,z,但無法弄清楚如何做相反的事情。將lonlat轉換爲xyz,反之亦然

var phi = (this.lat)*Math.PI/180; 
var theta = (this.lon-180)*Math.PI/180; 

x = -(this.R) * Math.cos(phi) * Math.cos(theta); 
y = -(this.R) * Math.sin(phi); 
z = (this.R) * Math.cos(phi) * Math.sin(theta); 

現在從X,Y轉換,Z向lonlat

lat = THREE.Math.radToDeg(Math.asin(rotation.y/this.R)); 
lon = THREE.Math.radToDeg(Math.atan2(rotation.z, rotation.x)); 

但是,這並不正常工作,我究竟做錯了什麼?

回答

0

好了,你的arent從XYZ轉換爲緯度經度,你正在嘗試做一些與歐拉角:

嘗試這樣的事情

lon = Math.atan2(x , z); //horizontal angle, just two components 
lon = Math.atan2(Math.sqrt(x*x,z*z) , y); //vertical angle, length of the diagonal between xz components and y component 
+0

我用這個爲XYZ座標平移旋轉,然後使用我以前的公式來獲得lonlat var xyz = new THREE.Vector3(0,0,0); this.camera.getWorldDirection(xyz);' 但是,感謝您的幫助! – Noripsni

相關問題