我正在使用包含700 x和y坐标以及位置名称的.DAT文件,我知道如何为每个坐标分隔x和y,所以此时每个坐标都是分开的。所以我的主要观点是设置为 USAcamp 50 50 ,我需要在我的代码中找到距离50,50的最远距离,并附上名称。找到这个的最佳公式是什么?我还需要找出每个点与50,50之间有多少英里。
一切都像这样分开:
string usaNames;
double x;
double y;
感谢您的帮助,我可以澄清一些事情,如果这太混乱了,我正在学习,所以一切都有帮助。
答案 0 :(得分:1)
两点之间的最短距离是:
SQRT((x2-x1)^ 2 +(y2-y1)^ 2)
这样对所有点集进行计算并找到最大距离。
由于它与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
}
}
有关更多信息,请查看以下帖子:What is the most efficient way to calculate the maximum distance of two points in a list?