I need to sort a list of points by distance.
So for e.g.
input : [[1,2],[5,10],[2,4]...]
output : [[1,2],[2,4],[5,10]...]
(assuming that geometrically [1,2] and [2,4] are nearest & [2,4] & [5,10] are nearest.
I need them to sort it so they are ordered by distance i.e. on the geometrical graph, point a is nearest to point b , point b is nearest to c and so on.
Any idea?
Edit: Code example
public class Point
{
public double X {get;set;}
public double Y {get;set;}
}
List<Point> points = new List<Point>();
let say my points list is getting populated in random order (not by geometrical distance). So points would look something like...
point ~ [[1,2],[5,10],[2,4]...]
Now my charting control just take the first & second point and draw a line between them. Which means it does not care which geometrical order is it in. If I simply supply the "points" list as above its going to draw lines between each points and from charting point of view it would not look correct as they would be "zig-zag".
To make sure the charting control draws a straight line (& and not zig-zag) I have to pass the points in the right order which would look something like ...
destination points ~ [[1,2],[2,4],[5,10]...]
So my question is how to achieve this.
Note: Changing chart control is not an option here.
Thanks