Get angle in Z axis

Get angle in Z axis

waseefur.rahman
Advocate Advocate
2,406 Views
1 Reply
Message 1 of 2

Get angle in Z axis

waseefur.rahman
Advocate
Advocate

Hi Everyone!

I am trying to get the angle between two lines, I have attached the image
For getting the angle in Z axis I have changed the ucs and then I tried to get the angle, but It has been showing the angle in xy, only ucs has been changed to specified point.

 

 

Dim Vuline As Line = New Line(center, ptver)
               '' Add the line to the drawing
                curSpace.AppendEntity(Vuline)
                tr.AddNewlyCreatedDBObject(Vuline, True)

                
                Dim Vlline As Line = New Line(center, ptlow)
                '' Add the line to the drawing
                curSpace.AppendEntity(Vlline)
                tr.AddNewlyCreatedDBObject(Vlline, True)

 Dim vlPt1 As Point3d = Vlline.StartPoint
Dim vlPt2 As Point3d = Vlline.EndPoint
 Dim vuPt1 As Point3d = Vlline.StartPoint
Dim vuPt2 As Point3d = Vlline.EndPoint

'change use
                Dim acUCSTbl As UcsTable
                acUCSTbl = tr.GetObject(acCurDb.UcsTableId, OpenMode.ForRead)
                Dim acUCSTblRec As UcsTableRecord
                ' Check to see if the "Window_UCS" UCS table record exists
                If acUCSTbl.Has("New_UCS") = False Then
                    acUCSTblRec = New UcsTableRecord()
                    acUCSTblRec.Name = "New_UCS"
                    '' Open the UCSTable for write
                    acUCSTbl.UpgradeOpen()
                    '' Add the new UCS table record
                    acUCSTbl.Add(acUCSTblRec)
                    tr.AddNewlyCreatedDBObject(acUCSTblRec, True)
                Else
                    acUCSTblRec = tr.GetObject(acUCSTbl("New_UCS"), OpenMode.ForWrite)
                End If

                Dim StartPts = center
                Dim EndPts = New Point3d(ptver.X, ptver.Y, center.Z)
                Dim AnglePts = ptver

                Dim xVex As Vector3d
                Dim yVex As Vector3d
                Dim zVex As Vector3d
                Dim AngleCord As Matrix3d
                xVex = center.GetVectorTo(EndPts).GetNormal()
                zVex = xVex.CrossProduct(StartPts.GetVectorTo(AnglePts)).GetNormal()
                yVex = zVex.CrossProduct(xVex).GetNormal()

                AngleCord = Matrix3d.AlignCoordinateSystem(Point3d.Origin, Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, StartPts, xVex, yVex, zVex)

                acUCSTblRec.Origin = AngleCord.CoordinateSystem3d.Origin
                acUCSTblRec.XAxis = AngleCord.CoordinateSystem3d.Xaxis
                acUCSTblRec.YAxis = AngleCord.CoordinateSystem3d.Yaxis

                '' Open the active viewport
                Dim acVportTblRec As ViewportTableRecord
                acVportTblRec = tr.GetObject(acDoc.Editor.ActiveViewportId,
                                          OpenMode.ForWrite)

                '' Display the UCS Icon at the origin of the current viewport
                acVportTblRec.IconAtOrigin = True
                acVportTblRec.IconEnabled = True

                '' Set the UCS current
                acVportTblRec.SetUcs(acUCSTblRec.ObjectId)
                acDoc.Editor.UpdateTiledViewportsFromDatabase()

Dim acLinAngDimv As LineAngularDimension2 = New LineAngularDimension2()
acLinAngDimv.XLine1Start = New Point3d(vlPt1.X, vlPt1.Y, 0)
                acLinAngDimv.XLine1End = New Point3d(vlPt2.X, vlPt2.Y, 0)
                acLinAngDimv.XLine2Start = New Point3d(vuPt1.X, vuPt1.Y, 0)
                acLinAngDimv.XLine2End = New Point3d(vuPt2.X, vuPt2.Y, 0)
                'acLinAngDims.ArcPoint = New Point3d(3, 5, 0)
                acLinAngDimv.DimensionStyle = acCurDb.Dimstyle

                '' Add the new object to Model space and the transaction
                curSpace.AppendEntity(acLinAngDimv)
                tr.AddNewlyCreatedDBObject(acLinAngDimv, True)



could anyone guide me, how to changed the code to achieve the result..

0 Likes
Accepted solutions (1)
2,407 Views
1 Reply
Reply (1)
Message 2 of 2

ActivistInvestor
Mentor
Mentor
Accepted solution

@waseefur.rahman wrote:

Hi Everyone!

I am trying to get the angle between two lines, I have attached the image
For getting the angle in Z axis I have changed the ucs and then I tried to get the angle, but It has been showing the angle in xy, only ucs has been changed to specified point.


I'm not sure I understand what 'the angle in Z axis' means. Do you mean the angle in the XZ or YZ plane? 

 

In any case, the angle between any two lines in 3D space in the plane that both lines lie in:

 

Line line1 = ....
Line line2 = ....

Vector3d v1 = line1.StartPoint.GetVectorTo(line1.EndPoint); Vector3d v2 = line2.StartPoint.GetVectorTo(line2.EndPoint);
double angle = v1.GetAngleTo(v2);

 

To get the angle of a line in the XZ plane, from the X axis:

 

Line line = ... (lies in the XZ plane)

Vector3d vector = line.StartPoint.GetVectorTo(Line.EndPoint);

double angle = Vector3d.XAxis.GetAngleTo(vector);

;; or where the line is in the YZ plane:

double angle = Vector3d.YAxis.GetAngleTo(vector);

 

To get the angle of a line in any plane that's parallel to the Z axis, you can use the same method as the above, to find the angle between the line and the Z axis (Vector3d.ZAxis), and the difference between that and 90 degrees is the angle of the line (e.g., the 'slope') from the XY plane.