Announcements

We are currently experiencing an issue impacting some Autodesk Products and Services - please refer to the Autodesk Health Dashboard for updates.

convert angle from ucs to wcs

convert angle from ucs to wcs

Anonymous
Not applicable
1,703 Views
6 Replies
Message 1 of 7

convert angle from ucs to wcs

Anonymous
Not applicable

I have derived an angle from an entity in UCS. Can someone tell me how to convert this angle to the correct angle in WCS?

 

Thanks,

Frank

0 Likes
Accepted solutions (2)
1,704 Views
6 Replies
Replies (6)
Message 2 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

project these entities to WCS and get then the angle 😉

You don't need to add these projected entities to the database, you can .dispose them on end of your calculation.

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 3 of 7

Anonymous
Not applicable

Hi Alfred,

 

The function I am working on works like this: the user picks a random point on an entity. The angle is derived from the entity at the picked point. So I only have the angle as result. But when the user works in a UCS I have to translate the angle to WCS to be able to work with it.

I would prefere to calculate the new angle.

 

Frank

0 Likes
Message 4 of 7

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

how do you request the angle now? Just one point is not enough for me, an angle could be calculated between to straight elements. Could you show this code-snippet?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes
Message 5 of 7

Anonymous
Not applicable
Accepted solution

Hi Alfred,

 

Here is the code I use

       Public Shared Function GetAngleAtPointOnLine() As AngleAtPointOnLineClass
            Dim retValue As New AngleAtPointOnLineClass

            Try
                Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
                Dim myEd As Editor = acDoc.Editor

                Dim bObject As New PromptNestedEntityOptions("")
                Dim opt As PromptPointOptions = New PromptPointOptions("Select point on object: ")
                bObject.NonInteractivePickPoint = myEd.GetPoint(opt).Value
                bObject.UseNonInteractivePickPoint = True

                Dim bRes As PromptNestedEntityResult = myEd.GetNestedEntity(bObject)
                If bRes.Status = PromptStatus.OK Then
                    Using myTrans As Transaction = acDoc.TransactionManager.StartTransaction
                        'the return value of your nested selection may not always be one of 
                        'those things that derives from curve, so you should check it first!
                        If bRes.ObjectId.ObjectClass.IsDerivedFrom(Curve.GetClass(GetType(Curve))) Then
                            Dim crv As Curve = myTrans.GetObject(bRes.ObjectId, OpenMode.ForRead, False, True)
                            Dim wcsPoint As Point3d = bRes.PickedPoint.TransformBy(myEd.CurrentUserCoordinateSystem)
                            Dim myFirstDerivative As Vector3d = crv.GetFirstDerivative(wcsPoint)
                            retValue.Angle = Math.Atan2(CDbl(myFirstDerivative.Y), CDbl(myFirstDerivative.X)) * (180 / Math.PI)
                            retValue.point = New Point3d(bRes.PickedPoint.X, bRes.PickedPoint.Y, bRes.PickedPoint.Z)
                        End If
                    End Using
                End If
                retValue.HasError = False
            Catch ex As Exception
                retValue.HasError = True
                Debug.Print(ex.Message)
            End Try

            Return retValue
        End Function
    End Class


    Public Class AngleAtPointOnLineClass
        Public HasError As Boolean
        Public Angle As Double
        Public point As Point3d
    End Class

 

I found parts of the code on internet. I more or less understand what is happening. As you can see the angle is derived from the exact location on the object. In WCS this function works fine. In UCS the point comes out correctly, but the angle not. The angle needs to be corrected to an angle in WCS.

 

Frank

 

 

0 Likes
Message 6 of 7

Balaji_Ram
Alumni
Alumni
Accepted solution

Hi Frank,

 

The derivative vector is always in WCS. To convert it to UCS can you try this ?

 

<code>

Dim myFirstDerivative AsVector3d = crv.GetFirstDerivative(wcsPoint)

 Dim wcs2ucs AsMatrix3d

wcs2ucs = myEd.CurrentUserCoordinateSystem.Inverse()

myFirstDerivative = myFirstDerivative.TransformBy(wcs2ucs)

</code>

 



Balaji
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 7 of 7

Anonymous
Not applicable

Thanks very much Balaji.

 

The CurrentUserCoordinateSystem.Inverse function returns the desired vector for calculating the correct angle.

 

Frank

0 Likes