title: iOS ARKit - Calculate the degree of rotation of device in all three direction
body: <p>I want to get the degree of Rotation of all three axis. I am trying to achieve with landscape mode.
  When rotate device from left to right (Y-rotation), I want the degree covered once user set a left end and rotatae to right. So we need the degree 360 when it reached the starting point. So for the y-rotation, using the following calculation and it is fine. </p>
  
  <pre><code>let q = sceneView.pointOfView.orientation
  let yRotation = Float.pi - atan2f( (2*q.y*q.w)-(2*q.x*q.z), 1-(2*pow(q.y,2))-(2*pow(q.z,2)) )
  </code></pre>
  
  <p>Ref: <a href="https://stackoverflow.com/questions/54893331/getting-the-rotation-of-device-around-the-world-origins-y-axis-in-arkit">Getting the rotation of device around the world origin&#39;s y axis in ARKit</a></p>
  
  <p>Similarly, want the Z-rotation, for Z-rotation , no need for 360 degree rotation. But need accurate value when rotate about upto 90 degree
  This is fine if we use the </p>
  
  <pre><code>var zRotation = sceneView.pointOfView.eulerAngles.z
  </code></pre>
  
  <p>But this will be wrong* if we rotate the device on left to right (Y-direction ) some degree and then check the Z rotation, we will get the Z-rotation values as near to 180 degree rather than near to 0</p>
  
  <p>So tried a bad way to get the Z rotation like:</p>
  
  <pre><code>var zRotation = sceneView.pointOfView.eulerAngles.z
  if abs(sceneView.pointOfVieweulerAngles.z.toDegree) &gt; 90 {
      zRotation = (abs(cameraNode.eulerAngles.z.toDegree) - 180).toRadian
  }
  </code></pre>
  
  <p>But this is not accurate, we can see a jumb the Z-rotation value when subtracting 180. </p>
  
  <p>Could you suggest a proper method..</p>
  
  <p>X-rotation value is simialr to Z-rotation, getting values near to 180 when check after rotate left to right (Y-rotation) some degree.</p>
  
  <p>Thanks</p>
  
  <p>Edited: Sep 3, 2109
  For x and y, Now I am using</p>
  
  <pre><code>let xRotation = sceneView!.session.currentFrame!.camera.eulerAngles.x
  let zRotation = sceneView!.session.currentFrame!.camera.eulerAngles.z
  </code></pre>