title: How to get the Z,Y,X Rotation of Android/iOS Device in React Native? (Pitch,Yaw,Roll)?
body: <p>I tried using: &quot;react-native-sensors&quot; library</p>
  <p><a href="https://github.com/react-native-sensors/react-native-sensors/blob/master/docs/API.md#orientation-observableqx-number-qy-number-qz-number-qw-number-pitch-number-roll-number-yaw-number-timestamp-string" rel="nofollow noreferrer">https://github.com/react-native-sensors/react-native-sensors/blob/master/docs/API.md#orientation-observableqx-number-qy-number-qz-number-qw-number-pitch-number-roll-number-yaw-number-timestamp-string</a></p>
  <pre><code>import { orientation } from &quot;react-native-sensors&quot;;
  
  const subscription = orientation.subscribe(({ qx, qy, qz, qw, pitch, roll, yaw, timestamp }) =&gt;
      console.log({ qx, qy, qz, qw, pitch, roll, yaw, timestamp })
  );
  </code></pre>
  <p>I tried using their given pitch,roll,yaw and converted from radian_to_degress still not the same values as the emulator.</p>
  <p>They also provide a quaternion to Angles function</p>
  <pre><code>function quaternionToAngles(q) {
      let data = q;
  
      let ysqr = data.y * data.y;
      let t0 = -2.0 * (ysqr + data.z * data.z) + 1.0;
      let t1 = +2.0 * (data.x * data.y + data.w * data.z);
      let t2 = -2.0 * (data.x * data.z - data.w * data.y);
      let t3 = +2.0 * (data.y * data.z + data.w * data.x);
      let t4 = -2.0 * (data.x * data.x + ysqr) + 1.0;
  
      t2 = t2 &gt; 1.0 ? 1.0 : t2;
      t2 = t2 &lt; -1.0 ? -1.0 : t2;
  
      const toDeg = 180 / Math.PI;
  
      const euler = {};
      euler.pitch = Math.asin(t2) * toDeg;
      euler.roll = Math.atan2(t3, t4) * toDeg;
      euler.yaw = Math.atan2(t1, t0) * toDeg;
  
      return euler;
  }
  </code></pre>
  <p>The function gives wrong results for roll,yaw and pitch. I dont want to dive into the Math of this. google searching gives 100x different equations.</p>
  <p><a href="https://i.stack.imgur.com/3Nn9s.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3Nn9s.png" alt="enter image description here" /></a></p>
  <p>Im searching for simple equations to get the Z,Y,X Rotations of my Device just like the Android Emulator provides. If Z-Rot Value is &quot;90&quot;(on emulator) my program should also receive the same value. I have access to gyrometer,barometer,accelometer etc.</p>
  <p>PS: I wasted way to much time on google for a problem that should be solvable with a copy paste after one google search so I hope this question will help.</p>