如何实现乘法BYT逆向方法(CMAttitude类)? [英] How multiplyByInverseOfAttitude (CMAttitude Class ) is implemented?

查看:547
本文介绍了如何实现乘法BYT逆向方法(CMAttitude类)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要实现来自CMAttitude iOS类的multiplyByInverseOfAttitude使用的相同行为。请注意,我不能直接使用它,但我有正确的CMAttitude对象。任何人都可以指向正确的方向?

I need to implement the same behaviour used by multiplyByInverseOfAttitude from the CMAttitude iOS class. Please note that I cannot directly use it but I have the right CMAttitude objects. Anyone can point me to the right direction?

推荐答案

由于您不允许自己创建CMAttitude实例,唯一的方法是创建一个新的四元数,并将其用于任何进一步的计算。我建议使用您自己的自定义四元数类,而不是简单的结构 CMQuaternion 。一个好的起点是 cocoamath 项目,您可以在其中使用Quaternion.m,Quaternion.h和QuaternionOperations.m来自中继,我将使用此示例代码。

As you are not allowed to create an instance of CMAttitude on your own, the only way is to create a new quaternion and take this for any further calculations. I recommend using your own customised quaternions class instead of the simple struct CMQuaternion. A good starting point is the cocoamath project where you can take Quaternion.m, Quaternion.h and QuaternionOperations.m from trunk and I will use it for this sample code.

首先,您必须保存 CMAttitude.quaternion )的 =nofollow>复共轭,即

First you have to save an instance from the complex conjugate of your reference quaternion (taken from CMAttitude.quaternion) to use for all subsequent multiplications i.e.

MyClass.h

MyClass.h

Quaternion* inverseReferenceQuaternion;

MyClass.c

MyClass.c

// initialising code run only once after each call to [motionManager startDeviceMotionUpdates];
CMAttitude firstAttitude = [motionManager deviceMotion].attitude;
CMQuaternion q = firstAttitude.quaternion;
inverseReferenceQuaternion = [[Quaternion alloc] initWithRe:q.w i:-q.x j:-q.y k:-q.z];

在定时器循环(或处理程序块)中,您需要四元数乘法

In your timer loop (or handler block) you need a quaternion multiplication:

// on every update
CMAttitude attitude = [motionManager deviceMotion].attitude;
CMQuaternion current = attitude.quaternion;
Quaternion currentMultiplied = initAsProductOf:inverseReferenceQuaternion And:current

现在 currentMultiplied 应该包含您正在寻找的内容。

Now currentMultiplied should contain what you are looking for.

如果您是这个主题的新手,四分法是很漂亮的,但值得阅读一些教程示例 OpenGL:教程:使用四元数表示旋转 Quaternion Powers

Quaternions are pretty if you are new to this subject, but it's worth to read some tutorials like for example OpenGL:Tutorials:Using Quaternions to represent rotation or Quaternion Powers.

这篇关于如何实现乘法BYT逆向方法(CMAttitude类)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆