Message 1 of 9
polyline inside closed polyline?
Not applicable
06-29-2006
04:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Im trying to write a function that determines whether a given polyline is inside of another given closed polyline. I use the standard method of drawing a ray and checking how many intersections it has with the second object. I also take into account if the polyline starts on top of the other. here is the code
Private Function fncIsInside(ByVal obj1stEnt As AcadEntity, ByVal obj2ndEnt As AcadEntity) As Boolean
Dim var1stEntPnts As Variant
Dim var2ndEntPnts As Variant
Dim varNoIntersect As Variant
Dim intNoIntersect As Integer
Dim intI As Integer
Dim intJ As Integer
Dim intK As Integer
Dim testRay As AcadRay
Dim firstPt(0 To 2) As Double
Dim secondPt(0 To 2) As Double
var1stEntPnts = obj1stEnt.Coordinates
For intI = 0 To UBound(var1stEntPnts)
intNoIntersect = 0
firstPt(0) = var1stEntPnts(intI)
firstPt(1) = var1stEntPnts(intI + 1)
firstPt(2) = 0
secondPt(0) = var1stEntPnts(intI) + 1
secondPt(1) = var1stEntPnts(intI + 1)
secondPt(2) = 0
Set testRay = ThisDrawing.ModelSpace.AddRay(firstPt, secondPt)
var2ndEntPnts = testRay.IntersectWith(obj2ndEnt, acExtendNone)
If UBound(var2ndEntPnts) > 0 Then
For intJ = 0 To UBound(var2ndEntPnts)
If var1stEntPnts(intI) <> var2ndEntPnts(intJ) And var1stEntPnts(intI + 1) <> var2ndEntPnts(intJ + 1) Then
intNoIntersect = intNoIntersect + 1
End If
intJ = intJ + 3
Next intJ
intNoIntersect = (intNoIntersect + 1) / 3
intNoIntersect = intNoIntersect Mod 2
End If
If intNoIntersect = 0 Then
fncIsInside = False
Else
fncIsInside = True
End If
intI = intI + 3
Next intI
End Function
my problem is that for some polylines it registers it as being outside when it clearly isnt, what am I doing wrong here?
Private Function fncIsInside(ByVal obj1stEnt As AcadEntity, ByVal obj2ndEnt As AcadEntity) As Boolean
Dim var1stEntPnts As Variant
Dim var2ndEntPnts As Variant
Dim varNoIntersect As Variant
Dim intNoIntersect As Integer
Dim intI As Integer
Dim intJ As Integer
Dim intK As Integer
Dim testRay As AcadRay
Dim firstPt(0 To 2) As Double
Dim secondPt(0 To 2) As Double
var1stEntPnts = obj1stEnt.Coordinates
For intI = 0 To UBound(var1stEntPnts)
intNoIntersect = 0
firstPt(0) = var1stEntPnts(intI)
firstPt(1) = var1stEntPnts(intI + 1)
firstPt(2) = 0
secondPt(0) = var1stEntPnts(intI) + 1
secondPt(1) = var1stEntPnts(intI + 1)
secondPt(2) = 0
Set testRay = ThisDrawing.ModelSpace.AddRay(firstPt, secondPt)
var2ndEntPnts = testRay.IntersectWith(obj2ndEnt, acExtendNone)
If UBound(var2ndEntPnts) > 0 Then
For intJ = 0 To UBound(var2ndEntPnts)
If var1stEntPnts(intI) <> var2ndEntPnts(intJ) And var1stEntPnts(intI + 1) <> var2ndEntPnts(intJ + 1) Then
intNoIntersect = intNoIntersect + 1
End If
intJ = intJ + 3
Next intJ
intNoIntersect = (intNoIntersect + 1) / 3
intNoIntersect = intNoIntersect Mod 2
End If
If intNoIntersect = 0 Then
fncIsInside = False
Else
fncIsInside = True
End If
intI = intI + 3
Next intI
End Function
my problem is that for some polylines it registers it as being outside when it clearly isnt, what am I doing wrong here?