c#我想计算两点之间的较低距离 [英] c# i want to calculate the lower distance between two points

查看:247
本文介绍了c#我想计算两点之间的较低距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了那个代码来计算两点之间的距离任何人都可以给这个点之间的最小距离 - 不是最大值 - ^^



非常感谢



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++;

推荐答案

使用以下功能: double.PositiveInfinity 作为起始值,如果你想找到最小值, double.NegativeInfinity ,如果你想找到最大值:

http://msdn.microsoft.com/en-us/library /system.double.positiveinfinity.aspx [ ^ ],

http ://msdn.microsoft.com/en-us/library/system.double.negativeinfinity.aspx [ ^ ]。



循环通过所有可能的pa当点距离并找到它们之间的距离时,与当前最小值进行比较,如果距离较小则减小当前最小值。与最大值相反。迭代完成后,您当前的最小值将是答案。最大值相同。



-SA
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


这篇关于c#我想计算两点之间的较低距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆