Question about ROLL angle for a sensor as produced by Euler angles and Quaternions compared.
We rotated an mbient sensor around the x – axis to simulate ROLL. We collected Euler angles and
Quaternions at 100 samples/second. We calculated Euler angles from Quaternions (roll from
quaternions, pitch from quaternions and yaw from quaternions and plotted them together with the
Euler angles, roll, pitch, and yaw.
What we observe is that Euler angle PITCH corresponds with ROLL angle calculated from Quaternions
and Euler angle ROLL corresponds with PITCH angle calculated from Quaternions.
We used the following vectorized python code to convert Quaternions to Euler angles:
def quaternion_to_euler_angle_vectorized1(w, x, y, z):
ysqr = y * y
t0 = +2.0 * (w * x + y * z)
t1 = +1.0 - 2.0 * (x * x + ysqr)
X = np.degrees(np.arctan2(t0, t1))
t2 = +2.0 * (w * y - z * x)
t2 = np.where(t2>+1.0,+1.0,t2)
# t2 = +1.0 if t2 > +1.0 else t2
t2 = np.where(t2<-1.0, -1.0, t2)
# t2 = -1.0 if t2 < -1.0 else t2
Y = np.degrees(np.arcsin(t2))
t3 = +2.0 * (w * z + x * y)
t4 = +1.0 - 2.0 * (ysqr + z * z)
Z = np.degrees(np.arctan2(t3, t4))
return X, Y, Z