I have a 3D point and the x,y,z rotations (qInitial
) for that point.
I want to rotate that point more (by some degrees that could be 0 up to 360) around y axis (qYextra
). How can I calculate the final Euler rotation (qResult.eulerAngles
) that is a combination of these 4 rotations (x-y-z-y)?
I have tried calculating the initial quaternion rotation, and the extra rotation to be applied. And then multiply these two quaternions. However, I get weird results (probably gimbal lock).
Code in C#. Unity.
1.Quaternion qX = Quaternion.AngleAxis(rotationFromBvh.x,Vector3.right);
2.Quaternion qY = Quaternion.AngleAxis(rotationFromBvh.y,Vector3.up);
3.Quaternion qZ = Quaternion.AngleAxis(rotationFromBvh.z,Vector3.forward);
4.Quaternion qYextra = Quaternion.AngleAxis(angle,Vector3.up);
Quaternion qInitial = qY * qX * qZ; // Yes. This is the correct order.
qY*qX*qZ
has exactly the same Euler x,y,z results asQuaternion.Euler(rotationFromBvh)
Quaternion qResult = qInitial * qYextra;
return qResult.eulerAngles;
I can confirm that the code works fine (no gimbal lock) when 4th rotation is 0 degrees (qYextra = identity
). Meaning that qInitial
is correct. So, the error might be due to the combination of those 2 rotations (qInitial
and qYextra
) OR due to the convertion from Quaternion to Euler.
Any suggestions? I haven't yet found a solution, and probably I won't.