写了一个判断点是否在多边形的某条边上的程序, 以白色部分作为边界的时候,当取某条边延长线(红色部分)上的点时,
请问什么结果不正确?
Private Sub TestOnBoundary() Dim TestPoint As Variant Dim Util As AcadUtility Dim Entity As AcadEntity Dim PickPt As Variant Set Util = ThisDrawing.Utility On Error GoTo Done Util.GetEntity Entity, PickPt, "Select region: " Do While (True) TestPoint = Util.GetPoint(, vbCrLf & "Test point: ") If IsPointOnBoundary(TestPoint, Entity) Then Util.Prompt (vbCrLf & "Point is on the boundary") Else Util.Prompt (vbCrLf & "Point is not on the boundary") End If Loop Done: End Sub
Private Function IsPointOnBoundary( _ ByVal varPnt As Variant, _ ByVal objBoundary As AcadEntity) As Boolean Dim objDoc As AcadDocument Dim objBlock As AcadBlock Dim objPnt As AcadPoint Dim varPnts As Variant Set objDoc = objBoundary.Document Set objBlock = objDoc.ObjectIdToObject(objBoundary.OwnerID) Set objPnt = objBlock.AddPoint(varPnt) varPnts = objPnt.IntersectWith(objBoundary, acExtendNone) IsPointOnBoundary = UBound(varPnts) > 0 objPnt.Delete End Function |