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

convert angle from ucs to wcs

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
FrankLenoir
1421 Views, 6 Replies

convert angle from ucs to wcs

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

6 REPLIES 6
Message 2 of 7

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 3 of 7

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

Message 4 of 7

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
Ingenieur Studio HOLLAUS ... www.hollaus.at ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 5 of 7

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

 

 

Message 6 of 7
Balaji_Ram
in reply to: FrankLenoir

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

Message 7 of 7
FrankLenoir
in reply to: Balaji_Ram

Thanks very much Balaji.

 

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

 

Frank

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