I have an array of x and y values representing points on a grid.
the arrays are x[0...n] and y[0...n] where the user inputs the n and inputs all of the coordinates. So far I choose three points (point 0, point 1, ... point n) and store them in the array point [0...n].
But how would I go about finding the closest point to point[2] that is not point[0] or point [1]? I have tried using for loops but I am not exactly sure how to word this equation. Does anyone know how I would do this?
int find_closest_to=2;
int closest=-1
for (int i=0;i<n;i++){
if (!i || i==1 || i==find_closest_to)
continue;
if (closest<0 || /*distance to x[closest],y[closest]*/>/*distance to x[i],y[i]*/)
closest=i;
}
if (closest<0)
//not found
else
//closest point that isn't 0 or 1 is 'closest'