如何计算两个 WGS84 坐标之间的方位角(向北的角度) [英] How do I calculate the Azimuth (angle to north) between two WGS84 coordinates

查看:80
本文介绍了如何计算两个 WGS84 坐标之间的方位角(向北的角度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 WGS84 坐标,以度为单位的纬度和经度.这些点相当接近,例如相距仅一米.

I have got two WGS84 coordinates, latitude and longitude in degrees. These points are rather close together, e.g. only one metre apart.

有没有简单的方法可以计算出这些点之间连线的方位角,也就是向北的角度?

Is there an easy way to calculate the azimuth of the line between these points, that is, the angle to north?

天真的方法是假设一个笛卡尔坐标系(因为这些点非常靠近)然后使用

The naive approach would be to assume a Cartesian coordinate system (because these points are so close together) and just use

sin(a) = abs(L2-L1)/sqrt(sqr(L2-L1) + sqr(B2-B1))

sin(a) = abs(L2-L1) / sqrt(sqr(L2-L1) + sqr(B2-B1))

a = 方位角L1, L2 = 经度B1, B2 = 纬度

a = azimuth L1, L2 = longitude B1, B2 = latitude

随着坐标远离赤道,误差会更大,因为两个经度之间的距离变得越来越小于两个纬度之间的距离(保持不变).

The error will be larger as the coordinates move away from the equator because there the distance between two longitudinal degrees becomes increasingly smaller than the one between two latitudinal degrees (which remains constant).

我发现了一些非常复杂的公式,我真的不想实现它们,因为它们对于那些靠得很近的点来说似乎有点矫枉过正,我不需要非常高的精度(两位小数就足够了,一个可能就可以了要么因为还有其他因素会降低精度,比如 GPS 返回的那个).

I found some quite complex formulas which I don't really want to implement because they seem to be overkill for points that are that close together and I don't need very high precision (two decimals are enough, one is probably fine either since there are other factors that reduce precision anyway, like the one the GPS returns).

也许我可以根据纬度确定一个近似的纵向校正因子,然后使用这样的东西:

Maybe I could just determine an approximate longitudinal correction factor depending on latitude and use somthing like this:

sin(a) = abs(L2*f-L1*f)/sqrt(sqr(L2*f-L1*f) + sqr(B2-B1))

sin(a) = abs(L2*f-L1*f) / sqrt(sqr(L2*f-L1*f) + sqr(B2-B1))

其中 f 是校正因子

有什么提示吗?

(我不想为此使用任何库,尤其是那些需要运行时许可证的库.任何 MPLed Delphi 源都很棒.)

(I don't want to use any libraries for this, especially not ones that require runtime licenses. Any MPLed Delphi Source would be great.)

推荐答案

你在文中引用的公式是计算2点之间的大圆距离.以下是我计算点之间角度的方法:

The formulas that you refer to in the text are to calculate the great circle distance between 2 points. Here's how I calculate the angle between points:

uses Math, ...;
...

const
  cNO_ANGLE=-999;

...

function getAngleBetweenPoints(X1,Y1,X2,Y2:double):double;
var
  dx,dy:double;
begin
  dx := X2 - X1;
  dy := Y2 - Y1;

  if (dx > 0) then  result := (Pi*0.5) - ArcTan(dy/dx)   else
  if (dx < 0) then  result := (Pi*1.5) - ArcTan(dy/dx)   else
  if (dy > 0) then  result := 0                          else
  if (dy < 0) then  result := Pi                         else
                    result := cNO_ANGLE; // the 2 points are equal

  result := RadToDeg(result);
end;

  • 记得处理2点相等的情况(检查结果是否等于cNO_ANGLE,或者修改函数抛出异常);

    • Remember to handle the situation where 2 points are equal (check if the result equals cNO_ANGLE, or modify the function to throw an exception);

      此功能假定您在平坦的表面上.你提到的距离很短,这一切都很好,但如果你要计算世界各地城市之间的航向,你可能想研究一下地球形状的东西;

      This function assumes that you're on a flat surface. With the small distances that you've mentioned this is all fine, but if you're going to be calculating the heading between cities all over the world you might want to look into something that takes the shape of the earth in count;

      最好为这个函数提供已经映射到平面的坐标.不过,您可以将 WGS84 Latitude 直接输入 Y(并将 lon 输入 X)以获得粗略的近似值.

      It's best to provide this function with coordinates that are already mapped to a flat surface. You could feed WGS84 Latitude directly into Y (and lon into X) to get a rough approximation though.

      这篇关于如何计算两个 WGS84 坐标之间的方位角(向北的角度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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