简体   繁体   English

计算被测点与目标线之间的距离

[英]Calculating the distance between measured points and target line

I have two kinds of geographical coordinates. 我有两种地理坐标。
One is target points and another is measured points by GPS. 一个是目标点,另一个是通过GPS测量的点。

I can draw line and points like the following image: 我可以画线和点,如下图所示:

sample image 样本图片

These black points are measured points and white points are target points. 这些黑点是测量点,白点是目标点。

So, I'd like to calculate the distance between the measured points and the line which is made by target points. 因此,我想计算被测点与目标点所形成的线之间的距离。 But importantly, the both points includes going backward points. 但重要的是,这两点都包括倒退点。 I mean that it'is like a returning path. 我的意思是,这就像一条返回之路。

I read this article -- Calculating the distance between a point and a virtual line of two lat/lngs but my coordinates includes so many points. 我读了这篇文章- 计算一个点与两条经度/纬度的虚拟线之间的距离,但是我的坐标包含了很多点。 And the interval of points is not fixed. 并且点的间隔不是固定的。

Therefor, I think that I should use for loop something like that. 因此,我认为我应该使用诸如此类的循环。 I'd like to know how far between points and line. 我想知道点和线之间的距离。

How can I calculate the distance? 如何计算距离?

Here is how I would structure my algorithm. 这就是我构造算法的方式。 I am assuming the target points and the measured points are 'linear' (that I don't go backwards at any point). 我假设目标点和被测点是“线性的”(我在任何时候都不会向后走)。

Step 1: Defining the virtual segments 步骤1:定义虚拟段

You know from Calculating the distance between a point and a virtual line of two lat/lngs how to determine the distance of a point from a virtual line. 通过计算一个点与两条经度/纬度的虚拟线之间的距离,您知道如何确定一个点与虚拟线的距离。 So you can think of your list of target points instead as a series of virtual lines. 因此,您可以将目标点列表视为一系列虚拟线。 Assuming your target points are provided in an array of x,y pairs targetCoords , if you have n = len(targetCoords) target points, then you will have n-1 virtual segments. 假设在x,y对targetCoords数组中提供目标点,如果您有n = len(targetCoords)目标点,则将有n-1虚拟段。

For each point in your target points, determine it's distance from the next target point. 对于目标点中的每个点,确定它与下一个目标点的距离。 You can do this with a simple list comprehension: 您可以通过简单的列表理解来做到这一点:

targetPointDistances = [(Dist(Coords2,Coords1) for Coords1, Coords2 in zip(targetCoords[:-1], targetCoords[1:])]

"Dist" is a user defined function to determine the distance between coordinate pairs. “距离”是用户定义的函数,用于确定坐标对之间的距离。 This question gives an example of how to easily implement this, while this question gives detail on the more precise Vincenty formula. 这个问题提供了一个如何轻松实现此示例的示例,而这个问题提供了有关更精确的Vincenty公式的详细信息。

Step 2: Determining the current virtual segment 步骤2:确定当前虚拟段

You want to start looking at each measured point, and comparing it's distance from a virtual segment. 您想开始查看每个测量点,然后比较它与虚拟线段的距离。 For each point, you want to check that you're still comparing it to the proper virtual segment. 对于每个点,您需要检查您是否仍在将其与正确的虚拟细分进行比较。

So, check that you're in the correct segment before doing each distance determination. 因此,在确定每个距离之前,请检查您是否在正确的段中。 Let's try this: 让我们尝试一下:

targetSegment = 0
for point in measuredPoints:
    while Dist(point, targetCoords[targetSegment+2]) < targetPointDistances[targetSegment+1]:
        targetSegment += 1

For each point, I'm checking to see if its distance from the end point of the next segment is less than the length of the current segment. 对于每个点,我正在检查它与下一个段的端点的距离是否小于当前段的长度。 If this is true, I start comparing it to the next virtual segment. 如果是这样,我开始将其与下一个虚拟段进行比较。 (Extra credit: are there any cases where this won't work, or would be suboptimal?) (额外的功劳:在任何情况下,这种方法行不通或不理想吗?)

In your example image, this leaves the first 4 measured points in the first segment. 在您的示例图像中,这将前四个测量点留在第一段中。 The fifth measured point is closer to the third target point than the second target point is to the third target point, so we advance to the next virtual segment. 第五个测量点比第二个目标点与第三个目标点更接近第三个目标点,因此我们前进到下一个虚拟线段。

Step 3: Calculate the distance from the virtual line 步骤3:计算与虚拟线的距离

This seems to be pretty straightforward - you already linked to this! 这似乎非常简单-您已经链接到此!

Just use targetCoords[targetSegment] and targetCoords[targetSegment+1] as the starting and ending points for your virtual line. 只需将targetCoords[targetSegment]targetCoords[targetSegment+1]用作虚拟线的起点和终点即可。 This can be part of the for loop in step 2! 这可以是步骤2中for循环的一部分!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM