问题描述
我在游戏中使用四元数,并且想知道当我有两个方向四元数时,如何获得从第一个q1到第二个q2所需的旋转四元数.我是自学成才的,因此我的词汇表中可能缺少明显的解决方案.
I'm using quaternions in my game, and I'm wondering how, when I have two orientation quaternions, I can get the rotation quaternion needed to go from the first one, q1, to the second one, q2.I'm self taught, so there may be obvious solutions missing from my vocabulary.
在等式中,当我从第一个旋转到另一个时,我正在做的事情如下:q2 = r * q1
In equations, what I'm doing when I rotate from the first one to the other is as follows:q2 = r * q1
但是,现在r是未知数.代数规则在这里也算在内吗?如果真是这样,我最终会把一个四元数除以另一个,这在互联网上找不到很好的解释.
However, now r is the unknown. Do the rules of algebra count here too? If that's the case, I'd end up dividing a quaternion by another, something I can't find a good explanation for on the internet.
我正在使用一个叫做Game Maker的程序
I'm using a program called game maker
推荐答案
为了用四元数来划分",您需要将其反转以使其与旋转方向相反.为了反转四元数,可以否定 w 组件或( x , y , z )组件,但不能同时使用这两个组件,因为这会使您拥有与开始时相同的四元数(完全取反的四元数表示相同的旋转).
In order to "divide" with a quaternion, you invert it so that it's the opposite rotation. In order to invert a quaternion, you negate either the w component or the (x, y, z) components, but not both since that would leave you with the same quaternion you started with (a fully negated quaternion represents the same rotation).
然后,请记住四元数不是可交换的.所以:
Then, remember that quaternions aren't commutative. So:
q2 = r*q1
q2*q1' = r
其中 q1'是倒四元数,必须将其与q2的右边相乘才能得到正确的结果.
Where q1' is the inverted quaternion and it must be multiplied on the right side of q2 to get the right result.
这篇关于当我有两个方向四元数时,如何找到从一个方向到另一个方向所需的旋转四元数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!