2016-09-25 46 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