Problem with Point Selection?

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?
Are you sure the arrays aren't [0..n-1]?

You mean something like this?
1
2
3
4
5
6
7
8
9
10
11
12
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' 
The distance between two points is the square root of (x1-x2)2 + (y1-y2)2
Incase you were wondering
Topic archived. No new replies allowed.