简体   繁体   English

最远距离和两点之间的距离(以英里为单位)

[英]Farthest away and distance in miles between two points

I am using a .DAT file that contains 700 x and y coordinates with a name of the location, I know how to separate the x and the y for each of them, so at the moment each coordinate is separated. 我正在使用一个包含700 x和y坐标以及位置名称的.DAT文件,我知道如何分别将x和y分开,因此目前每个坐标都分开了。 So my main point is set up like USAcamp 50 50 and I need to find the farthest distance away from 50,50 inside my code with the name attached. 因此,我的要点是像USAcamp 50 50这样设置的,我需要在代码中附加名称的地方找到距离50,50最远的距离。 What is the best formula to use to find this? 找到这个的最佳公式是什么? I also need to find how many miles are between each point and 50,50. 我还需要找到每个点与50,50之间的距离。

Everything is seperated like this: 一切都是这样分开的:

string usaNames;
double x;
double y;

Thanks for any help, I can clarify on things if this is too confusing, I'm learning so everything helps. 感谢您的帮助,如果这太令人困惑,我可以澄清一些事情,我正在学习,所以一切都会有所帮助。

Shortest distance between two points is: 两点之间的最短距离是:

SQRT((x2-x1)^2 + (y2-y1)^2) SQRT((x2-x1)^ 2 +(y2-y1)^ 2)

Thus do this calculation for all sets of points and find the greatest distance. 因此,对所有点集进行此计算并找到最大距离。

As it related to C#, I would create a composite class around C#'s Point class and add the field for the name, then perform the nested for-loop to find the distances. 由于它与C#有关,因此我将围绕C#的Point类创建一个复合类,并添加名称字段,然后执行嵌套的for循环以查找距离。

double max = -1;
for(int i = 0; i<arr.length-1;i++){
    for(int j = i+1; j<arr.length; j++){
        // Calculate the distance and set the max if highest
    }
}

For more information look at this post: What is the most efficient way to calculate the maximum distance of two points in a list? 有关更多信息,请参见这篇文章: 计算列表中两点最大距离的最有效方法是什么?

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

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