更新时间:2023-02-11 09:11:44
你在文中引用的公式是计算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.