1publicstaticclassCommon2{3///4///获取两个向量的夹角5///6///源向量7///目标向量8///9publicstaticdoubleGetAngle(PlaneVectorsourcePlaneVector,PlaneVectordestPlaneVector)10{11doubletemp=0;12doublenorm1=0;13doublenorm2=0;1415norm1=System.Math.Sqrt(sourcePlaneVector.X*sourcePlaneVector.X+sourcePlaneVector.Y*sourcePlaneVector.Y);16norm2=System.Math.Sqrt(destPlaneVector.X*destPlaneVector.X+destPlaneVector.Y*destPlaneVector.Y);1718temp=sourcePlaneVector.X*destPlaneVector.X+sourcePlaneVector.Y*destPlaneVector.Y;1920if(norm1==0||norm2==0)21{22return0;23}24else25{26temp=temp/(norm1*norm2);2728if(temp>1.0)29{30temp=1.0;31}32elseif(temp42///获取一个点在一个点集合中的最远点43///44///点45///点集合46///最远点47publicstaticSystem.Drawing.PointFGetFarthestPointF(System.Drawing.PointFaPointF,ListaPoints)48{49if(aPointF==null)50{51thrownewArgumentNullException("aPointF");52}5354if(aPoints==null)55{56thrownewArgumentNullException("aPoints");57}5859System.Drawing.PointFfarthestPointF=System.Drawing.PointF.Empty;6061doublemaxLength=0;62doubletempLength=0;6364doublex=0;65doubley=0;6667foreach(System.Drawing.PointFaDestPointinaPoints)68{69x=(double)(aDestPoint.X-aPointF.X);70y=(double)(aDestPoint.Y-aPointF.Y);7172tempLength=Math.Sqrt(x*x+y*y);7374if(maxLength85///获取离散点集的边界点86///87///一组离散点88///离散点的边界点89publicstaticListGetBorderPointFs(ListaPoints)90{91ListaBorderPoints=newList();9293if(aPoints==null)94{95thrownewArgumentNullException("aPoints");96}9798if(aPoints.Count<3)99{100aBorderPoints.AddRange(aPoints);101102returnaBorderPoints;103}104105//1.获取任意点的最远点106107System.Drawing.PointFfarthestPointF=GetFarthestPointF(aPoints.First(),aPoints);108109//2.获取边界点--------------------------------------->110111System.Drawing.PointFsourcePointF=farthestPointF;112System.Drawing.PointFdestPointF=aPoints.First();113114System.Drawing.PointFmaxAnglePoint=System.Drawing.PointF.Empty;115116while(!farthestPointF.Equals(maxAnglePoint))117{118PlaneVectorsourcePlaneVector=newPlaneVector(destPointF,sourcePointF);119120doublemaxAngle=0;121122foreach(System.Drawing.PointFaDestPointinaPoints)123{124PlaneVectordestPlaneVector=newPlaneVector(aDestPoint,sourcePointF);125126doubletempAngle=GetAngle(sourcePlaneVector,destPlaneVector);127128if(maxAngle<=tempAngle)129{130maxAngle=tempAngle;131maxAnglePoint=aDestPoint;132}133}134135aBorderPoints.Add(maxAnglePoint);136137destPointF=sourcePointF;138sourcePointF=maxAnglePoint;139140141}//---------------------------------------
1500字范文,内容丰富有趣,写作好帮手!