将局部四元数旋转转换为全局(陀螺仪)
我需要一种方法来从局部获取全局参考系中旋转的欧拉角。我正在使用 c#、wpf 3d 和陀螺仪。我的屏幕上有一个地球仪,它应该以与陀螺仪相同的方式移动。由于陀螺仪发送相对于自身的运动,我需要使用四元数来保持对象的状态并更新它,但我被卡住了。如果我执行以下操作:
var qu=eulerToQ(Gyro.X,Gyro.Y,Gyro.Z);
GlobalQu = Quaternion.Multiply(qu, GlobalQu);
IT 在一个轴上正确旋转。当我沿一个方向旋转 A,然后沿另一个方向旋转 B 时,对象和陀螺仪的旋转不再沿同一方向,因为上述适用于绝对旋转(相对于世界)。
例如:
var qu=eulerToQ(KeyboardValue1,KeyboardValue2,KeyboardValue3);
GlobalQu = qu;
这是有效的,因为我总是在全局轴上通过键盘增加横滚、俯仰、偏航即键盘值。陀螺仪在本地轴上发送旋转。
切换四元数旋转顺序没有帮助
var qu=eulerToQ(Giro.X,Giro.Y,Giro.Z);
GlobalQu = Quaternion.Multiply(GlobalQu,qu);
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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这其实才是正确的做法。如果将 globalQuaternion * newQuaternion 相乘,则得到全局旋转,而 newQuaternion * globalQuaternion 则得到局部旋转。我只是在生成四元数时犯了一个错误。
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.
你说你有陀螺仪。是物理陀螺仪吗?陀螺仪本身只能生成角速率信息。它上面是否有电子设备可以产生角度而不是角速率?有十二种可能的欧拉角旋转序列;每个都有不同的四元数数学转换。来自陀螺仪的角度顺序与 eulertoQ 函数的顺序相同的可能性只有十二分之一。这是链接我几年前写的欧拉到四元数白皮书。
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.