- ''' <summary>
- ''' 找多段线上某一顶点到线外一点的最近顶点
- ''' </summary>
- ''' <param name="pt"></param>
- ''' <param name="objPolID"></param>
- ''' <param name="VerNum">可以传出最近点的序号</param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Public Function NearestVerPt(ByVal pt As Point2d, ByVal objPolID As ObjectId, Optional ByRef VerNum As Integer = 0) As Point2d
- Using Trans As Transaction = DB.TransactionManager.StartTransaction
- Dim Ent As Entity = Trans.GetObject(objPolID, clsAADS.OpenMode.ForRead)
- If TypeOf Ent Is Polyline Then
- Dim objPol As Polyline = Ent
- Dim ptTemp As Point2d = objPol.GetPoint2dAt(0)
- Dim Dist As Double = pt.GetDistanceTo(ptTemp)
- VerNum = 0
- For I As Integer = 1 To objPol.NumberOfVertices - 1
- ptTemp = objPol.GetPoint2dAt(I)
- If pt.GetDistanceTo(ptTemp) < Dist Then
- VerNum = I
- Dist = pt.GetDistanceTo(ptTemp)
- End If
- Next
- Return objPol.GetPoint2dAt(VerNum)
- Else
- NearestVerPt = Nothing
- End If
- Trans.Commit()
- End Using
- End Function
|