Author Topic: How to find Bisecting Line  (Read 3335 times)

0 Members and 1 Guest are viewing this topic.

Proctor

  • Guest
How to find Bisecting Line
« on: May 14, 2010, 12:49:44 PM »
Hello: I'm working in Cad 09 for .net api and want to find line that Bisects through the intersection of 2 lines (see pic). The 2 blue lines represent the 2 lines that intersect.  i want to biset through these. the red line is the line i want to find.

How can I do this?

Thank you,
Proctor

Daniel Eiszele

  • Newt
  • Posts: 85
Re: How to find Bisecting Line
« Reply #1 on: May 15, 2010, 04:09:06 AM »
I don't know if there is a native API function that will do this; but to do it the long way I would calculate the Unit direction vectors for the two lines from the centre point outwards.  Next, compute the halfway point between these vectors and add it to the original centre point.  You now have two points on the bisecting line (ie the calculated point plus the centre point); from these you can create the line itself.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to find Bisecting Line
« Reply #2 on: May 15, 2010, 04:50:18 AM »
Daniel,
Proctor wants to 'FIND' the line I think, not create it.

Proctor,
Assuming this is ALL being done programmatically ;
doing a crossing selection where you think the line should be may give you a choice of possibilities ...
you may need to take selection attempts at multiple locations until you can isolate the particular line that  meets the required criteria.

 Have you made any attempts at writing code to solve the problem ??
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Proctor

  • Guest
Re: How to find Bisecting Line
« Reply #3 on: May 18, 2010, 04:36:27 PM »
Thanks to both of you for your inputs! I actually did need to create the line. I used
Daniel's instructions to help me.

thanks again.....

Proctor

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: How to find Bisecting Line
« Reply #4 on: May 18, 2010, 08:10:59 PM »
Thanks to both of you for your inputs! I actually did need to create the line. I used
Daniel's instructions to help me.

thanks again.....

Proctor

.. and for anyone following along later, the code solution was ... ?
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8789
  • AKA Daniel
Re: How to find Bisecting Line
« Reply #5 on: May 18, 2010, 08:20:24 PM »
Yeah, show the code  ;-)

Proctor

  • Guest
Re: How to find Bisecting Line
« Reply #6 on: May 19, 2010, 12:45:44 PM »
Here's my code: Im using the Point3AngularDimension object to get the angle between 2 lines and now i've also added code to get the the bisector between the 2 lines (see purple line in pic).

I pulled the code to get he angular dimension off the AutoCad .NET Developer's Guide. 

Sending a pic of the final outcome. Thanks again for your help.
Proctor

Code: [Select]

   <CommandMethod("CreateAngularDimension")> _
        Public Function GetAngle(ByVal myPreviousLine, ByVal myLine) As Double


            ' Get the current database
            Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
            Dim acCurDb As Database = acDoc.Database
            Dim dAngle As Double = 0 'angle of line
            Dim dMeasurment As Double = 0
            Dim pMidpoint As Point3d
            Dim sDirection As String = ""
            Dim myCenterPoint As Point3d = Nothing
            Dim myNewLine As Line = Nothing
            Dim myTriangleLineToGetBisector As Line = Nothing
            Dim myTriangleLineToGetBisector1 As Line = Nothing
            Dim myTriangleLineToGetBisector2 As Line = Nothing
            Dim myBisectorLine As Line = Nothing

            Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
                Dim myIntersectPts As New Point3dCollection
                Dim myLine3d As Line3d

                ' Open the Block table for read
                Dim acBlkTbl As BlockTable
                acBlkTbl = acTrans.GetObject(acCurDb.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 an angular dimension
                Dim acLinAngDim As Point3AngularDimension = New Point3AngularDimension()
                acLinAngDim.SetDatabaseDefaults()

                'this represents the vertex point (point between the 2 lines)
                If myLine.startpoint.Equals(myPreviousLine.startpoint) Then
                    myTriangleLineToGetBisector = New Line(myLine.startpoint, myLine.endpoint)
                    myTriangleLineToGetBisector1 = New Line(myPreviousLine.startpoint, myPreviousLine.endpoint)
                    acLinAngDim.CenterPoint = New Point3d(myLine.startpoint.x, myLine.startpoint.y, 0)
                    'this is the point that's not the vertex for myLine
                    acLinAngDim.XLine1Point = New Point3d(myLine.endpoint.x, myLine.endpoint.y, 0)
                    'this is the point that's not the vertex for myPreviousLine
                    acLinAngDim.XLine2Point = New Point3d(myPreviousLine.endpoint.x, myPreviousLine.endpoint.y, 0)
                ElseIf myLine.startpoint.Equals(myPreviousLine.endpoint) Then
                    myTriangleLineToGetBisector = New Line(myLine.startpoint, myLine.endpoint)
                    myTriangleLineToGetBisector1 = New Line(myPreviousLine.endpoint, myPreviousLine.startpoint)
                    acLinAngDim.CenterPoint = New Point3d(myLine.startpoint.x, myLine.startpoint.y, 0)
                    'this is the point that's not the vertex for myLine
                    acLinAngDim.XLine1Point = New Point3d(myLine.endpoint.x, myLine.endpoint.y, 0)
                    'this is the point that's not the vertex for myPreviousLine
                    acLinAngDim.XLine2Point = New Point3d(myPreviousLine.startpoint.x, myPreviousLine.startpoint.y, 0)
                ElseIf myLine.endpoint.Equals(myPreviousLine.startpoint) Then
                    myTriangleLineToGetBisector = New Line(myLine.endpoint, myLine.startpoint)
                    myTriangleLineToGetBisector1 = New Line(myPreviousLine.startpoint, myPreviousLine.endpoint)
                    acLinAngDim.CenterPoint = New Point3d(myLine.endpoint.x, myLine.endpoint.y, 0)
                    'this is the point that's not the vertex for one myLine
                    acLinAngDim.XLine1Point = New Point3d(myLine.startpoint.x, myLine.startpoint.y, 0)
                    'this is the point that's not the vertex for myPreviousLine
                    acLinAngDim.XLine2Point = New Point3d(myPreviousLine.endpoint.x, myPreviousLine.endpoint.y, 0)
                ElseIf myLine.endpoint.Equals(myPreviousLine.endpoint) Then
                    myTriangleLineToGetBisector = New Line(myLine.endpoint, myLine.startpoint)
                    myTriangleLineToGetBisector1 = New Line(myPreviousLine.endpoint, myPreviousLine.startpoint)
                    acLinAngDim.CenterPoint = New Point3d(myLine.endpoint.x, myLine.endpoint.y, 0)
                    'this is the point that's not the vertex for myLIne
                    acLinAngDim.XLine1Point = New Point3d(myLine.startpoint.x, myLine.startpoint.y, 0)
                    'this is the point that's not the vertex for myPreviousLine
                    acLinAngDim.XLine2Point = New Point3d(myPreviousLine.startpoint.x, myPreviousLine.startpoint.y, 0)
                End If

                'going to find the bisecting line between the angle:
                'create 2 lines - from the center point going in the same direction as the lines:
                Dim myPointForMyTriangleLineToGetBisector As Point3d = myTriangleLineToGetBisector.GetPointAtDist(1)
                Dim myPointForMyTriangleLineToGetBisector1 As Point3d = myTriangleLineToGetBisector1.GetPointAtDist(1)
                DrawLine(myTriangleLineToGetBisector.StartPoint, myPointForMyTriangleLineToGetBisector, "Blue")
                myPointForMyTriangleLineToGetBisector1 = myTriangleLineToGetBisector1.GetPointAtDist(1)
                DrawLine(myTriangleLineToGetBisector1.StartPoint, myPointForMyTriangleLineToGetBisector1, "Red")
                myTriangleLineToGetBisector2 = New Line(myPointForMyTriangleLineToGetBisector, myPointForMyTriangleLineToGetBisector1)
                DrawLine(myTriangleLineToGetBisector2.StartPoint, myTriangleLineToGetBisector2.EndPoint, "Pink")
                pMidpoint = myTriangleLineToGetBisector2.StartPoint.Add(myTriangleLineToGetBisector2.StartPoint.GetVectorTo(myTriangleLineToGetBisector2.EndPoint).MultiplyBy(0.5))

                'get midline of this line and then you have the bisector
                myLine3d = New Geometry.Line3d(myTriangleLineToGetBisector2.StartPoint, myTriangleLineToGetBisector2.EndPoint)
                pMidpoint = pMidpoint.Subtract(myLine3d.Direction.Negate.GetPerpendicularVector.MultiplyBy(1))
                DrawLine(myTriangleLineToGetBisector2.StartPoint, myTriangleLineToGetBisector2.EndPoint, "Gold")
                myBisectorLine = New Line(myTriangleLineToGetBisector2.StartPoint, myTriangleLineToGetBisector2.EndPoint)

                acLinAngDim.DimensionStyle = acCurDb.Dimstyle
                myCenterPoint = acLinAngDim.CenterPoint
                Debug.Print("My Center Point: " & myCenterPoint.ToString())
                'Draw Bisecting line:
                myBisectorLine = New Line(myCenterPoint, pMidpoint)
                DrawLine(myBisectorLine.StartPoint, myBisectorLine.EndPoint, "Purple")
                acLinAngDim.ArcPoint = New Point3d(myBisectorLine.EndPoint.X, myBisectorLine.EndPoint.Y, 0)

                sDirection = GetLineDirrection(myBisectorLine)
                colLISTOfAngularDimensionsDirection.Add(sDirection)

                dMeasurment = acLinAngDim.Measurement
                dAngle = Math.Round(dMeasurment * 180 / Math.PI)
                Debug.Print("Angle: " & dAngle.ToString())

                ' Add the new object to Model space and the transaction
                acBlkTblRec.AppendEntity(acLinAngDim)
                acTrans.AddNewlyCreatedDBObject(acLinAngDim, True)

                acTrans.Commit()
            End Using

        End Function


Bryco

  • Water Moccasin
  • Posts: 1883
Re: How to find Bisecting Line
« Reply #7 on: May 19, 2010, 04:06:18 PM »
Vector3d v1 = (p1 - p2).GetNormal(), v2 = (p3 - p2).GetNormal();
 Vector3d v3 = (v1.Add(v2)).GetNormal();

This is the simplest way to find a biscector that I have found,
where p2 is the shared vertex, the line would have p2 as the start and p2+v3* some number as the end point