thecountoftuscany / PyTeapot-Quaternion-Euler-cube-rotation

Visualization of IMU orientation from quaternion or Euler angles with a rotating cube
GNU General Public License v3.0
144 stars 42 forks source link

Quaternion calculation #4

Closed lolodenimes closed 3 years ago

lolodenimes commented 4 years ago

is the calculation correct? On your code: yaw = math.atan2(2.0 (q[1] q[2] + q[0] q[3]), q[0] q[0] + q[1] q[1] - q[2] q[2] - q[3] q[3]) pitch = -math.sin(2.0 (q[1] q[3] - q[0] q[2])) roll = math.atan2(2.0 (q[0] q[1] + q[2] q[3]), q[0] q[0] - q[1] q[1] - q[2] q[2] + q[3] q[3]) And on wikipedia for example: yaw = atan2(2 (q0 q3 + q1 q2), 1 - 2 (q2 q2 + q3 q3)); pitch = asin( 2 (q0 q2 - q3 q1)); roll = atan2(2 (q0 q1 + q2 q3),1 - 2 (q1 q1 + q2 q2));

thecountoftuscany commented 3 years ago

These forms are equivalent since the sum of squares of quaternions is 1 and sin() is an odd function. Refer this page.