您如何找到两点之间的相对方位? [英] How do you find relative bearing between two points?

查看:304
本文介绍了您如何找到两点之间的相对方位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double computeHeading(double latitude1, double longitude1, double latitude2, double longitude2)
{
    double degToRad = PI / 180.0;
    double phi1 = latitude1*degToRad;
    double phi2 = latitude2*degToRad;
    double lam1 = longitude1*degToRad;
    double lam2 = longitude2*degToRad;

    double x,y;
    x = cos(phi2) * sin(lam2-lam1);
    printf("X is %lf\n", x);
    y = cos(phi1) * sin(phi2) - sin(phi1) * cos(phi2) * cos(lam2-lam1);
    printf("Y is %lf\n", y);
    return atan2(x,y)*180/PI;
}

我正在使用上述功能来确定两个地理坐标之间从北向的真实方位.

I am using the above function to determine the true bearing from North between two geographic coordinates.

我目前正在开发一个小型导航小部件,该小部件使用来自Android传感器的GPS数据.小部件的箭头指向远离设备当前位置的点.箭头的方向会随着设备的当前位置和方位角而变化,以始终面对着远处的点.

I'm currently developing a small navigation widget which uses GPS data from Android sensors. The widget has an arrow facing towards a point away from the device's current location. The arrow's direction changes with the device's current location and azimuth to always face the distant point.

这是一个场景:

我在一个位置,朝北,另一个位置的方位角为300度(在我的西北方向).如果我朝南而不动,那么与遥远位置的相对方位应该为120度.

I'm at a location, facing north, and another location has a bearing of 300 degrees(somewhat northwest of me). If I face towards south, without moving, my relative bearing to the distant location should be 120 degrees.

如何找到考虑到朝向(方位角)的相对方位?

How can I find the relative bearing with accounting for the facing direction (azimuth)?

推荐答案

有两种方法可以解决此问题.第一个,即您似乎正在做的,假设地球是球形的.相对轴承是使用Haversine公式计算的,用于大圆导航.在给定起点和终点的情况下,此公式找到了穿过这两个点的大圆.由此可以计算出初始方位.该大圆弧路线是两点之间的最短路线,但存在这样的问题,轴承通常不会沿该路线保持恒定.另外,除了在某些非常特殊的情况下之外,反向轴承的运行不像您预期​​的那样,并且如果要总体上确定反向轴承的位置,则必须执行另一次计算以反转起点和终点.

There are a couple of ways you can work this out. The first, which is what you appear to be doing, assumes the earth is spherical. Relative bearings are calculated using Haversine formulation for great circle navigation. Given starting and ending points, this formulation finds the great circle passing through the two points. From this an initial bearing can be calculated. This great circle route is the shortest route between the two points, but suffers from the problem the bearing, in general, will not be constant along the route. Also, except under some very specific cases, the reverse bearing does not behave as you seem to expect and if you want to determine it in general, you will have to perform another calculation reversing the starting and ending points.

您可以使用的另一种方法是Rhumb线配方.在这种情况下,起点和终点之间的方位角是恒定的,如果需要,您可以使用反向关系所具有的关系.由于这通常与大圆距不同,因此沿Rhumb线不会导致两点之间的路径最短,但是通过保持航向不变,确实可以简化导航.

Another method you could use is the Rhumb line formulation. In this case, the bearing between the starting point and ending point is constant and would allow you to use the relation you have for the reverse course if you would like. Since this will in general differ from the great circle distance, following Rhumb lines will not result in the shortest path between the two points, but it does simplify the navigation by holding the course constant.

计算距离,方位及其他之间的距离时,将详细介绍这两种方法纬度/经度点

另一种用于大圆弧导航的公式,它使用更精确的地球形状表示法,扁圆球体是椭圆的一种特殊类型,归因于

Another formulation for great circle navigation which uses a more accurate representation of the earth's shape, an oblate spheriod, which is a special type of ellipsoid, is attributed to Vincenty with additional enhancements provided by Karney. In these cases, the formulation is quite a bit more complicated and is probably overkill for most applications, and performance is quite a bit worse than the Haversine formulations above. But these formulations provide much better accuracy if you need it.

更新:

基于以下评论,主要问题是弄清楚要走多远的问题之一.这将简单地是包含当前航向的大圆的平面法线与所需航向之间的角度.要在当前航向上获取平面的法线,您需要当前位置L,并在当前航向C上有一段距离.正常值只是V = L×C.要计算包含沿所需航向的大圆圈的平面的法线,只需知道沿所需路线的一个点,该点已经以目标点的形式存在,我们称之为D.然后可以通过U = L×D查找法线.它们之间的角度由θ = acos((U∙V)/(|U||V|))给出.

Based on the comment below, the main issue is one of figuring out how far to turn. This will simply be the angle between the normals of the plane containing the great circles for the current heading and the desired heading. To get the normal for the plane on the current heading, you need your current location L and a point some distance away on the current heading, C. The normal is just V = L×C. To compute the normal for the plane containing the great circle along the desired heading, you only need to know a point along the desired route, which you already have in the form of your destination point, which we call D. You can then find the normal by U = L×D. The angle between them is given by θ = acos((U∙V)/(|U||V|)).

为了找到LCD,您必须转换将纬度,经度,海拔(LLA)"坐标转换为以地球为中心",经地球固定"(ECEF)坐标.

In order to find L, C and D you must convert the Latitude, Longitude, Altitude (LLA) coordinates into Earth Centered, Earth Fixed (ECEF) coordinates.

这篇关于您如何找到两点之间的相对方位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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