title: Android SensorManager.java getOrientation and getRotationMatrix algorithm
body: <p>I am trying to figure out how <code>getRotationMatrix()</code> and <code>getOrientation()</code> work exactly.</p>
  
  <p>So far I've known that in <code>getRotationMatrix()</code> function it crossproducts the gravity vector with the magnetic vector to get the new vector pointing to the East. And then , it crossproducts the East vector with the gravity vector again to get the vector pointing to the magnetic north. According to this <a href="http://www.physicsforums.com/archive/index.php/t-333207.html" rel="nofollow">article</a> said, now we have three orthogonal vectors and we can form a rotation matrix. </p>
  
  <p>Here is my <strong>first question</strong>: Why we should crossproduct the East vector with gravity vector again to get a vector pointing the magnetic north? Isn't the original magnetic vector pointing the magnetic north? what are the difference between new vector and the original magnetic vector?</p>
  
  <p>Speaking about the <code>getOrientation()</code>, here is my <strong>second question</strong>: how do the azimuth, roll and pitch come out? Are there any equations or formula for explanation?</p>
  
  <p>you can go to this <a href="http://gitorious.org/android-eeepc/base/blobs/9cb3e09ec49351401cf19b5ae5092dd9ca90a538/core/java/android/hardware/SensorManager.java" rel="nofollow">website</a>  to see the code    </p>
  
  <p>very appreciated for your attention. Thanks a lot!    </p>