title: 3d Accelerometer calculate the orientation
body: <p>I have accelerometer values for the 3 axes (usually when there is only gravity contains data  between -1.0 and 1.0 ):</p>
  
  <pre><code>  float Rx;
    float Ry;
    float Rz;
  </code></pre>
  
  <p>I make some calculations, then I get the angles for each axis.</p>
  
  <pre><code>  float R =  sqrt(pow(Rx,2)+pow(Ry,2)+pow(Rz,2));
    float Arx = acos(Rx/R)*180/M_PI;
    float Ary = acos(Ry/R)*180/M_PI;
    float Arz = acos(Rz/R)*180/M_PI;
  </code></pre>
  
  <p>Then I set the values for the box angles in opengl</p>
  
  <pre><code>rquad = Arx;
  yquad = Ary;
  </code></pre>
  
  <p>Which rotates my box:</p>
  
  <pre><code>glRotatef(yquad,1.0f,0.0f,0.0f);
  glRotatef(rquad,0.0f,1.0f,0.0f);
  </code></pre>
  
  <p>It works on a hemisphere. I would like to use the full sphere and I know that I have to use the Arz value to make it work, but I don't know how can I use that for this rotation. Could you help me?</p>
  
  <p>Update:
  The final answer is in my case:</p>
  
  <pre><code>  rquad = -atan2(Rx/R, Rz/R)*180/M_PI;
    yquad = -atan2(Ry/R, Rz/R)*180/M_PI;
  </code></pre>