问题
When transforming a quaternion to Euler Angles, usually there has to be a order in which the axes are rotated, like in this visualization.
How does it work for libgdx?
The Quaternion class has the functions
getRoll():
Math.asin(MathUtils.clamp(2f * (w*x - z * y), -1f, 1f)) :
(float)pole * MathUtils.PI * 0.5f;`
getPitch():
Math.asin(MathUtils.clamp(2f * (w*x - z * y), -1f, 1f)) :
(float)pole * MathUtils.PI * 0.5f;`
getYaw():
`
MathUtils.atan2(2f * (y * w + x * z), 1f - 2f * (y * y + x * x)) : 0f;`
Where is the order of the resulting angles set, which axes is rotated first,second,third ?
How are these functions related to a quaternion rotation matrix like:
Why is it that often this Rotationmatrix is given as Inverse /Transposed (equal because of orthogonality) ?
回答1:
Rotation order
There are 12 possible orders of rotations possible for using an angle triplet for orientation.
Six of them are called Proper Euler angles, and rest six are called Tait–Bryan angles.
Read more here
Libgdx uses the following order.
- Rotate by yaw about Y
- Elevate by pitch towards Y
- Rotate by roll about obtained direction
Rotation Matrix
Rotation matrices, Quaternions, Euler angles and Axis-Angle representation are different ways to encode rotation/orientation.
They often trade off between storage space and computation cost.
They can be freely converted into each other by means of well defined equations, one of which you mentioned. So these conversion expressions are related to each other.
Edit Thanks for pointing out the mistake. It is indeed about Y axis not Z.
I have verified it from the source code.
Libgdx uses coordinate system of bullet physics engine. In that system, XZ plane is considered horizontal and Y is considered upwards (not Z). This was the root of my mistake.
来源:https://stackoverflow.com/questions/41633455/rotation-order-for-eulers-getpitch-getroll-getyaw-from-quaternion-in-lib