2017-01-10 96 views
0

我有一個圖像的equirectangular投影,我將其作爲一個全景圖像載入,我的相機放置在原點處看着-z。我的座標系是右手的,即x在右邊,y在上(北),z從屏幕出來。將經緯度轉換爲opengl中的世界座標右手

我想要做的就是選取像素並將其轉換爲世界座標xyz。

,我使用來獲得緯度和經度的公式是:

double centerX = totalWidth/2; 
double centerY = totalHeight/2; 

double latScaling = centerY/90; 
double lonScaling = centerX/180; 


double longitude = (pixelX-centerX)/lonScaling; 
double latitude = -(pixelY-centerY)/latScaling; 

totalWidth和totalHeight是等距離長方圓柱圖像的寬度和高度以及pixelX和pixelY是所選擇的像素的座標。

而且我使用這些經/緯來獲得世界座標爲:

double x = sphereRadius * Math.sin(latRadians) * Math.sin(longRadians); 
double y = sphereRadius * Math.cos(latRadians); 
double z = sphereRadius * Math.cos(longRadians) * Math.sin(latRadians); 

sphereRadius是18等於該圖像是最後繪製的OpenGL球體的半徑。相機在這個球體的起源。 請有人檢查我的方法是否正確,以及如果使用的公式適用於右手座標系統。

對於緯度= 0和經度= 0,使用上述公式得到x = 0,y = 18,z = 0,這不是預期的結果。我錯過了什麼嗎?

編輯:這似乎是爲我工作的公式爲:

//翻轉Y軸 latRadians = Math.PI/2 - latRadians;

double x = sphereRadius * Math.sin(latRadians) * Math.sin(longRadians); 
    double y = -sphereRadius * Math.cos(latRadians); 
    double z = -sphereRadius * Math.sin(latRadians) * Math.cos(longRadians); 

但還是有一些偏移(約850像素)和偏差最小的赤道和本初子午線,因爲它包含了真實比例值。我想我需要通過相機的向上和向量之間的角度來計算偏移量。有人能糾正我嗎?

有一個扁平的equirectangular投影,我把像素xy的位置。然後這個equirectangular包裹在球體的內部,我的相機在這個球體的原點。我需要計算像素xy的世界座標。希望澄清一些疑問。

+1

交換sin(lat)和cos(lat) '。 –

+0

根據您的評論我的新公式是: double x = sphereRadius * Math.cos(latRadians)* Math.sin(longRadians); double y = sphereRadius * Math.cos(latRadians); double z = sphereRadius * Math.cos(longRadians)* Math.cos(latRadians); 新值是x = 0,y = 18,z = 18但偏移仍然存在,我的經度從西到東-180到180,緯度從南到北-90到90。 –

回答

0

我的方法有點不對。我不必搜索緯度經度映射,而必須計算紋理的UV映射。 UV貼圖與經緯度貼圖略有不同。 UV映射不在-PI和PI之間,而是在0.0-1.0之間。紋理被劃分成扇形和環形。你可以找到邏輯生成一個球體here

這是我解決了這個問題:

產生從像素

double u = pixelX/totalWidth; 
double v = 1 - pixelY/totalHeight; 

的xy位置的UV貼圖並用以下公式來轉換到XYZ球體的座標

double theta = 2 * Math.PI * u; //sector 
double phi = Math.PI * v; //ring 

double x = Math.cos(theta) * Math.sin(phi) * sphereRadius; 
double y = -Math.sin(-Math.PI/2 + phi) * sphereRadius; 
double z = Math.sin(theta) * Math.sin(phi) * sphereRadius; 

該球具有在y軸上的磁極北方上+ VE對-ve y,其中相機處於或y和南部這個球體的igin具有上矢量0,1,0和右矢量1,0,0並且用0,0看,

相關問題