
How can we sort the points in c #? There is no single way of ordering the points, it all depends on the value we are looking at: X or Y. respective classification X values to sort an array of points from left to right (or vice versa). Also order values and sorts the points from top to bottom. This is useful when the application of advanced processing algorithms for a list of points. An example is agorithms image distortion in an ordered list of the curves is crucial.
To sort the items, we will create a class that inherits from the IComparer interface. The main meat of the function will be the comparison function that, depending on whether To order from left to right or up and down, compare the X or Y values of the points. The actual sorting algorithm is handled by the. Net Framework, all we need Compare function to do what it does is establish a point greater than, less than or equal to a second point.
This is the header of the function:
int IComparer.Compare (object to object, b)
Note that the parameter types are object, this is so. Net Framework can call the function later. Thus objects must be converted to points before doing anything. Just use (point) and a (point) b.
Observe how the function Compare returns an int, int has to be one of three values:
0 – The two objects are equal
1 – The first object is greater than the second object
-1 – The first object is less than the second object
Then call the current selection is quite simple:
Array.Sort (pointArray, new PointSort (PointSort.Mode.X));
Since the current classification is done by. Net Framework, the process has been optimized to run at a decent speed. I detail that does not include the class is PointSort need to know what the value (X or Y) to order, that's what's for PointSort.Mode. To see how this all comes together, rel = "nofollow" href = "http://vckicks.110mb.com/sort_points.html"> download the project files.
http://vckicks.110mb.com/csharp_resources.html
http://www.codeproject.com/KB/cs/GenericComparer.aspx
Using Web Services with MATLAB