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. 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. 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.
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)
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.
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?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.