Open FiorixF1 opened 4 years ago
My two cents: more options might mean more confusion: Euler angles are horrible and you don't need them. I'd even vote to remove them.
how do we decide if it's a left or right handed system. Also, is the rotation order specified somewhere.
Hi, I saw that this library offers the function
yaw_pitch_roll
to get the Euler angles from a quaternion. However I see they are calculated based on a fixed application of the rotations (I guess XYZ). When using this library, I had the necessity to calculate these angles with respect to a different rotation order (YXZ). Looking deeply on the internet, I found this wonderful paper where a guy explains how to convert from a quaternion to Euler angles for EVERY possible rotation order. https://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/Quaternions.pdfTo make it short, a quaternion Q is represented by four numbers p0, p1, p2, p3 where p0 is always Q.w while p1, p2, p3 are the components of the quaternion with respect of rotation order (e.g. if the rotation order is XYZ then p1 = Q.x, p2 = Q.y, p3 = Q.z, if the rotation order is ZYX then p1 = Q.z, p2 = Q.y, p3 = Q.x...) plus a variable "e" which equals 1 for right handed systems and -1 for left-handed systems. The three angles alpha, beta, gamma are then calculated as:
alpha = asin(2*(p0*p2 + e*p1*p3))
beta = atan2(2*(p0*p1 - e*p2*p3), 1-2*(p1**2 + p2**2))
gamma = atan2(2*(p0*p3 - e*p1*p2), 1-2*(p2**2 + p3**2))
and it magically works.
This could be implemented in the library by adding a parameter to
yaw_pitch_roll
expressing the rotation order (it could be optional for backward compatibility).