I'm not sure if you`ve lost interest but what about this for a start:
Supposing you had 2 arrays int x[100] and int y [100] which held your sets of x and y coordinates. And suppose that int variables m and n were the 2 coordinates for which you wanted the closest match from x[i] and y[i].
You could compare the abs value of m with each element in x[ ] using a for loop
like for(int i =0;i<100;i++)
{ min=abs(m-x[i];
if(x[i]<min)min=x[i];} //if x[i]>min it would be ignored
min now holds the least difference between m and x[i] between i=0 and i=99.
If you traversed the x array again you could identify the element which held the value = m+ or - min and its i th position in the array. Repeat for y [] array and variable n.
If you could turn this dog`s breakfast into something vaguely representing an algorithm perhaps the code would follow.
Using 'abs' in the above is not required and prevents you from calculating the desired value of x[i] by simply adding min to m. This then avoids the need for a second traverse of the array.
Comment