private void Cal(System.Drawing .Point [] pt)
{
double max=0.00,min=0.00;
int maxIdex=0,minIndex=0;
System.Collections .Hashtable linePoint=new Hashtable ();//點集
System.Collections .Hashtable kPoint=new Hashtable ();//斜率
int i=0;
foreach(Point tempt in pt)
{
linePoint[i]=tempt;
i++;
}
/////////////計算斜率
while (i> 0)
{
Point tempt1=(Point)linePoint[i-1];
Point tempt2=(Point)linePoint[i];
kPoint[i]=(double)(tempt2.Y -tempt1.Y )/(tempt2.X -tempt1.X);
}
////////////找出斜率最大和最小的值
foreach(DictionaryEntry item in kPoint)
{
if(max <(double)item.Value )
{
max=(double)item.Value ;
maxIdex=(int)item.Key;
}
if(min> (double)item.Value )
{
min=(double)item.Value ;
minIndex=(int)item.Key;
}
}
string maxk=kPoint[maxIdex].ToString ();//最大斜率
Point maxBegin=(Point)linePoint[maxIdex-1];//最大斜率起點
Point maxEnd=(Point)linePoint[maxIdex];//最大斜率終點
string mink=kPoint[minIndex].ToString ();//最小斜率
Point minBegin=(Point)linePoint[minIndex-1];//最小斜率起點
Point minEnd=(Point)linePoint[minIndex];//最大小斜率終點
}