Compute Rotation and Scale from Transform Object
-
I did delete the rotX/Y/Z methods, that's why I didn't understand where the variable xyz came from and why it could get value = 0/1/2. I do understand how methods with there variables work. Sorry was confused.
On the other hand, I have been working with the euler_angle method for a while and now that I'm closely getting to a complete script I have noticed this method only partial works (for me?). Does it work for you guys? When I did draw shapes with a given rotation, the method didn't succeed to calculate the right angles for me so I did some research and made some changes. Here's the code I use:
def self.rotation(trans) b = [trans.xaxis.to_a, trans.yaxis.to_a, trans.zaxis.to_a] m = b.transpose.flatten! if m[6] != 1 and m[6] != -1 ry = -Math.asin(m[6]) rx = Math.atan2(m[7]/Math.cos(ry),m[8]/Math.cos(ry)) rz = Math.atan2(m[3]/Math.cos(ry),m[0]/Math.cos(ry)) else rz = 0 phipos = Math.atan2(m[1],m[2]) phineg = Math.atan2(-m[1],-m[2]) if m[6] == -1 ry = Math;;PI/2 rx = rz + phipos else ry = -Math;;PI/2 rx = -rz + phineg end end return [rx.radians,ry.radians,rz.radians] end
First I found this document (page 5) that explains the calculations the way you do it. But it seems that you miss little pieces of code to make it complete.
When I did calculate the angles it yet didn't calculate the right angles. So I did try some things and found out that the angles that were calculated represent the transpose matrix of the rotation that I need. So I fixed this by transposing the rotation matrix before the calculations.
With these changes this piece of code does calculate the right angles. Did your code work for you?
-
You realize that this topic thread is like 4 and 1/2 years old ?
-
@dan rathbun said:
You realize that this topic thread is like 4 and 1/2 years old ?
Yes, I have seen it. That does not mean that people can't come here and look for code that works? That's how I landed here. I was looking for some code that could convert the rotation matrix to euler angles. I found out that this code didn't work for me, so I did correct it and now I share it here just in case people experience the same problem as me. I'm just excited that I finally can contribute a little instead of always asking things!
Nothing wrong with that, right?
-
-
Hello transformation gurus!
just to double check the euler_angle(xyz=[]) method ... is the condition:
if m[6] != 1 and m[6]!= 1
at the beginning correct? Why double checking the same variable against the same value? Or is it meant to be:
if m[6] != 1 and m[6]!= -1
?
Cheers,
Jernej -
An olde typo - use 1 for the second test...
Advertisement