- Home /
Split quaternion into multiple angle-axis rotations for hierarchical ordered appliance
Hi,
I want to split an arbitrary rotation into multiple rotations and apply them to 3 hierarchly ordered axles consecutive.
Which means that the first axle (x) is in the hierarchy at top. Under that is axle 2 (y) und last is axle 3 (z). This order is not be set in stone, in fact I rather want arbitrary axis, e.g. x, z, -y. They can be orthogonal at least ;-)
In the end, the rotation should be performed by this construct (call it a robot arm or something) by letting each axle only rotate around it's defined angle. I know that one could hack such behaviour for certain applications, but in this case it is for pure research.
My first attempt was to convert the arbitrary rotation (for testing purpose I made a look-at rotation) into Euler angles, however, i am not sure which order is used in unity for appliance of those angles, and it seems that it is not x -> y -> z. (I think it's yxz ?) I also tried the angle-axis conversion and multiplied each component of the axis with the angle and put that portion to the corresponding axle. Don't work either.
I know that one can describe the rotation of the resulting rotation of the construct by: R = Rx*Ry*Rz with the single rotations being rotations matrices or quaternions. To trace back one multiply the other way around: R' = Rz*Ry*Rx, this is probably what I want. But than again, how to split the rotation components to the single axles? I actually have some creepy formulas for that, but I want to confirm these by an alternative approach (using the unity engine internal methods for example).
Right now, I'm looking into http://answers.unity3d.com/questions/737725/how-to-reverse-quaternion-multiplication.html, which seems a good start... but it would be nice to find a way using the built-in rotation methods of unity instead of hassle around with such "low level" formulas, especially as an backup for confirmation.
I attached my simple playground scene in case someone wants to try for itself.
Answer by Eno-Khaon · Feb 23, 2016 at 12:52 AM
Incidentally, I *just* happened to dig up information pertaining to your question under the topic "Invert quaternion rotation", so I'm more than happy to assist here as well.
Unity applies Euler rotation calculations in the order Z-X-Y
If you consider the axis each of the three would rotate around, X rotations occur relative to Vector3.right, Y rotations occur relative to Vector3.up, and Z rotations occur relative to Vector3.forward.
With this in mind, recreating rotations to match Unity's can be done using something like this:
Vector3 v = transform.eulerAngles; // Example rotation
Quaternion q = Quaternion.AngleAxis(v.y, Vector3.up) * Quaternion.AngleAxis(v.x, Vector3.right) * Quaternion.AngleAxis(v.z, Vector3.forward); // Same rotation
Using this basis for rotation reconstruction, you can separate each rotation angle to be applied to its respective axis.
Yeah...exactly this "separation" gives my a hard time. I know that one can solve a linear equation system with 3 variables, but that would be different for each coordinate system/rotation axles. If this is the only way... well so be it, but I thought there might be a different way.
Thanks for clarifying the rotation order.
Answer by unity_b0Dq6nOtRN55SQ · Feb 26, 2018 at 03:17 AM
This is exactly what I am struggling with for a satellite tracking controller. Working with quaternion, I know the rotation to point to the satellite. I know the current posiotion, from which I can calculate a correction quaternion. But how to devolve that correction into its component axial part to drive the orthogonal axis motors. Any hints?,This is exactly what I am struggling with for a satellite tracking controller. I know the resultant rotation I need to point to the satellite. I know where I am currently pointing, I know the correction required to my current position all calculated in quaternions. However now I need to devolve the correction quaternion to apply it to my distinct, orthogonal axis motor. I’m a bit lost at this point.
Answer by Azial · Feb 26, 2018 at 01:42 PM
Actually, I solved this a while ago now. The steps to do something like this are as follows:
Build your wanted rotation (e.g. point to) and convert it to a rotation matrix
Describe your motors rotation model by axis-angle rotation matrices with the inner-most axis to the right and the outer-most axis to the left
Calculate this the composition rotation matrix by hand (you need the analytical form)
Pick the axis angles from the matrix's elements (the elements are terms like sin(angle), so calculate angle using asin(mat[row,column]))
Example:
I did this one in the Blender game engine. As Blender has a right-handed coord-system, you might need to adjust this to Unity.
Say we have a robot model with 3 axis. The outer axis (highest in hierarchy) points in x direction and rotates by angle "oa", the middle axis points in y direction and rotates by angle "ma" and the inner axis points in z direction and rotates by angle "ia". We want the robot to perform an arbitray rotation (described as a rotation matrix related to the same coord-system of course). To do that, we need to set the angles "oa", "ma" and "ia" of the axes.
We build the analytical rotation matrix of the robot composed of 3 angle-axis rotation matrices:
R = Rx("oa") * Ry("ma") * Rz("ia")
Fortunately, someone already had calculated this matrix for us, but it wouldn't be that hard to calculate it. It is just multiplication of standard rotation matrices (remember: starting from right).
The angles can now be extracted as:
ma = asin(R[0][2])
ia = -atan2(R[0][1], R[0][0])
oa = -atan2(R[1][2], R[2][2])
Note that this is not a general solution. It works only for this model. For an 4-axes robot, or a robot that has its axes in different order (e.g. x -> z -> y), you need to follow the steps above.
Also mind the conversion of radians and degrees. Math library functions like sin, asin, ... usually work in radians.
Your answer
![](https://koobas.hobune.stream/wayback/20220612065243im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
need my object to rotate between specific angles on the x axis 2 Answers
Prevent child rotation but still control it yourself 1 Answer
Top down camera always facing north - avoid residual rotation 1 Answer
Clamping rotation undesired effects. 1 Answer
Quaternions; how do I rotate an object around only 2 axis based on another rotation? 1 Answer