Click here to Skip to main content
11,637,415 members (66,079 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ImageProcessing
i wrote that code to calculate the distance between two point any one can gime a tip how to get the minimun distance between these point -not the max - ^^

thanks a lot

int distanceX;
                   int distanceY;
 
                   int index = 0;
                   int max_index = 0;
                   int shortd=0;
 
                   double total_distance;
                   double max_distance = 0;
 
                   List<PointPixel> ppList1 = new List<PointPixel>();
                   List<PointPixel> ppList2 = new List<PointPixel>();

ppList1.Insert(index, getPointPixel(plist, h));
                               ppList2.Insert(index, getPointPixel(plist, g));
 
                               distanceX = ppList1.ElementAt(index).getX() - ppList2.ElementAt(index).getX();
                               distanceY = ppList1.ElementAt(index).getY() - ppList2.ElementAt(index).getY();
                               total_distance = Math.Pow((double)distanceX, 2) + Math.Pow((double)distanceY, 2);
                               total_distance = Math.Sqrt(total_distance);
                               total_distance = Math.Round(total_distance, 2);
 

                                   if (total_distance > max_distance)
                                   {
                                       max_distance = total_distance;
                                       max_index = index;
                                   }
 
                               index++;
Posted 19-Feb-13 11:35am
Comments
Zoltán Zörgő at 19-Feb-13 17:42pm
   
You need the minimum distance between the two point lists? Since there is only one distance between two singular points.
alexandrosok at 19-Feb-13 17:47pm
   
i use the lists to insert the pair inside like list1(x,y) compared with list2(x,y) i found the max distance but my brain i stuck and i want to find the minimum distance
Sergey Alexandrovich Kryukov at 19-Feb-13 18:08pm
   
There is no algorithmic difference between max and min... :-)
—SA
Sergey Alexandrovich Kryukov at 19-Feb-13 18:07pm
   
There is only one Cartesian distance between two points, no minimum, maximum or something else.
—SA

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the following feature: double.PositiveInfinity as a starting value, if you want to find minimum, and double.NegativeInfinity, if you want to find maximum:
http://msdn.microsoft.com/en-us/library/system.double.positiveinfinity.aspx[^],
http://msdn.microsoft.com/en-us/library/system.double.negativeinfinity.aspx[^].

Cycle through all possible pairs of point and find the distance between them, compare with current minimum and decrease the current minimum if the distance is smaller. The opposite with maximum. When iterations are done, your current minimum will be the answer. Same thing with maximum.

—SA
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 344
1 OriginalGriff 295
2 stibee 288
3 jyo.net 270
4 himanshu agarwal 209
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,763
2 Mika Wendelius 6,999
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320


Advertise | Privacy | Mobile
Web01 | 2.8.150728.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100