获得通过的具体位置和经度(机器人)的屏幕坐标经度、坐标、机器人、具体位置

2023-09-06 09:54:21 作者:问世间谁能敌我

我有增强现实中,我已存储的信息,我们的地铁,加油站,兴趣点等方面与相应的纬度和经度的应用程序。

I have an application of augmented reality in which I have stored information such us metro, gas stations, places of interest, etc. with the corresponding latitude and longitude.

现在,根据设备的方位,我会显示一个标记,以便在该装置的相机视图中的每个站点。类似拉亚和Wikitude。

Now, according to the orientation of the device, I would show a marker for each site in the camera view of the device. Similar to Layar and Wikitude.

这需要三天搜索不停止,并没有发现任何人解释如何解决这个问题。

It takes three days searching without stopping and have not found anyone to explain how to solve this problem.

推荐答案

由于有关此主题的信息非常稀少,而且最近我解决了这个问题在iPhone上,我想我会分享我的方法的人,可以使它发挥作用与Android(有没有什么具体到iPhone,除了在数学函数SIN,COS,和FMOD,可以在java.lang.Math中可以找到这个答案)。这是我采取的步骤:

Since information on this topic is very sparse, and I recently solved this problem on the iPhone, I thought I would share my method for anyone that can make it work with Android (there's nothing really specific to iPhone in this answer except for the Math functions sin, cos, and fmod, which can be found in java.lang.Math). These are the steps I took:

在获取自己的纬度/经度和您当前的罗盘航向(LAT1,lon1和航向)。在iPhone上,CLLocation度返回这些,但对于这些计算,他们的必须在弧度(即乘以PI / 180) 在获得兴趣点(POI)弧度的纬度/经度(LAT2和lon2)。 在使用计算LAT1 / lon1和LAT2 / lon2之间的距离公式在这里找到: http://www.movable-type.co.uk/scripts/latlong.html

计算角度LAT2 / lon2相对于北方。这是在上面的链接还描述,但我有麻烦这个工作一点点,这里是C $ C $下这样的: Obtain your own lat/lon and your current compass heading (lat1, lon1 and heading). On the iPhone, CLLocation returns these in degrees, but for these calculations they MUST be in radians (i.e. multiply by PI/180) Obtain lat/lon of Points of Interest (POI) in radians (lat2 and lon2). Calculate the distance between lat1/lon1 and lat2/lon2 using formula found here: http://www.movable-type.co.uk/scripts/latlong.html

Calculate angle to lat2/lon2 in relation to north. This is also described in the link above but I had a little bit of trouble getting this to work, here is C code for this:

双latDelta =(LAT2 - LAT1); 双lonDelta =(lon2 - lon1); 双Y = SIN(lonDelta)* COS(LAT2); 双X = COS(LAT1)*罪(LAT2) - 罪(LAT1)* COS(LAT2)* COS(lonDelta); 双角= ATAN2(Y,X); //这里没有说完呢 双headingDeg = compass.currentHeading; 双angleDeg =角度* 180 / PI; 双击标题= headingDeg * PI / 180; 角= FMOD(angleDeg + 360,360)* PI / 180; //归为0至360(而非-180到180),然后再转换回弧度 angleDeg =角度* 180 / PI;

double latDelta = (lat2 - lat1); double lonDelta = (lon2 - lon1); double y = sin(lonDelta) * cos(lat2); double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2)* cos(lonDelta); double angle = atan2(y, x); //not finished here yet double headingDeg = compass.currentHeading; double angleDeg = angle * 180/PI; double heading = headingDeg*PI/180; angle = fmod(angleDeg + 360, 360) * PI/180; //normalize to 0 to 360 (instead of -180 to 180), then convert back to radians angleDeg = angle * 180/PI;

使用标准的三角,我计算出x和y。请记住,这些坐标是在三维空间中,因此我们不会在这里说完呢,因为你还是将它们映射到2D:

Using standard trigonometry, I calculate x and y. Remember, these coordinates are in 3D space, so we are not finished here yet because you still have to map them to 2D:

X = SIN(角题)*距离; Z = COS(角题)*距离; //通常,Z面临到屏幕,但在我们的2D地图,它是一个y坐标,因为如果你正在寻找从底部向下世界,如谷歌地图

x = sin(angle-heading) * distance; z = cos(angle-heading) * distance; //typically, z faces into the screen, but in our 2D map, it is a y-coordinate, as if you are looking from the bottom down on the world, like Google Maps

最后,使用投影公式,可以计算出屏幕X(我没有做y方法,因为没有必要为我的项目,但你需要得到加速数据,并计算出该设备是否垂直到地面)。该投影式的发现这里(滚动至最底部): HTTP:/ /membres.multimania.fr/amy$c$crs/tutorials/3dbasics.html

Finally, using the projection formula, you can calculate screen x ( I didn't do y because it was not necessary for my project, but you would need to get accelerator data and figure out if the device is perpendicular to the ground). The projection formula is found here (scroll to the very bottom): http://membres.multimania.fr/amycoders/tutorials/3dbasics.html

双screenX =(X * 256)/ Z

现在你可以使用这个x坐标移动图像或屏幕上的标记。请记住几点:

Now you can use this x coordinate to move an image or a marker on your screen. Remember a few points:

在一切都必须是弧度 从您的POI相对于北方的角度angleBeteweenPoints - currentHeading

(出于某种原因,我不能正确格式化code这台计算机上,因此如果有人想编辑这个答案,随意)。

(For some reason I can't properly format the code on this computer, so if anyone wants to edit this answer, feel free).