python散点图获取边界_获取离散点的边界点

1 publicstaticclassCommon2 {3 ///4 ///获取两个向量的夹角5 ///6 ///源向量7 ///目标向量8 ///9 publicstaticdoubleGetAngle(PlaneVector sourcePlaneVector, PlaneVector destPlaneVector)10 {11 doubletemp=0;12 doublenorm1=0;13 doublenorm2=0;14 15 norm1=System.Math.Sqrt(sourcePlaneVector.X*sourcePlaneVector.X+sourcePlaneVector.Y*sourcePlaneVector.Y);16 norm2=System.Math.Sqrt(destPlaneVector.X*destPlaneVector.X+destPlaneVector.Y*destPlaneVector.Y);17 18 temp=sourcePlaneVector.X*destPlaneVector.X+sourcePlaneVector.Y*destPlaneVector.Y;19 20 if(norm1==0||norm2==0)21 {22 return0;23 }24 else25 {26 temp=temp/(norm1*norm2);27 28 if(temp>1.0)29 {30 temp=1.0;31 }32 elseif(temp42 ///获取一个点在一个点集合中的最远点43 ///44 ///点45 ///点集合46 ///最远点47 publicstaticSystem.Drawing.PointF GetFarthestPointF(System.Drawing.PointF aPointF, ListaPoints)48 {49 if(aPointF==null)50 {51 thrownewArgumentNullException("aPointF");52 }53 54 if(aPoints==null)55 {56 thrownewArgumentNullException("aPoints");57 }58 59 System.Drawing.PointF farthestPointF=System.Drawing.PointF.Empty;60 61 doublemaxLength=0;62 doubletempLength=0;63 64 doublex=0;65 doubley=0;66 67 foreach(System.Drawing.PointF aDestPointinaPoints)68 {69 x=(double)(aDestPoint.X-aPointF.X);70 y=(double)(aDestPoint.Y-aPointF.Y);71 72 tempLength=Math.Sqrt(x*x+y*y);73 74 if(maxLength85 ///获取离散点集的边界点86 ///87 ///一组离散点88 ///离散点的边界点89 publicstaticListGetBorderPointFs(ListaPoints)90 {91 ListaBorderPoints=newList();92 93 if(aPoints==null)94 {95 thrownewArgumentNullException("aPoints");96 }97 98 if(aPoints.Count<3)99 {100 aBorderPoints.AddRange(aPoints);101 102 returnaBorderPoints;103 }104 105 //1.获取任意点的最远点106 107 System.Drawing.PointF farthestPointF=GetFarthestPointF(aPoints.First(), aPoints);108 109 //2.获取边界点 --------------------------------------->110 111 System.Drawing.PointF sourcePointF=farthestPointF;112 System.Drawing.PointF destPointF=aPoints.First();113 114 System.Drawing.PointF maxAnglePoint=System.Drawing.PointF.Empty;115 116 while(!farthestPointF.Equals(maxAnglePoint))117 {118 PlaneVector sourcePlaneVector=newPlaneVector(destPointF, sourcePointF);119 120 doublemaxAngle=0;121 122 foreach(System.Drawing.PointF aDestPointinaPoints)123 {124 PlaneVector destPlaneVector=newPlaneVector(aDestPoint, sourcePointF);125 126 doubletempAngle=GetAngle(sourcePlaneVector, destPlaneVector);127 128 if(maxAngle<=tempAngle)129 {130 maxAngle=tempAngle;131 maxAnglePoint=aDestPoint;132 }133 }134 135 aBorderPoints.Add(maxAnglePoint);136 137 destPointF=sourcePointF;138 sourcePointF=maxAnglePoint;139 140 141 }//---------------------------------------

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值