经纬度点到小弧线段的距离 [英] Distance from Lat/Lng point to Minor Arc segment
问题描述
我需要计算从 lat/lng GPS 点 P 到由其他 2 个 lat/lng GPS 点 A 和 B 描述的线段的最短距离.
'Cross-track distance' 帮助我计算 P 与 A 和 B 描述的大圆之间的最短距离.
然而,这不是我想要的.我需要 P 和 A-B 的 segment 线之间的距离,而不是整个大圆.
我使用了
在第一张图片中,绿色线表示的跨轨道距离是正确的,并且确实是到线段 AB 的最短距离.
在第二张图片中显示了跨轨道距离的问题,在这种情况下,我希望最短距离是简单距离 AP,但跨轨道距离给了我由 红色 行.
如何更改我的算法以考虑到这一点,或检查点 X 是否在 AB 内.是否可以通过计算来做到这一点?还是迭代是唯一可能的(昂贵的)解决方案?(沿 AB 取 N 个点,计算 P 到所有这些点的最小距离)
为简单起见,图像中的所有线条都是直的.实际上,这些是大圆上的小弧
首先,一些命名法:
我们的弧是从 p1 到 p2 绘制的.
我们的第三点是p3.
与大圆相交的假想点是 p4.
p1 由 lat1,lon1 定义;p2 by lat2,lon2;等等
dis12 是 p1 到 p2 的距离;等等
Bear12 是从 p1 到 p2 的方位角;等等
dxt 是跨轨道距离.
dxa 是跨弧距离,我们的目标!
请注意,交叉轨道公式依赖于相对方位,bear13-bear12
我们有 3 个案例要处理.
案例1:相对方位为钝角.所以,dxa=dis13.
案例 2.1: 相对方位是尖锐的,并且 p4 落在我们的弧上.所以,dxa=dxt.
案例 2.2: 相对方位是尖锐的,并且 p4 超出了我们的弧线.所以,dxa=dis23
算法:
第1步:如果相对方位是钝角,dxa=dis13
完毕!
第 2 步: 如果相对方位很尖锐:
2.1: 查找 dxt.
2.3:找到dis12.
2.4:找到dis14.
2.4:如果dis14>dis12,dxa=dis23.
完毕!
2.5:如果我们到达这里,dxa=abs(dxt)
MATLAB 代码:
function [dxa] = crossarc(lat1,lon1,lat2,lon2,lat3,lon3)%//CROSSARC 以米为单位计算最短距离%//在圆弧(由 p1 和 p2 定义)和第三点 p3 之间.%//以度为单位输入 lat1,lon1,lat2,lon2,lat3,lon3.lat1=deg2rad(lat1);lat2=deg2rad(lat2);lat3=deg2rad(lat3);lon1=deg2rad(lon1);lon2=deg2rad(lon2);lon3=deg2rad(lon3);R=6371000;%//地球的半径,以米为单位%//公式的先决条件熊12 =熊(lat1,lon1,lat2,lon2);熊13 =熊(lat1,lon1,lat3,lon3);dis13 = dis(lat1,lon1,lat3,lon3);差异=绝对(bear13-bear12);如果差异 >圆周率差异 = 2 * pi - 差异;结尾%//相对方位是否钝?如果差异>(pi/2)dxa=dis13;别的%//求跨轨距离.dxt = asin( sin(dis13/R)* sin(bear13 - Bear12) ) * R;%//p4是否超出了圆弧?dis12 = dis(lat1,lon1,lat2,lon2);dis14 = acos( cos(dis13/R)/cos(dxt/R) ) * R;如果 dis14>dis12dxa=dis(lat2,lon2,lat3,lon3);别的dxa=abs(dxt);结尾结尾结尾函数 [ d ] = dis( latA, lonA, latB, lonB )%DIS 查找两个纬度/经度点之间的距离.R=6371000;d = acos( sin(latA)*sin(latB) + cos(latA)*cos(latB)*cos(lonB-lonA) ) * R;结尾函数 [ b ] = 熊( latA,lonA,latB,lonB )%BEAR 查找从一个纬度/经度点到另一个的方位角.b=atan2( sin(lonB-lonA)*cos(latB) , ...cos(latA)*sin(latB) - sin(latA)*cos(latB)*cos(lonB-lonA) );结尾
示例输出:展示所有案例.请参阅下面的地图.
>>十字弧(-10.1,-55.5,-15.2,-45.1,-10.5,-62.5)答案=7.6709e+05>>交叉弧(40.5,60.5,50.5,80.5,51,69)答案=4.7961e+05>>交叉弧(21.72,35.61,23.65,40.7,25,42)答案=1.9971e+05
地图上的相同输出!:
演示案例1:
演示案例 2.1:
演示案例 2.2:
归功于:http://www.movable-type.co.uk/scripts/latlong.html
对于公式
和:http://www.darrinward.com/lat-long/?id=1788764
用于生成地图图像.
I need to calculate the shortest distance from a lat/lng GPS point P to a line segment described by 2 other lat/lng GPS points A and B.
'Cross-track distance' helps me to calculate the shortest distance between P and the great circle described by A and B.
However, this is not what I want. I need need the distance between P and the line segment of A-B, not the entire great circle.
I have used the following implementation from http://www.movable-type.co.uk/scripts/latlong.html
Formula: dxt = asin( sin(δ13) ⋅ sin(θ13−θ12) ) ⋅ R
where:
δ13 is (angular) distance from start point to third point
θ13 is (initial) bearing from start point to third point
θ12 is (initial) bearing from start point to end point
R is the earth’s radius
The following images hopefully demonstrate the problem I am trying to solve:
In the first image the Cross-Track distance, indicated by the green line is correct and indeed the shortest distance to the line segment AB.
In the second image the problem with cross-track distance is shown, In this case I would want the shortest distance to be the simple distance AP, but Cross-Track distance gives me the distance indicated by the red line.
How do I change my algoritm to take this into account, or check whether or not point X is within AB. Is it possible to do this computationally? Or is iterative the only possible (expensive) solution? (take N points along AB and calculate the min distance from P to all these points)
For simplicity purposes all lines in the images are straight. In reality, these are minor arcs on a great circle
First, some nomenclature:
Our arc is drawn from p1 to p2.
Our third point is p3.
The imaginary point that intersects the great circle is p4.
p1 is defined by lat1,lon1; p2 by lat2,lon2; etc.
dis12 is the distance from p1 to p2; etc.
bear12 is the bearing from p1 to p2; etc.
dxt is cross-track distance.
dxa is cross-arc distance, our goal!
Notice that the cross-track formula relies on the relative bearing, bear13-bear12
We have 3 cases to deal with.
Case 1: The relative bearing is obtuse. So, dxa=dis13.
Case 2.1: The relative bearing is acute, AND p4 falls on our arc. So, dxa=dxt.
Case 2.2: The relative bearing is acute,AND p4 falls beyond our arc. So, dxa=dis23
The algorithm:
Step 1: If relative bearing is obtuse, dxa=dis13
Done!
Step 2: If relative bearing is acute:
2.1: Find dxt.
2.3: Find dis12.
2.4: Find dis14.
2.4: If dis14>dis12, dxa=dis23.
Done!
2.5: If we reach here, dxa=abs(dxt)
MATLAB code:
function [ dxa ] = crossarc( lat1,lon1,lat2,lon2,lat3,lon3 )
%// CROSSARC Calculates the shortest distance in meters
%// between an arc (defined by p1 and p2) and a third point, p3.
%// Input lat1,lon1,lat2,lon2,lat3,lon3 in degrees.
lat1=deg2rad(lat1); lat2=deg2rad(lat2); lat3=deg2rad(lat3);
lon1=deg2rad(lon1); lon2=deg2rad(lon2); lon3=deg2rad(lon3);
R=6371000; %// Earth's radius in meters
%// Prerequisites for the formulas
bear12 = bear(lat1,lon1,lat2,lon2);
bear13 = bear(lat1,lon1,lat3,lon3);
dis13 = dis(lat1,lon1,lat3,lon3);
diff = abs(bear13-bear12);
if diff > pi
diff = 2 * pi - diff;
end
%// Is relative bearing obtuse?
if diff>(pi/2)
dxa=dis13;
else
%// Find the cross-track distance.
dxt = asin( sin(dis13/R)* sin(bear13 - bear12) ) * R;
%// Is p4 beyond the arc?
dis12 = dis(lat1,lon1,lat2,lon2);
dis14 = acos( cos(dis13/R) / cos(dxt/R) ) * R;
if dis14>dis12
dxa=dis(lat2,lon2,lat3,lon3);
else
dxa=abs(dxt);
end
end
end
function [ d ] = dis( latA, lonA, latB, lonB )
%DIS Finds the distance between two lat/lon points.
R=6371000;
d = acos( sin(latA)*sin(latB) + cos(latA)*cos(latB)*cos(lonB-lonA) ) * R;
end
function [ b ] = bear( latA,lonA,latB,lonB )
%BEAR Finds the bearing from one lat/lon point to another.
b=atan2( sin(lonB-lonA)*cos(latB) , ...
cos(latA)*sin(latB) - sin(latA)*cos(latB)*cos(lonB-lonA) );
end
Sample outputs: Demonstrate all cases. See maps below.
>> crossarc(-10.1,-55.5,-15.2,-45.1,-10.5,-62.5)
ans =
7.6709e+05
>> crossarc(40.5,60.5,50.5,80.5,51,69)
ans =
4.7961e+05
>> crossarc(21.72,35.61,23.65,40.7,25,42)
ans =
1.9971e+05
Those same outputs on the map!:
Demonstrates case 1:
Demonstrates case 2.1:
Demonstrates case 2.2:
Credit to: http://www.movable-type.co.uk/scripts/latlong.html
for the formulas
and: http://www.darrinward.com/lat-long/?id=1788764
for generating the map images.
这篇关于经纬度点到小弧线段的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!