Android SensorManager.java getOrientation 和 getRotationMatrix 算法
我试图弄清楚 getRotationMatrix()
和 getOrientation()
究竟是如何工作的。
到目前为止,我知道在 getRotationMatrix() 函数中,它将重力矢量与磁力矢量进行叉积,以获得指向东方的新矢量。然后,再次将东向量与重力向量进行叉积,以获得指向磁北的向量。根据这篇文章所说,现在我们有三个正交向量和我们可以形成一个旋转矩阵。
这是我的第一个问题:为什么我们应该再次将东向量与重力向量进行叉积以获得指向磁北的向量?原来的磁矢量不是指向磁北吗?新矢量与原始磁矢量有什么区别?
说到getOrientation()
,这是我的第二个问题:方位角、横滚角和俯仰角是如何得出的?有没有方程式或公式可以解释?
您可以访问此网站 看到代码
非常感谢您的关注。多谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个答案:磁矢量指向(磁)北,也可能稍微向上或向下。第二个叉积的目的是获得水平面上指向(磁)北的矢量。
第二个答案:根据该代码,滚转俯仰角和方位角是根据旋转矩阵的元素计算的,而旋转矩阵的元素又是从三个空间向量的分量导出的。乍一看,
tan(方位角) = My/Hy
sin(螺距) = -Ay
tan(roll) = -Az/Ax
(这是否是足够的答案取决于您对三角学和在 3 空间中可视化旋转的熟悉程度。)
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.)