http://bbs.mjtd.com/thread-92445-1-1.html
Public Function ptInPolygon1(pt As Point3d, pPolyline As Polyline) As Integer
Dim count As Integer = pPolyline.NumberOfVertices
'构建多边形外接矩形
Dim maxx As Double = Double.MinValue, maxy As Double = Double.MinValue, minx As Double = Double.MaxValue, miny As Double = Double.MaxValue
Dim i As Integer = 0
While i < count
If pPolyline.GetPoint3dAt(i).X > maxx Then
maxx = pPolyline.GetPoint3dAt(i).X
End If
If pPolyline.GetPoint3dAt(i).Y > maxy Then
maxy = pPolyline.GetPoint3dAt(i).Y
End If
If pPolyline.GetPoint3dAt(i).X < minx Then
minx = pPolyline.GetPoint3dAt(i).X
End If
If pPolyline.GetPoint3dAt(i).Y < miny Then
miny = pPolyline.GetPoint3dAt(i).Y
End If
System.Math.Max(System.Threading.Interlocked.Increment(i),i - 1)
End While
If pt.X > maxx OrElse pt.Y > maxy OrElse pt.X < minx OrElse pt.Y < miny Then
Return -1
End If
Dim line1 As New Line(New Point3d(maxx, pt.Y, 0), New Point3d(minx, pt.Y, 0))
Dim crossCount As Integer = 0
Using tran As Transaction = pDatabase.TransactionManager.StartTransaction()
Dim pBlockTableRecord As BlockTableRecord = TryCast(tran.GetObject(pDatabase.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
Dim crossPoint As New Point3dCollection()
line1.IntersectWith(pPolyline, Intersect.OnBothOperands, crossPoint, 0, 0)
If crossPoint.Count >= 1 Then
Dim n As Integer = 0
While n < crossPoint.Count
Dim crossPt As Point3d = crossPoint(n)
If crossPt.X > pt.X Then
System.Math.Max(System.Threading.Interlocked.Increment(crossCount),crossCount - 1)
Dim pCircle As New Circle(crossPt, Vector3d.ZAxis, 2)
pBlockTableRecord.AppendEntity(pCircle)
tran.AddNewlyCreatedDBObject(pCircle, True)
End If
System.Math.Max(System.Threading.Interlocked.Increment(n),n - 1)
End While
End If
Dim circle As New Circle(pt, Vector3d.ZAxis, 2)
pBlockTableRecord.AppendEntity(circle)
tran.AddNewlyCreatedDBObject(circle, True)
pBlockTableRecord.AppendEntity(line1)
tran.AddNewlyCreatedDBObject(line1, True)
tran.Commit()
End Using
Return crossCount Mod 2
End Function
还可以参考 :http://bbs.xdcad.net/thread-715959-1-1.html
判断点是否在多边形内部
如何判断一个点是否在多边形内部?
(1)面积和判别法:判断目标点与多边形的每条边组成的三角形面积和是否等于该多边形,相等则在多边形内部。
(2)夹角和判别法:判断目标点与所有边的夹角和是否为360度,为360度则在多边形内部。
(3)引射线法:从目标点出发引一条射线,看这条射线和多边形所有边的交点数目。如果有奇数个交点,则说明在内部,如果有偶数个交点,则说明在外部。
[本日志由 tiancao1001 于 2018-10-24 11:05 AM 编辑]
|
homemisha 于 2017-09-16 09:55 PM 发表评论:
看不到啊,亲
发表评论 - 不要忘了输入验证码哦! |