Posts: 22
Registered: ‎08-30-2011
Message 1 of 4 (389 Views)

Getting blocs & solids rotation angle in 3D space

389 Views, 3 Replies
08-30-2011 01:51 AM

Hi to all.


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.

There is a object.method? or a procedure?


Thanks to all

ADN Support Specialist
Posts: 561
Registered: ‎06-02-2009
Message 2 of 4 (386 Views)

Re: Getting blocs & solids rotation angle in 3D space

08-30-2011 03:12 AM in reply to: Luigi71

Hi Luigi,


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.


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.


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.


Here is the Inventor solution to retrieve the matrix angles:


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?


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.
t11   t12   t13   tx
t21   t22   t23   ty
t31   t32   t33   tz
0      0      0     1
tx, ty, and tz represent the translations along x, y, and z directions.
From the values of other elements of the matrix, one can get the Eulerian/ Cardanian angles.



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) <= 0.000001) Then
        aRotAngles(0) = 0#
        If (dNumer / dDenom >= 1#) Then
            dAcosValue = 0#
            If (dNumer / dDenom <= -1#) Then
                dAcosValue = PI
                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) >= 1#) Then
        dAcosValue = 0#
        If (oMatrix.Cell(3, 3) <= -1#) Then
            dAcosValue = PI
            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) >= 1#) Then
        dAcosValue = 0#
        If (oMatrix.Cell(1, 1) <= -1#) Then
            dAcosValue = PI
            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


This code example is based on the theory from http://kwon3d.com/theory/euler/euler_angles.html


Philippe Leefsma
Developer Consultant
Developer Technical Services




Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Posts: 22
Registered: ‎08-30-2011
Message 3 of 4 (383 Views)

Re: Getting blocs & solids rotation angle in 3D space

08-30-2011 03:57 AM in reply to: philippe.leefsma

Thank-you Philippe for the answer.


I will try the solution.


Valued Contributor
Posts: 100
Registered: ‎07-11-2011
Message 4 of 4 (290 Views)

Re: Getting blocs & solids rotation angle in 3D space

01-20-2012 07:14 PM in reply to: Luigi71

good stuff. I need to work out how to set the tx,ty,tz.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community