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

Getting blocs & solids rotation angle in 3D space

5 REPLIES 5
Reply
Message 1 of 6
Luigi71
7451 Views, 5 Replies

Getting blocs & solids rotation angle in 3D space

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

5 REPLIES 5
Message 2 of 6
philippe.leefsma
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?

 
Solution

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


 

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

 

Philippe Leefsma
Developer Consultant
Developer Technical Services
  

www.autodesk.com/joinadn

 

 



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 6
Luigi71
in reply to: philippe.leefsma

Thank-you Philippe for the answer.

 

I will try the solution.

 

Message 4 of 6
cean_au
in reply to: Luigi71

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

Message 5 of 6
GeorgK
in reply to: philippe.leefsma

Hello Philippe,

 

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

 

Thanks

 

Georg

Message 6 of 6
dgorsman
in reply to: GeorgK

@GeorgK - you should start a new thread for this.  Anyways, be aware that not all programs use the Z-axis as "world up".  Its very common for mechanical design programs like Inventor to use Z-axis as "depth" and Y-axis as "up".  You need to construct the transform relative to the space you are working with.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


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