# Points form a line. How can I find the most distant points?

Hello experts!

I have set of points.
I know that they form a line.

I need to find two most distant points (start and end of line).

How can I do it?

Thank you

panJames
###### Who is Participating?

Commented:
If the line is vertical, the all x's are the same. So, if x_min = x_max, then start over and sort all the points by the key y.
0

Commented:
How about sorting the set of points, { (xi, yi) } by the key x.
The first point (x_min, y1) and the last point (x_max, y2) should be the two most distant points.

If the slope of the line is positive, then y1 should be y_min; otherwise y1 should be y_max.
0

Commented:
What do you know about the points?  Do you have their coordinates?
0

Commented:
The ends of the line segment must include the maximum and minimum values of
x and y.

If the line is vertical, the max and min values of x will be the same.

If the line is horizontal, the max and min values of y will be the same.

If the slope of the line is positive, the max and min values of x will be paired
with the max and min values of y respectively.

If the slope is negative, the max and min values of x will be paired
with the min and max values of y respectively.
0

Commented:
You don't have to sort, all you have to do is find the max and min.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.