本文介绍了投影点到路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含点的有序阵列(纬度,经度)描述的路径,而我也有一点(纬度,经度) 描述我现在的位置。

Suppose I have an ordered array containing points (lat, lon) describing a path, and I also have a point (lat, lon) describing my current location.

我怎么能投影点到路径上(并放置在数组中的适当位置点)?

How can I project the point onto the path (and place the point in the appropriate place in the array)?

我试过只是简单地通过搜索最近的两个点,并假设它是在他们中间。这是一个很好的猜测,但有时会失败。

What I tried is just simply by searching for the nearest two points and assume it's in the middle of them. It's a good guess, but sometimes fails.

什么是这样做的一个很好的方式?

What would be a good way of doing this?

推荐答案

我认为是这样的:

  • P0,P1 的路径线段的端点
  • P 是你的立场
  • Q'在3D cartessian
  • 行最近点
  • Q'球形投影校正
  • p0,p1 are path line segment endpoints
  • p is your position
  • q' closest point on line in 3D cartessian
  • q is q' corrected by spherical projection

所以:

  1. 转换点的三维坐标cartessian
  2. 计算点和线的垂直距离

  • Q'= P0 +(点(P-P0,P1-P0)*(P1-P0)/(| P-P0 | * | P1-P0 |))
  • perpendicular_distance = | P-Q'|
  • q'=p0+(dot(p-p0,p1-p0)*(p1-p0)/(|p-p0|*|p1-p0|))
  • perpendicular_distance = |p-q'|

找到最小perpendicular_distance段

  • ,只将其用于其余的子弹

计算

compute q

  • 如果您使用的球,而不是椭球,那么你已经知道半径
  • 如果没有,那么无论是计算半径代数...
  • 或者使用平均 R = 0.5 *(| p0-(0,0,0)| + | P1-(0,0,0)|)假设(0,0,0)是地球的中心
  • 您也可以更precise如果你重量的位置
  • W = | Q'P0 | / | P1-P0 |
  • R =(1-W)* | p0-(0,0,0)| + W * | P1-(0,0,0)|
  • 现在,只需正确Q的位置
  • Q = Q'* R / | Q'| ...设置矢量 Q'为<$ C $ç>①与大小研究如果不是显而易见的
  • | p0-(0,0,0)| = | P0 | 很明显,但我想,以确保你我是如何得到它...
  • if you use sphere instead of ellipsoid then you already know the radius
  • if not then either compute the radius algebraically ...
  • or use average r=0.5*(|p0-(0,0,0)|+|p1-(0,0,0)|) assuming (0,0,0) is Earth's center
  • you can also be more precise if you weight by position
  • w=|q'-p0|/|p1-p0|
  • r=(1-w)*|p0-(0,0,0)|+w*|p1-(0,0,0)|
  • now just correct the position of q'
  • q=q'*r/|q'| ... set vector q' as q with size r if it is not obvious enough
  • also |p0-(0,0,0)|=|p0| obviously but I wanted to be sure you get how I get it ...

转换•从cartessian到球面坐标

[注意事项]

  • | A | 是向量的大小 A 喜欢做的: | A | =开方(斧* AX +唉* AY + AZ * AZ)
  • 点(A,B)是向量的点积 A,B 喜欢做的:点(A,B)=(AB)= AX * BX + AY *由+ AZ * BZ
  • 如果您的路径是不是太复杂形状的话,可以用二进制搜索找到最接近段
  • 的距离比较,你不需要开方...
  • |a| is size of vector a done like: |a|=sqrt(ax*ax+ay*ay+az*az)
  • dot(a,b) is dot product of vectors a,b done like: dot(a,b)=(a.b)=ax*bx+ay*by+az*bz
  • if your path is not too complex shaped then you can use binary search to find the closest segment
  • for distance comparison you do not need the sqrt ...

这篇关于投影点到路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 21:27