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

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

问题描述

我有两个WGS84坐标,纬度和经度(以度为单位)。这些点相当接近,例如只有一米之遥。



有没有一种简单的方法来计算这些点之间的线的方位角,即与北方的角度?



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



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



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



随着坐标远离赤道,误差将更大,因为两个纵向度之间的距离变得越来越小比起两个纬度(保持不变)之间的一个。



我发现了一些非常复杂的公式,我不太希望实现,因为他们似乎是过度的那些靠近在一起的点,我不需要非常高的精度(两个小数就够了,一个可能很好,因为还有其他因素会降低精度否则就像GPS返回的那样)。



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



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



其中f是修正因子



任何提示?



(我不想使用任何库,特别是不需要运行时许可证的库。任何MPLed的Delphi源将是伟大的。)

解决方案

您在文中引用的公式是计算大圆距离在2点之间。以下是计算点之间的角度:

 使用数学,...; 
...

const
cNO_ANGLE = -999;

...

函数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; //两点相等

result:= RadToDeg(result);
结束




  • 记住处理2点相等的情况检查结果是否等于cNO_ANGLE,或修改该函数以引发异常);


  • 此功能假设您处于平坦的表面。随着你提到的小距离,这一切都很好,但是如果你要计算世界各地的城市之间的距离,你可能想要研究一些取决于地球形状的东西, p>


  • 最好为已经映射到平面的坐标提供此函数。您可以将WGS84 Latitude直接输入Y(并且进入X)以获得粗略的近似值。



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))

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).

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))

where f is the correction factor

Any hints?

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

解决方案

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;

  • 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;

  • 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天全站免登陆