The question is answered, right answer was accepted
Order of the rotations around the axes with Euler angles
According to the documentation, with Euler angles:
rotations are performed around the Z axis, the X axis, and the Y axis, in that order.
When I try to reproduce it in the inspector and with scripts, it seems that the rotation order is "YXZ", and not "ZXY".
Do you know the reason of this behaviour ? If Unity use the "YXZ" order, do you know how to convert the euler angles to "ZXY" ?
You can check the GIF files or the script below:
using UnityEngine;
public class RotationTest : MonoBehaviour
{
public Vector3 rotation;
public bool useYXZ = true;
private void Awake()
{
if (useYXZ) ApplyQuaternionYXZ();
else ApplyQuaternionZXY();
Debug.Log(transform.eulerAngles);
}
private void ApplyQuaternionYXZ()
{
transform.RotateAround(transform.position, transform.up, rotation.y);
transform.RotateAround(transform.position, transform.right, rotation.x);
transform.RotateAround(transform.position, transform.forward, rotation.z);
}
private void ApplyQuaternionZXY()
{
transform.RotateAround(transform.position, transform.forward, rotation.z);
transform.RotateAround(transform.position, transform.right, rotation.x);
transform.RotateAround(transform.position, transform.up, rotation.y);
}
}
Answer by GGsparta · Mar 31, 2020 at 05:18 PM
Rotations are performed around the global axis, not local. You can test with the following code:
transform.RotateAround(transform.position, Vector3.forward, rotation.z);
transform.RotateAround(transform.position, Vector3.right, rotation.x);
transform.RotateAround(transform.position, Vector3.up, rotation.y);
Thank you for your answer ! So if I understand well, the rotation order ZXY with global axes is equivalent to the rotation order YXZ with local axes. Interesting...
Hello Flo! I'm encountering the same problem as you. the equivalence of global ZXY and local YXZ is really interesting. Is there a mathematical proof for it?
Hi ! Nice to see that the question is useful for you
Currently you can consider it as an empirical result.
I suppose it may be proven by constructing the quaternions representing the two ways of rotating the axes, and by checking that they are equals.
The real name of what I called "Zxy" with local axes (or "Yxz" with global axes) is "roll/pitch/yaw" angles.
To calculate it, use this answer
Follow this Question
Related Questions
Quaternions to EulerAngles weird x-axis interaction 1 Answer
Quaternion.Angle() unexpected output. Compare to Vector3.Angle() which produces correct values. 0 Answers
Mirror rotation of object along 2 Euler Axis' 0 Answers
Why Quaternion from inverted Euler angles not equal to inverted Quaternion from original Euler? 1 Answer
Annoying Quaternions and Eulers 1 Answer