gpt4 book ai didi

java - 查找从固定位置到两个 GPS 位置连接线的最近位置

转载 作者:行者123 更新时间:2023-12-01 04:19:51 24 4
gpt4 key购买 nike

我想找到从固定位置到由两个 GPS 位置连接的线的最近位置。我试图用图表的方式来说明它。所有位置均采用 GPS 坐标。我想找到从位置 P 到位置 A 和位置 B 连接的线的最短距离,即,从 P 开始的线与连接 A 和 B 的线成 90 度。如果您知道现有的实现或算法,那就太好了。非常感谢。 enter image description here

我被告知计算的方式是:首先将 GPS 位置转换为笛卡尔坐标。对于转换,它使用引用位置(Q_Ref_longitude、Q_Ref_latitude)。

x=(longitude-reflong)*π/180*r_e, r_e radius of earth
y=artanh(sin⁡(latitude))
Therefore the reference point has the Cartesian coordinates (0,artanh(sin⁡(reflat))).
conv(refp)=(0,artanh(sin⁡(reflat)))
All positions A,B, P are converted to (x,y) coordinate system
Calculation of the intercept point with reference Cartesian coordinates (x,y)∈R^2:
In the following context (vp) ⃗∈R^2 is the position vector of the P in reference Cartesian coordinates.
<a ⃗,b ⃗> is the dot product of two vectors a ⃗ and b ⃗.
(op2) ⃗ refers to position A
(op1) ⃗ refers to position B
(vp) ⃗ refers to position P
(op1) ⃗,(op2) ⃗,(vp) ⃗∈R^2

intPoint=[(<((op2)-(op1)),((vp)-(op1))>)/(<((op2)-(op1)),((op2)-(op1))>)]*((op2)-(op1))+(op1)

The intercept point has to be transformed back into GPS coordinates with the following inverse formula:

Iconv:R^2→[-180°,180°]×[-90°,90]
longitude=x+reflong
latitude=arcsin⁡(tanh⁡(y))

有人知道这个方法吗?我尝试这样做,但它给出了负值。

最佳答案

鉴于距离如此短,如果您不靠近极点,则可以使用基于规则平面几何的廉价近似值。

您要做的第一件事是更改坐标系:将经度乘以纬度的余弦,以考虑到两极附近的经度较短的事实。否则计算投影时将无法得到 90° 角。

之后,像平常一样计算点 P 在直线 AB 上的投影。

完成后,将经度除以纬度以撤消之前所做的坐标更改。

这是基本算法:

// input:
double Alat, Alng, Blat, Blng, Plat, Plng;
// output:
double Xlat, Xlng;

// change of coordinate system
Alng *= cos(Alat * PI/180);
Blng *= cos(Blat * PI/180);
Plng *= cos(Plat * PI/180);

// compute projection
double scale = ((Blng-Alng)*(Plng-Alng)+(Blat-Alat)*(Plat-Alat)) /
((Blng-Alng)*(Blng-Alng)+(Blat-Alat)*(Blat-Alat));

Xlat = (1-scale)*Alat + scale*Blat;
Xlng = (1-scale)*Alng + scale*Blng;

// change to original coordinate system
Xlng /= cos(Xlat * PI/180);

return (Xlat, Xlng)

您可以通过仅计算其中一个纬度的余弦来使其更便宜;没有什么大的区别。

如果您靠近杆子或出于某种原因需要更准确的结果,则必须使用更复杂的算法。

关于java - 查找从固定位置到两个 GPS 位置连接线的最近位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19046774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com