2014-01-10 46 views
1

我需要實現從具有高數據的地理座標到圖像的轉換。圓柱投影 - 如何從tangens(緯度)獲取y圖像座標

http://mathworld.wolfram.com/CylindricalProjection.html中所述。

我根本不知道如何創造合適的y值...

例如:

double longitude = -180; // (λ) 
    double latitude = 80; // (φ) 
    int mapHeight = 360; 
    int mapWidth = 720; 
    x = (int)((longitude+180.0)*(mapWidth/360.0)); 

如何使用

Math.tan(Math.toRadians(latitude)) 

感謝結果您!

回答

0

您無法使用圓柱投影來表示極點。所以你需要設置一個最大的緯度並存儲它(比如double maxlat=3.1415/2.0)。爲了得到y,首先,測試,如果一點都不到接近極點,然後計算:

y=(int)(mapHeight/2+mapHeight/2*Math.tan(Math.toRadians(latitude)) /Math.tan(Math.toRadians(maxlat))) ; 

如果你正在尋找一個美麗的地圖,可以考慮使用墨卡託投影:

y=(int)(mapHeight/2+mapHeight/2*Math.log(Math.tan(Math.toRadians(latitude)/2.0+M_PI/4.0)) /Math.log(Math.tan(Math.toRadians(maxlat)/2.0+M_PI/4.0))) ; 

商店Math.tan(Math.toRadians(maxlat))math.log(Math.tan(Math.toRadians(maxlat)/2.0+M_PI/4.0))如果您需要計算多點

+0

非常感謝您的快速和有益的答案! /Math.tan(Math.toRadians(maxlat))是我缺失的部分。 我知道墨卡託是一個比標準圓柱體更好的地圖投影,我已經有了它的實現(我必須實現3個不同的投影)。 – user3183556

相關問題