<?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: Getting blocs &amp;amp; solids rotation angle in 3D space in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/6868455#M59515</link>
    <description>&lt;P&gt;Hello Philippe,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your code in Autodesk Inventor. But I get everytime a wrong value for the z-angle. It is 180 opposite - for example it should be 180 and it is 0 or -180 and is 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Georg&lt;/P&gt;</description>
    <pubDate>Fri, 10 Feb 2017 10:45:50 GMT</pubDate>
    <dc:creator>GeorgK</dc:creator>
    <dc:date>2017-02-10T10:45:50Z</dc:date>
    <item>
      <title>Getting blocs &amp; solids rotation angle in 3D space</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3140470#M59511</link>
      <description>&lt;P&gt;Hi to all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In .NET environment I'm seeking a method to detect the orientation (rotation angle) of blocs and solids in 3D space through the X,Y and Z axis.&lt;/P&gt;&lt;P&gt;There is a object.method? or a procedure?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks to all﻿&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2011 08:51:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3140470#M59511</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-08-30T08:51:01Z</dc:date>
    </item>
    <item>
      <title>Re: Getting blocs &amp; solids rotation angle in 3D space</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3140494#M59512</link>
      <description>&lt;P&gt;Hi Luigi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no direct way to retrieve this information from the API, however concerning BlockReferences you could use the "BlockReference.BlockTransform" property that returns a 3d matrix and compute those angles (called Euler angles) yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example of such a computation is illustrated by the code below. Unfortunately it applies to Inventor, but you will be able to invoke equivalent methods from the ARX.Net API on the Matrix3d object.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Concerning Solid3d, this class doesn't expose a transformation property or equivalent information, so unless you created the solid aligned with (X,Y,Z) axis and keep track of any transformation that is applied to it (by keeping a total transformation matrix up-to-date each time the solid is transformed), you won't be able to determine anything about its orientation in space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the Inventor solution to retrieve the matrix angles:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we look at the properties of a part in an assembly, we can see the x,y,z coordinates and angles. How can we get the angle values via API?&lt;/P&gt;
&lt;DIV class="clear"&gt;
&lt;DIV&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;STRONG&gt;Solution&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;P&gt;&lt;SPAN class="681334909-02082005"&gt;There is no direct way to get these angles via API. However, it should be possible to get them via the 4x4 homogeneous transformation matrix.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;t11&amp;nbsp;&amp;nbsp; t12&amp;nbsp;&amp;nbsp; t13&amp;nbsp;&amp;nbsp; tx&lt;BR /&gt;t21&amp;nbsp;&amp;nbsp; t22&amp;nbsp;&amp;nbsp; t23&amp;nbsp;&amp;nbsp; ty&lt;BR /&gt;t31&amp;nbsp;&amp;nbsp; t32&amp;nbsp;&amp;nbsp; t33&amp;nbsp;&amp;nbsp; tz&lt;BR /&gt;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;tx, ty, and tz represent the translations along x, y, and z directions.&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;From the values of other elements of the matrix, one can get the Eulerian/ Cardanian angles. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Public Function Acos(value) As Double
    Acos = Math.Atn(-value / Math.Sqr(-value * value + 1)) + 2 * Math.Atn(1)
End Function

Sub CalculateRotationAngles(ByVal oMatrix As Inventor.Matrix, ByRef aRotAngles() As Double)
    Const PI = 3.14159265358979
    Const TODEGREES As Double = 180 / PI
 
    Dim dB As Double
    Dim dC As Double
    Dim dNumer As Double
    Dim dDenom As Double
    Dim dAcosValue As Double
        
    Dim oRotate As Inventor.Matrix
    Dim oAxis As Inventor.Vector
    Dim oCenter As Inventor.Point
    
    Set oRotate = ThisApplication.TransientGeometry.CreateMatrix
    Set oAxis = ThisApplication.TransientGeometry.CreateVector
    Set oCenter = ThisApplication.TransientGeometry.CreatePoint

    oCenter.X = 0
    oCenter.Y = 0
    oCenter.Z = 0

    '
    ' Choose aRotAngles[0] about x which transforms axes[2] onto the x-z plane
    '
    dB = oMatrix.Cell(2, 3)
    dC = oMatrix.Cell(3, 3)
 
    dNumer = dC
    dDenom = Sqr(dB * dB + dC * dC)
 
    ' Make sure we can do the division.  If not, then axes[2] is already in the x-z plane
    If (Abs(dDenom) &amp;lt;= 0.000001) Then
        aRotAngles(0) = 0#
    Else
        If (dNumer / dDenom &amp;gt;= 1#) Then
            dAcosValue = 0#
        Else
            If (dNumer / dDenom &amp;lt;= -1#) Then
                dAcosValue = PI
            Else
                dAcosValue = Acos(dNumer / dDenom)
            End If
        End If
    
        aRotAngles(0) = Sgn(dB) * dAcosValue
        oAxis.X = 1
        oAxis.Y = 0
        oAxis.Z = 0
  
        Call oRotate.SetToRotation(aRotAngles(0), oAxis, oCenter)
        Call oMatrix.PreMultiplyBy(oRotate)
    End If
 
    '
    ' Choose aRotAngles[1] about y which transforms axes[3] onto the z axis
    '
    If (oMatrix.Cell(3, 3) &amp;gt;= 1#) Then
        dAcosValue = 0#
    Else
        If (oMatrix.Cell(3, 3) &amp;lt;= -1#) Then
            dAcosValue = PI
        Else
            dAcosValue = Acos(oMatrix.Cell(3, 3))
        End If
    End If
 
    aRotAngles(1) = Math.Sgn(-oMatrix.Cell(1, 3)) * dAcosValue
    oAxis.X = 0
    oAxis.Y = 1
    oAxis.Z = 0
    Call oRotate.SetToRotation(aRotAngles(1), oAxis, oCenter)
    Call oMatrix.PreMultiplyBy(oRotate)
 
    '
    ' Choose aRotAngles[2] about z which transforms axes[0] onto the x axis
    '
    If (oMatrix.Cell(1, 1) &amp;gt;= 1#) Then
        dAcosValue = 0#
    Else
        If (oMatrix.Cell(1, 1) &amp;lt;= -1#) Then
            dAcosValue = PI
        Else
            dAcosValue = Acos(oMatrix.Cell(1, 1))
        End If
    End If
 
    aRotAngles(2) = Math.Sgn(-oMatrix.Cell(2, 1)) * dAcosValue
 
    'if you want to get the result in degrees
    aRotAngles(0) = aRotAngles(0) * TODEGREES
    aRotAngles(1) = aRotAngles(1) * TODEGREES
    aRotAngles(2) = aRotAngles(2) * TODEGREES
End Sub


&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This&amp;nbsp;code example is based on the theory from &lt;A href="http://kwon3d.com/theory/euler/euler_angles.html" target="_blank"&gt;http://kwon3d.com/theory/euler/euler_angles.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;Philippe Leefsma&lt;/EM&gt;&lt;/STRONG&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;Developer Consultant&lt;/EM&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;Developer Technical Services&lt;/EM&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;A href="http://www.autodesk.com/joinadn" target="_blank"&gt;www.autodesk.com/joinadn&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 30 Aug 2011 10:12:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3140494#M59512</guid>
      <dc:creator>philippe.leefsma</dc:creator>
      <dc:date>2011-08-30T10:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting blocs &amp; solids rotation angle in 3D space</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3140514#M59513</link>
      <description>&lt;P&gt;Thank-you Philippe for the answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will try the solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2011 10:57:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3140514#M59513</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2011-08-30T10:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Getting blocs &amp; solids rotation angle in 3D space</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3301723#M59514</link>
      <description>&lt;P&gt;good stuff. I need to work out how to set the tx,ty,tz.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2012 03:14:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/3301723#M59514</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2012-01-21T03:14:48Z</dc:date>
    </item>
    <item>
      <title>Re: Getting blocs &amp; solids rotation angle in 3D space</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/6868455#M59515</link>
      <description>&lt;P&gt;Hello Philippe,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your code in Autodesk Inventor. But I get everytime a wrong value for the z-angle. It is 180 opposite - for example it should be 180 and it is 0 or -180 and is 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Georg&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 10:45:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/6868455#M59515</guid>
      <dc:creator>GeorgK</dc:creator>
      <dc:date>2017-02-10T10:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Getting blocs &amp; solids rotation angle in 3D space</title>
      <link>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/6869263#M59516</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/241746"&gt;@GeorgK&lt;/a&gt;&amp;nbsp;- you should start a new thread for this.&amp;nbsp; Anyways, be aware that not all programs use the Z-axis as "world up".&amp;nbsp; Its very common for mechanical design programs like Inventor&amp;nbsp;to use Z-axis as "depth" and Y-axis as "up".&amp;nbsp; You need to construct the transform relative to the space you are working with.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Feb 2017 15:43:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/getting-blocs-amp-solids-rotation-angle-in-3d-space/m-p/6869263#M59516</guid>
      <dc:creator>dgorsman</dc:creator>
      <dc:date>2017-02-10T15:43:12Z</dc:date>
    </item>
  </channel>
</rss>

