<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: convert angle from ucs to wcs in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3262750#M57991</link>
    <description>&lt;P&gt;Hi Alfred,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I use&lt;/P&gt;&lt;PRE&gt;       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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Dec 2011 17:10:50 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2011-12-14T17:10:50Z</dc:date>
    <item>
      <title>convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261470#M57987</link>
      <description>&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 19:21:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261470#M57987</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-13T19:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261592#M57988</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;project these entities to WCS and get then the angle &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;You don't need to add these projected entities to the database, you can .dispose them on end of your calculation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 20:44:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261592#M57988</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2011-12-13T20:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261656#M57989</link>
      <description>&lt;P&gt;Hi Alfred,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function I am working on works like this: the user picks a random&amp;nbsp;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.&lt;/P&gt;&lt;P&gt;I would prefere to calculate the new angle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 21:11:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261656#M57989</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-13T21:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261698#M57990</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- alfred -&lt;/P&gt;</description>
      <pubDate>Tue, 13 Dec 2011 21:38:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3261698#M57990</guid>
      <dc:creator>Alfred.NESWADBA</dc:creator>
      <dc:date>2011-12-13T21:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3262750#M57991</link>
      <description>&lt;P&gt;Hi Alfred,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I use&lt;/P&gt;&lt;PRE&gt;       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&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Dec 2011 17:10:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3262750#M57991</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-14T17:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3265482#M57992</link>
      <description>&lt;P&gt;Hi Frank,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The derivative vector is always in WCS. To convert it to UCS can you try this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;code&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;Dim &lt;/FONT&gt;&lt;FONT size="2"&gt;myFirstDerivative &lt;FONT color="#0000ff"&gt;&lt;FONT color="#0000ff"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;Vector3d = crv.GetFirstDerivative(wcsPoint)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;nbsp;&lt;FONT color="#0000ff"&gt;&lt;FONT color="#0000ff"&gt;Dim&lt;/FONT&gt;&lt;/FONT&gt; wcs2ucs &lt;FONT color="#0000ff"&gt;&lt;FONT color="#0000ff"&gt;As&lt;/FONT&gt;&lt;/FONT&gt;Matrix3d&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;wcs2ucs = myEd.CurrentUserCoordinateSystem.Inverse()&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;myFirstDerivative = myFirstDerivative.TransformBy(wcs2ucs)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&amp;lt;/code&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2011 09:58:20 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3265482#M57992</guid>
      <dc:creator>Balaji_Ram</dc:creator>
      <dc:date>2011-12-16T09:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: convert angle from ucs to wcs</title>
      <link>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3265774#M57993</link>
      <description>&lt;P&gt;Thanks very much Balaji.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The &lt;SPAN&gt;CurrentUserCoordinateSystem.Inverse&amp;nbsp;&lt;/SPAN&gt;function returns the desired vector for calculating the correct angle.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Frank&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2011 15:03:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/convert-angle-from-ucs-to-wcs/m-p/3265774#M57993</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-12-16T15:03:13Z</dc:date>
    </item>
  </channel>
</rss>

