Java 两个四元数旋转的点积

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21513637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 09:05:10  来源:igfitidea点击:

dot product of two quaternion rotations

javamathrotationquaternionsdot-product

提问by Kent

I understand that the dot (or inner) product of two quaternions is the angle between the rotations (including the axis-rotation). This makes the dot product equal to the angle between two points on the quaternion hypersphere.
I can not, however, find how to actually compute the dot product.

我知道两个四元数的点(或内)积是旋转(包括轴旋转)之间的角度。这使得点积等于四元数超球面上两点之间的角度。
但是,我无法找到如何实际计算点积。

Any help would be appreciated!

任何帮助,将不胜感激!

current code:

当前代码:

public static float dot(Quaternion left, Quaternion right){
    float angle;

    //compute

    return angle;
}

Defined are Quaternion.w, Quaternion.x, Quaternion.y, and Quaternion.z.

定义为 Quaternion.w、Quaternion.x、Quaternion.y 和 Quaternion.z。

Note: It can be assumed that the quaternions are normalised.

注意:可以假设四元数是归一化的。

采纳答案by user3146587

The dot product for quaternions is simply the standard Euclidean dot product in 4D:

四元数的点积只是 4D 中的标准欧几里得点积:

dot = left.x * right.x + left.y * right.y + left.z * right.z + left.w * right.w

Then the angle your are looking for is the arccosof the dot product (note that the dot product is not the angle): acos(dot).

那么你要找的角度就是arccos点积的(注意点积不是角度):acos(dot)

However, if you are looking for the relative rotation between two quaternions, say from q1to q2, you should compute the relative quaternion q = q1^-1 * q2and then find the rotation associated withq.

但是,如果您正在寻找两个四元数之间的相对旋转,例如从q1to q2,您应该计算相对四元数q = q1^-1 * q2,然后找到与 关联的旋转q

回答by minorlogic

Just NOTE: acos(dot) is very not stable from numerical point of view.

请注意:从数字的角度来看,acos(dot) 非常不稳定。

as was said previos, q = q1^-1 * q2 and than angle = 2*atan2(q.vec.length(), q.w)

正如之前所说, q = q1^-1 * q2 而不是 angle = 2*atan2(q.vec.length(), qw)

回答by Murt Moriarty

Should it be 2 x acos(dot) to get the angle between quaternions.

应该是 2 x acos(dot) 来获得四元数之间的角度。