.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Intersection Point

4 REPLIES 4
Reply
Message 1 of 5
cadcamm99
1921 Views, 4 Replies

Intersection Point

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."

4 REPLIES 4
Message 2 of 5
norman.yuan
in reply to: cadcamm99

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

Message 3 of 5
cadcamm99
in reply to: norman.yuan

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.'.

Message 4 of 5
cadcamm99
in reply to: cadcamm99

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

Message 5 of 5
cadcamm99
in reply to: cadcamm99

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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost