Translate Local quaternion rotation into global (gyro)

六眼飞鱼酱① 提交于 2020-01-05 05:00:12

问题


I need a way to get euler angles for rotation in global frame of reference from a local. I am using c#, wpf 3d and a gyroscope. I have a globe on the screen that should move in the same way as the gyro. Since the gyro sends movement relative to itself I need to use quaternions to keep the state of the object and update it but I'm stuck. If i do the following:

                var qu=eulerToQ(Gyro.X,Gyro.Y,Gyro.Z);
                GlobalQu = Quaternion.Multiply(qu, GlobalQu);

IT rotates correctly on one axis. When I rotate by A in one direction and then by B in another the rotations of the object and the gyro are no longer in the same direction because the above works for absolute rotations (relative to the world).

For example:

                    var qu=eulerToQ(KeyboardValue1,KeyboardValue2,KeyboardValue3);
                    GlobalQu = qu;

This works because I am increasing the roll,pitch,yaw ie keyboard values via keyboard always on the global axis. Gyro send rotations on LOCAL axis.

Switching the order of quaternion rotation doesn't help

                    var qu=eulerToQ(Giro.X,Giro.Y,Giro.Z);
                    GlobalQu = Quaternion.Multiply(GlobalQu,qu);

回答1:


This actually is the proper way. If you multiply globalQuaternion * newQuaternion you get global rotation and newQuaternion * globalQuaternion then you get local rotation. I simply had a mistake in generating my quaternion.




回答2:


You say you have a gyro. Is it a physical gyro? A gyro, in and of itself, can only generate angular rate information. Is there electronics attached to it that produces angles, not angular rates? There are twelve possible Euler angle rotation sequences; each has a different mathematical conversion to quaternion. You only have a one in twelve chance that the order of angles coming from your gyro is the same as the order that your eulertoQ function. Here is a Link to an euler to quaternion white paper I wrote several years ago.



来源:https://stackoverflow.com/questions/2281864/translate-local-quaternion-rotation-into-global-gyro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!