View Full Version : Matrix/vector maths.... Converting individual rotations to XYZ rotations...
I was hoping that someone with a slightly better knowledge of matrix/vector maths might be able to help me out with something....
I've got a series of vector rotations that I need to turn into a straight-forward XYZ rotation.
I've got the following at the moment:
X(A) Y(B) X(C) Y(D) X(E)
(where X(a) means rotate a radians around the X axis)
And I need to turn it into the format:
X(a) Y(b) Z(c)
I was hoping I'd be able to go via a matrix. I've got something like this coming out of the first series of rotations, but I have no idea how to convert this back to 3 rotations:
( -0.7308102 -0.3475305 -0.5874854 0.0000000
0.3475305 0.5513297 -0.7584578 0.0000000
0.5874854 -0.7584578 -0.2821400 0.0000000
0.0000000 0.0000000 0.0000000 1.0000000 )
Does anyone know either how to convert the matrix to XYZ rotations or to go from the original 5 rotations straight to XYZ?
Thanks!
|
|
UrbanFuturistic
10-31-2007, 12:47 PM
How can a double post show up minutes after you checked it handn't gone through? :shrug:
UrbanFuturistic
10-31-2007, 12:51 PM
I can sort of solve this for you, I don't know about three rotations but I know how to do it in two; It's surprisingly easy when you know what those numbers actually represent.
In a homogeneous matrix, the first three values across and down represent the vectors of the three co-ordinate axes X Y and Z, the bottom represents the position of the axes centre and the right side represents the scaling of the co-ordinates depending on their distance from the plane of the other two axes.
To try and make it a bit more clear:
[Xx][Yx][Zx][Sx]
[Xy][Yy][Zy][Sy]
[Xz][Yz][Zz][Sz]
[Xt][Yt][Zt][??]where Xx, Xy, and Xz are the XYZ co-ordinates of the X axis.
Now I have no idea how to convert this to three rotations as all that is ever required is two as at this point you can just grab the co-ordinates of an axis (-0.7308102, 0.3475305, 0.5874854) and use basic trigenometry to work out the two angles between that and (0, 0, 1) assuming that the axis is a normalised vector.
This should give you rotations around two of the three axes.
ThE_JacO
10-31-2007, 04:18 PM
what you're after is a matrix to euler rotation conversion.
go for this:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/
It's not exempt from problems though if it's animation data, and some code to handle continuous rotations will be needed on top of the straight conversion.
Thanks guys...
I posted this on the Shake SDK mailing list too (it's for a Shake plugin) and someone pointed out that there was a function in Shake that does just that:
NRiMove::extractAngles(const NRiM4d &m4, char rotationOrder, float &xAng, float &yAng, float &zAng);
That's quite convoluted code internally, though, so I'm probably just going to write it myself from what's in the link you posted, ThE_JacO.....
Thanks!
ThE_JacO
10-31-2007, 07:00 PM
yeah, most SDKs that handle linear algebra will deal with it one way or another.
the code in the link is convoluted, but I think it's meant to verbosely execute to show the process. The maths behind it are correct though.
Robert Bateman
11-01-2007, 05:47 PM
what you're after is a matrix to euler rotation conversion.
go for this:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/
It's not exempt from problems though if it's animation data, and some code to handle continuous rotations will be needed on top of the straight conversion.
Don't use that code. use the ken shoemake code... ;)
http://gypsy.rose.utoronto.ca/people/david_dir/GEMS/GEMS.html
you still have to handle the cases where angles wrap from -180 to +180 though....
Bolt1
11-02-2007, 04:36 AM
Graphics Gems is pretty good. I recommend it.
Bolt1
11-02-2007, 05:03 AM
This works for me:
// fill M with your own data
HMatrix M; // Right-handed, for column vectors
EulerAngles ea;
ea = Eul_FromHMatrix( M, EulOrdXYZs );
// angles returned as radians
Kuroyume0161
11-07-2007, 02:58 AM
The problem with any of these 'matrix decomposition' methods is that you get back mostly Euler rotation equivalents - and the great sacrifice of one of the rotations (usually z-axis) to the great god of null (0.0f). In many cases this is acceptable, but in cases where you are working with hierarchies, the results will be nice and disastrous. There is no way to retrieve exact Euler representations due to the intermixing dependencies of two of the rotations (one of them is directly extractable, that's it).
If the conversion can be done heuristically (based upon previous, known Euler angles), check out this link:
http://www.allyourpixel.com/post/well-behaved-euler-angles/ (http://www.allyourpixel.com/post/well-behaved-euler-angles/)
Shoemake's code is, put euphemistically, 'terse'. He might be a master of quaternions, but he couldn't program himself out of a paper bag (without compressing all of the possible permutations of paper bag into an incomprehensible obfuscation). ;P Dave Eberly's code is much more concise and readable - although not as expansive.
http://www.geometrictools.com/Documentation/EulerAngles.pdf (http://www.geometrictools.com/Documentation/EulerAngles.pdf)
If you can avoid Euler angle representations of rotations, by all means do so. I have the priviledge of not having a choice in the matter.
CGTalk Moderation
11-07-2007, 02:58 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.