在OpenGL中以正确的经度和纬度渲染地球上的点 [英] Rendering dots on a globe with correct longitude and latitude in OpenGL

查看:234
本文介绍了在OpenGL中以正确的经度和纬度渲染地球上的点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一天中的大部分时间里,我一直在挣扎着从经度和纬度数据中获取正确的输出.通过在Google地图中进行绘制,我知道此数据是正确的.例如,我将显示这些经纬度坐标的数据: 经度:4.905396 纬度:52.364643

在Google地图中绘制时,它显示了正确的位置,即荷兰的阿姆斯特丹:

现在,当我在应用程序中绘制它时,它看起来如下:

是的,谷歌地图是2D表示,我的是3D,但这只是为了证明经度和纬度值是正确的,因此,如果我将其转换为3D空间的公式是正确的,它们应该出现在同一位置. /p>

我已经阅读了很多Web文章以及stackoverflow本身. 我浏览了这些文章并应用了我所看到的所有不同类型的公式:

将纬度和经度转换为指向3D空间中的点

球体上的3D坐标到纬度和经度

这两个似乎已经清楚地说明了很好的例子,但似乎无济于事.我现在正在做的是计算3D空间中的位置,然后对其进行归一化,并将其用作绘制末端带点线的方向,如您在我的应用程序的屏幕截图中所见.使用大多数示例中使用的地球半径时,仅从中心到计算位置绘制一条线并没有什么不同.

我当前的公式是:

X = r * cos(latitude) * cos(lontitude);
Y = r * cos(latitude) * sin(longitude);
Z = r * sin(latitude);

我知道这是错的,但是我已经遍历了我在网络上看到的所有示例,但都没有显示正确的数据.通过使用来自Google地图的数据进行测试,我知道至少输入是正确的.

Update1:​​

我检查了我的纹理的拓扑,这是它的经度和纬度分别为0.0000和0.0000时发生的情况:

所以这意味着这已经是错误的了,但是它以奇数偏移量关闭了,如谷歌地图所示,它应该是这样的:

绿色箭头是0.0000、0.0000标记.因此,我的位置明显偏向侧面. 我认为它可能是(不希望如此),我正在使用这一纹理: http://naturalearth.springercarto.com/ne3_data/16200/textures/2_no_clouds_16k. jpg

我从以下国家/地区获得: Shadedrelief天然地球纹理

更新2: 我已经检查了具有纹理的球体的拓扑,似乎0.0和0.0都不可用,但是我也怀疑我的公式.我从网上尝试了许多不同的方法,其中一些方法的第一个公式得到的0.0 0.0相同,但很多都没有.我的经度和纬度分别是-180〜180和-90〜90.

更新3: 这是阿姆斯特丹地块的视图,它有点偏离,就像0.0 0.0纬度/经度的点.我猜在某个地方,地图或计算都错了.我将尝试调整纹理以使其稍微移位.

解决方案

您必须首先将弧度角设为弧度,而不是度数.

然后检查:哪个轴在上?您的公式与Z向上(北极)和X超出屏幕(您将地球旋转以查看0,0)一致

但是,将Y向上和Z向上显示在屏幕外的视图更为常见.

检查纹理坐标是如何生成的,以查看用于sin的轴.

I've been breaking my head the greater part of the day on getting correct output from longitude and latitude data. I know this data is correct by plotting it in google maps. For example I will show the data for these lat and long coordinates: Longitude: 4.905396 Latitude: 52.364643

When plotted in google maps it shows the correct location which is Amsterdam in The Netherlands:

Now when I plot this in my application it looks as follows:

And yes google maps is a 2D representation and mine is 3D but this was just to prove that the longitude and latitude values are correct so if my formula of converting them to 3D space is correct they should appear on the same spot.

I've been reading through a lot of articles on the web as well as stackoverflow itself. I've been through these articles and applied all of the different types of formula's I saw:

Convert Latitude and Longitude to point in 3D space

and

3D coordinates on a sphere to Latitude and Longitude

These two seemed to have the cleared explanation with good examples but nothing seems to work. What I am doing right now is calculating the position in 3D space and then normalizing it and using it as a direction to draw a line with a dot on the end as you can see in the screenshot of my application. This doesn't differ of just drawing a line from the center to the calculated position when using the radius of the earth which is used in most examples.

My current formula is:

X = r * cos(latitude) * cos(lontitude);
Y = r * cos(latitude) * sin(longitude);
Z = r * sin(latitude);

Which is wrong I know but Ive went through all the examples I saw on the web and none showed me correct data. By testing it with data from google maps I know that at least the input is correct.

Update1:

I checked the topology of my texture, this is what happens when its latitude and longitude are 0.0000 and 0.0000:

So this means that this is wrong already but its off with an odd offset, as google maps shows it it should be like this:

The green arrow is the 0.0000, 0.0000 mark. So mine is off that's obvious, its off to the side. I'm thinking it might ( dont think/hope so ) be the texture, I'm using this one: http://naturalearth.springercarto.com/ne3_data/16200/textures/2_no_clouds_16k.jpg

Which I obtained from: Shadedrelief Natural Earth textures

Update 2: I've checked the topology of my sphere with texture, it seems to be off for 0.0 and 0.0 but I'm also doubting my formula. I've tried a lot of different ones from the web and some of them get the same 0.0 0.0 as my first formula but a lot don't. My longitude and latitude are in degrees with the -180~180 and -90~90.

Update 3: This is the view of a plot on amsterdam, its off a little bit, just like the 0.0 0.0 lat/long piont. Somewhere either the map or calculations are wrong I guess. I'll try adapting the texture to be shifted a little bit.

解决方案

You must first have your angles in radians, not degrees.

Then check: which axis is up? Your formulas are consistent with Z being up (north pole) and X out of the screen (you have Earth rotated to see 0,0)

However it's more common to have a view rendered with Y up and Z out of the screen.

Check how the texture coordinates are generated to see which axis is used with sin.

这篇关于在OpenGL中以正确的经度和纬度渲染地球上的点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆