iPhone - CLHeading:如何将 trueHeading 转换为矢量
我知道如何获取磁航向的坐标:heading.x、heading.y、heading.z 问题是我需要 trueHeading 的 (x, y, z) 向量。我怎样才能创建这个向量?
谢谢你!
I know how to get the coordinates of the magnetic heading: heading.x, heading.y, heading.z
The thing is that I'd need the (x, y, z)-vector of the trueHeading. How can I create this vector?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:我已经改变了我的答案很多......
基本上你需要以与磁偏角角度。
困难的部分是您需要在水平面上旋转矢量。为此,您需要知道手机的方向。
以下是您需要执行的操作:
获取磁北矢量。
从加速度计获取重力矢量。
现在计算/查找磁偏角(这取决于您在世界上的位置,并且它也会随时间缓慢变化)。
将磁北向量绕重力向量旋转 X 度(其中 -X = 磁偏角) )。这将是棘手的部分,您需要温习一些 3D 三角。
Edit: I have changed my answer quite a bit...
Basically you need to rotate the magnetic north vector in the opposite direction to the Magnetic Declination angle.
The hard part is that you need to rotate the vector on a horizontal plane. For that you need to know the orientation of the phone.
Here is what you need to do:
Get the magnetic north vector.
Get the gravity vector from the accelerometer.
Now calculate / look up the Magnetic Declination (it depends where you are in the world and it also varies slowly with time).
Rotate the magnetic north vector X degrees about the gravity vector (where -X = Magnetic Declination). This will be the tricky part, you will need to brush up on some 3d trig.
感谢您的编辑...有趣,这正是我当时所做的。我获取了磁北向量,并使用旋转矩阵围绕重力向量旋转它,并在磁航向和真实航向之间进行变化。
问题是在这种情况下我依赖于磁矢量。
在某些情况下,我注意到磁矢量变得绝对疯狂,并且传感器提供了奇怪的值。
所以我想要的是获得独立于磁向量的 trueHeading 向量。好吧,多么愚蠢的想法——真正的航向很可能已经依赖于磁航向了。
不过-谢谢你的回答:)
Thank's for the edit...funny, that's exactly what I did then. I took the magnetic north vector and rotated it with a rotation matrix around the gravity vector with the variation between the magneticHeading and the trueHeading.
The thing is that I'm dependent on the magnetic vector in this case.
In some situations I noticed that the magnetic vector was going absolutely crazy and the sensor delivered weird values.
So what I wanted is to get the vector of the trueHeading which is independent from the magnetic vector. Ok, what a silly thought - the true heading is most probably anyway dependent on the magnetic heading already.
However - thank's for the answer :)