Hallo zusammen,
ich arbeite mich gerade in die Transformationen beim Inventor ein. Gibt es noch andere Beispiele?
http://forums.autodesk.com/t5/net/getting-blocs-amp-solids-rotation-angle-in-3d-space/td-p/3140470
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
http://modthemachine.typepad.com/files/mathgeometry.pdf
http://aucache.autodesk.com/au2011/sessions/5840/class_handouts/v1_MA5840_Ekins.pdf
http://www.geometrictools.com/Source/Mathematics.html
Vielen Dank
Georg
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP