2016-09-25 47 views
1

長座標我想顯示地圖使用經度/緯度座標從.csv文件中的城市。這些值必須被轉換成xy值,以便使用處理在屏幕上顯示。我的老師給了我這個代碼,但是對於我的座標,輸出的地圖旋轉了90度。旋轉LAT,已轉換爲像素

// 1. normalize the value between the minimum and maximum latitude or longitude values (new value between 0 and 1) 
// 2. blow up the value between 0 and 1 by muliplying by the width or height of the screen (reduced by the margin 2 * 20 pixel) 
// 3. shift the position by 20 pixel for the margin 
float xPosition = 20 + (width-40) * norm(l.longitude, minLongCoord, maxLongCoord); 
float yPosition = 20 + (height-40) * norm(l.latitude, minLatCoord, maxLatCoord); 

有誰知道如何旋轉xy位置90度,並依次從座標輸出的地圖嗎?

編輯:隨着翻譯的問題是,如果我有一個鼠標點擊功能看到鼠標是什麼形狀了,點擊什麼形狀的鼠標在不對齊。

回答

0

你可以只調用rotate()功能。從the reference

translate(width/2, height/2); 
rotate(PI/3.0); 
rect(-26, -26, 52, 52); 

rotated square

請注意,您還必須調用translate()函數來設置點進行圍繞其旋轉,然後繪製相對於這一點。

如果你不想使用rotate()函數,那麼你首先必須弄清楚什麼點要旋轉,然後繞着那個點旋轉。谷歌搜索「圍繞另一點旋轉一個點」返回一堆結果,包括這堆棧溢出帖子:Rotating a point about another point (2D)

+0

我試過,但問題是,地圖包含一堆較小的形狀。我正在使用beginShape()。這意味着每個單獨的形狀都會旋轉,而不是整個地圖。 – OptOut

+0

@OptOut您可以圍繞其中心旋轉每個形狀。或者你可以使用我提到的第二種方法。你也可以調用['PShape#rotate()'](https://processing.org/reference/PShape_rotate_.html)函數。 –

+0

@OptOut beginShape()只是意味着該指令畢竟改造將在endShape()被重置,所以你可以把之前的旋轉。 – Alex