1

我想找到从固定位置到由两个 GPS 位置连接的线的最近位置。我试图用图表来说明它。所有位置都在 GPS 坐标中。我想找到从位置 P 到从位置 A 和位置 B 连接的线的最短距离,即 P 的线在连接 A 和 B 的线上形成 90 度。如果你知道现有的实现或相同的算法。非常感谢。 在此处输入图像描述

我被告知计算的方式是:首先将 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 ⃗&gt; 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))

有人知道这种方式吗?我试图这样做,但它给出了负值。

4

1 回答 1

0

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

您必须做的第一件事是改变坐标系:将经度乘以纬度的余弦,以说明在两极附近经度更短的事实。否则在计算投影时您不会得到 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)

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

如果您在极点附近或出于任何原因需要更准确的结果,则必须使用更复杂的算法。

于 2013-09-27T10:51:31.797 回答