Author Topic: Angle between two lines  (Read 2692 times)

0 Members and 1 Guest are viewing this topic.

Proctor

  • Guest
Angle between two lines
« on: April 28, 2010, 01:56:54 PM »
Hello: I'm trying to find the angle between 2 lines; however, I've been running into difficulties.

Take a look at the first pic below, you will see the angle i would like to find ....it's the 112 degree angle that's inside the polygon -between the 2 red lines.

To get the angle, I'm getting the difference between each line angle; however, I found that depending on which dirrection the line was drawn will give me different results. e.g. Take a look at my second pic - the 2 lines are identified in red. The angle of the top red line is 0 and the other red line is 292. Clearly the differnce between these 2 angles is not 112; however, if i redraw the red line w/ the angle of 0 in a different direction, i get 180. therefore, 292-180=112.

I thought that i would therefore try to use this code I got from the AutoCAD .NET Developer's Guide - for creating an Angular Dimension to see if it would give me the correct angle, but It's not working correctly (see pic 3 that shows the output).

Here's the code:
Code: [Select]

  <CommandMethod("CreateAngularDimension")> _
    Public Sub CreateAngularDimension(myPreviousLine,myLine)
        '' Get the current database
        Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim acCurDb As Database = acDoc.Database

        '' Start a transaction
        Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()

            '' 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 LineAngularDimension2 = New LineAngularDimension2()
            acLinAngDim.SetDatabaseDefaults()

            acLinAngDim.XLine1Start = New Point3d(myLine.startpoint.x, myLine.startpoint.y, 0)
            acLinAngDim.XLine1End = New Point3d(myLine.endpoint.x, myLine.endpoint.y, 0)
            acLinAngDim.XLine2Start = New Point3d(myPreviousLine.startpoint.x, myPreviousLine.startpoint.y, 0)
            acLinAngDim.XLine2End = New Point3d(myPreviousLine.endpoint.x, myPreviousLine.endpoint.y, 0)
            acLinAngDim.ArcPoint = New Point3d(3, 5, 0)
            acLinAngDim.DimensionStyle = acCurDb.Dimstyle

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

            '' Commit the changes and dispose of the transaction
            acTrans.Commit()
        End Using
    End Sub


I was hoping someone might know why the angle is drawing on the outside of the poly and therefore not giving me the correct angle (112)....from looking at this code? Or, perhaps there's a better way to do this?

Thank you for your input,
Proctor

Proctor

  • Guest
Re: Angle between two lines
« Reply #1 on: April 28, 2010, 02:07:49 PM »
I just realized that this line:

acLinAngDim.ArcPoint = New Point3d(3, 5, 0)

is why the arc is pointing outwards....I need to establish a point that's between both lines.
I'm not sure how to do this - I think i might have to make sure the point didn't reside on the outside of the poly.

Any ideas? Maybe there's another way to do this that's better?

Thanks again,
Proctor

Swift

  • Swamp Rat
  • Posts: 596
Re: Angle between two lines
« Reply #2 on: April 28, 2010, 04:27:33 PM »
Just a quick thought, but if you checked if the points were in a clockwise order, then the dot product would give you a point between them?

Just a thought

Proctor

  • Guest
Re: Angle between two lines
« Reply #3 on: April 28, 2010, 04:59:25 PM »
Swift...good ideas...thanks! Let me try this and see if it works.

Thanks,
Proctor