第二个是找出点是在区域对象的内侧还是外侧,我也试过了。
- Namespace BRepSamples
- Public NotInheritable Class Containment
- Private Sub New()
- End Sub
- '' <summary>
- ''
- '' This sample shows how to use the BREP API to do
- '' simple topographical point/boundary classification
- '' on regions.
- ''
- '' This code requires a reference to AcDbMgdBrep.dll
- ''
- '' The sample prompts for a region object; gets a BRep
- '' object representing the region; and then repeatedly
- '' prompts for points, and computes and displays the
- '' containment (inside, outside, or on an edge) of each
- '' selected point.
- ''
- '' A point within an inner loop is considered to be
- '' 'ouside' the region's area, and so if you perform
- '' this operation on a complex region with inner loops,
- '' points contained within an inner loop will yield a
- '' result of PointContainment.Outside.
- '
- '' This is the most robust means of determining if a
- '' point lies within the implied boundary formed by a
- '' collection of AutoCAD entites that can be used to
- '' create a valid AutoCAD Region object, and is the
- '' preferred means of doing simple point containment
- '' testing.
- ''
- '' You can adapt this code to perform containment tests
- '' on various AutoCAD entities such as closed polylines,
- '' splines, ellipses, etc., by generating a region from
- '' the closed geometry, using it to do the containment
- '' test, and then disposing it without having to add it
- '' to a database.
- ''
- '' Note that the sample code was designed to work with
- '' regions that lie in the WCS XY plane and points that
- '' lie in the same plane.
- ''
- '' </summary>
- <CommandMethod("CONTAINMENT")> _
- Public Shared Sub ContainmentCommand()
- Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
- Dim id As ObjectId = GetRegion(ed, vbLf & "Select a region: ")
- If Not id.IsNull Then
- Using tr As Transaction = ed.Document.TransactionManager.StartTransaction()
- Try
- Dim region As Region = TryCast(id.GetObject(OpenMode.ForRead), Region)
- Dim ppo As New PromptPointOptions(vbLf & "Select a point: ")
- ppo.AllowNone = True
- While True
- ' loop while user continues to pick points
- '' Get a point from user:
- Dim ppr As PromptPointResult = ed.GetPoint(ppo)
- If ppr.Status <> PromptStatus.OK Then
- ' no point was selected, exit
- Exit While
- End If
- ' use the GetPointContainment helper method below to
- ' get the PointContainment of the selected point:
- Dim containment As PointContainment = GetPointContainment(region, ppr.Value)
- ' Display the result:
- ed.WriteMessage(containment.ToString())
- End While
- Finally
- tr.Commit()
- End Try
- End Using
- End If
- End Sub
- '' <summary>
- ''
- '' This variation performs point contianment testing
- '' against any closed curve from which a simple region
- ' (e.g., no inner-loops) can be genreated, using the
- '' Region.CreateFromCurves() API.
- ''
- '' </summary>
- <CommandMethod("CURVECONTAINMENT")> _
- Public Shared Sub CurveContainmentCommand()
- Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
- Dim id As ObjectId = GetCurve(ed, vbLf & "Select a closed Curve: ")
- If Not id.IsNull Then
- Using tr As Transaction = ed.Document.TransactionManager.StartTransaction()
- Try
- Dim curve As Curve = DirectCast(id.GetObject(OpenMode.ForRead), Curve)
- If Not curve.Closed Then
- ed.WriteMessage(vbLf & "Invalid selection, requires a CLOSED curve")
- Return
- End If
- Using region As Region = RegionFromClosedCurve(curve)
- Dim ppo As New PromptPointOptions(vbLf & "Select a point: ")
- ppo.AllowNone = True
- While True
- ' loop while user continues to pick points
- '' Get a point from user:
- Dim ppr As PromptPointResult = ed.GetPoint(ppo)
- If ppr.Status <> PromptStatus.OK Then
- ' no point was selected, exit
- Exit While
- End If
- ' use the GetPointContainment helper method below to
|