Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SensorManager.java getOrientation and getRotationMatrix algorithm

I am trying to figure out how getRotationMatrix() and getOrientation() work exactly.

So far I've known that in getRotationMatrix() 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 article said, now we have three orthogonal vectors and we can form a rotation matrix.

Here is my first question: 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?

Speaking about the getOrientation(), here is my second question: how do the azimuth, roll and pitch come out? Are there any equations or formula for explanation?

you can go to this website to see the code

very appreciated for your attention. Thanks a lot!

like image 844
stevensyy Avatar asked Nov 15 '22 01:11

stevensyy


1 Answers

First answer: The magnetic vector points (magnetic) North and maybe also somewhat up or down. The purpose of the second cross product is to get a vector in the horizontal plane, pointing (magnetic) North.

Second answer: According to that code, roll pitch and azimuth are calculated from elements of the rotation matrix, which in turn are derived from components of the three spacial vectors. At a glance,

tan(azimuth) = My/Hy
sin(pitch) = -Ay
tan(roll) = -Az/Ax

(Whether that's sufficient answer depends on how comfortable you are with trigonometry and visualizing rotations in 3-space.)

like image 154
Beta Avatar answered Dec 09 '22 21:12

Beta