Intersection Point

Intersection Point

Anonymous
Not applicable
2,075 Views
4 Replies
Message 1 of 5

Intersection Point

Anonymous
Not applicable

What is the best way to get the intersection point of two selected lines.

 

if I use:

dim pntIntPoint as Point2d = objFirstLine.IntersectWith(objSecondLine, Intersect.ExtendBoth)

 

I get a message saying "Overload resolution failed because no accessible 'IntersectWith' accepts this number of arguments."

0 Likes
2,076 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

The Entity.IntersectWith() has 5 or 6 argumnet and does not have return value.

 

If you only pass in 2 parameteres and try to get a returned value in your code, granted, the code would not compile/run.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable

Now I did:

 

dim pntIntPoint as Point3d

dim myDir as Vector3d = New Vector3d(0,0,1)

dim myOrig as Point3d = New Point3d(0,0,0)

dim myPlane as Plane = New Plane(myOrig, myDir)

dim myPntColl as Point3dCollection = New Point3dCollection

 

objFirstLine.IntersectWith(objSecondLine, Intersect.ExtendBoth, myPntColl,0,0)

 

if myPntColl.count >0 then

   msgbox(myPntColl.count)

end if

 

 

I now get the message:

 

IntersectWith(entityPointer As Autodesk.AutoCAD.DatabaseServices.Entity,

intersectType As Autodesk.AutoCAD.DatabaseServices.Intersect,

points As Autodesk.AutoCAD.Geometry.Point3dCollection,

thisGraphicSystemMarker As Integer,

otherGraphicSystemMarker As Integer)' is obsolete: 'Use the overload taking IntPtr instead.'.

0 Likes
Message 4 of 5

Anonymous
Not applicable

This is a sample of what I came up with that works.

 

Private Sub subCreateCircleExample(ByVal objFirstLine As Line, ByVal objSecondLine As Line)


        Dim myPnt01 As Point3d = objFirstLine.StartPoint
        Dim myPnt02 As Point3d = objFirstLine.EndPoint
        Dim myPnt03 As Point3d = objSecondLine.StartPoint
        Dim myPnt04 As Point3d = objSecondLine.EndPoint

 

        Dim myLine01 As New LineSegment2d(New Point2d(myPnt01.X, myPnt01.Y), New Point2d(myPnt02.X, myPnt02.Y))
        Dim myLine02 As New LineSegment2d(New Point2d(myPnt03.X, myPnt03.Y), New Point2d(myPnt04.X, myPnt04.Y))

 

        Dim pntCurvInt As CurveCurveIntersector2d = New CurveCurveIntersector2d(myLine01, myLine02)
        Dim intNoOfPnts As Integer = pntCurvInt.NumberOfIntersectionPoints


        Dim pntIntPnt As Point2d

        If intNoOfPnts = 1 Then 'you can put a counter here
            pntIntPnt = New Point2d(pntCurvInt.GetIntersectionPoint(0).X, pntCurvInt.GetIntersectionPoint(0).Y)
        Else
            Exit Sub
        End If

 

        'Setup a transaction to the drawing
        Using lock As DocumentLock = MyDrawing.LockDocument
            '' Start a transaction
            Using acTrans As Transaction = MyDrawingDb.TransactionManager.StartTransaction()
                Try
                    '' Open the Block table for read
                    Dim acBlkTbl As BlockTable
                    acBlkTbl = acTrans.GetObject(MyDrawingDb.BlockTableId, OpenMode.ForRead)

                    '' Open the Block table record Model space for write
                    Dim acBlkTblRec As BlockTableRecord
                    acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _
                                                    OpenMode.ForWrite)

                    '' Create a circle that is at 2,3 with a radius of 4.25
                    Dim acCirc As Circle = New Circle()
                    acCirc.SetDatabaseDefaults()
                    acCirc.Center = New Point3d(pntIntPnt.X, pntIntPnt.Y, 0)
                    acCirc.Radius = 4.25

                    '' Add the new object to the block table record and the transaction
                    acBlkTblRec.AppendEntity(acCirc)
                    acTrans.AddNewlyCreatedDBObject(acCirc, True)

                    '' Save the new object to the database
                    acTrans.Commit()
                Catch ex As Exception
                    MsgBox(ex.Message & vbCr & ex.StackTrace)
                End Try
            End Using
        End Using
    End Sub

0 Likes
Message 5 of 5

Anonymous
Not applicable

This worked better to get the intersection point. It gets apparent intersections also.

 

        'Setup 3d plane and point collection
        Dim myPlaneWCS As Plane = New Plane(New Point3d(0, 0, 0), New Vector3d(0, 0, 1))
        Dim myIntPntCol As Point3dCollection = New Point3dCollection()
        Dim myintptr01 As IntPtr = New IntPtr()
        Dim myintptr02 As IntPtr = New IntPtr()

 

        'Get intersecting point collection
        objFirstLine.IntersectWith(objSecondLine, Intersect.ExtendBoth, myPlaneWCS, myIntPntCol, myintptr01, myintptr02)

 

        Dim pntIntPnt As Point3d
        'Check if number of intersecting points is one
        If myIntPntCol.Count = 1 Then
            'Create a new point from intersecting point
            pntIntPnt = New Point3d(myIntPntCol(0).X, myIntPntCol(0).Y, 0)
        Else
            MsgBox("Intersecting error.", MsgBoxStyle.Critical, "")
            Exit Sub
        End If

0 Likes