四元数到EulerXYZ,如何区分正负四元数 [英] Quaternion to EulerXYZ, how to differentiate the negative and positive quaternion
问题描述
我一直在试图弄清楚这些之间的区别,以及为什么ToEulerXYZ没有得到正确的轮换。
使用MathGeoLib:
axisX:
x 0.80878228 float
y -0.58810818 float
z 0.00000000 float
axisY:
x 0.58811820 float
y 0.80877501 float
z 0.00000000 float
axisZ:
x 0.00000000浮动$ b $ 0.00000000浮动
z 1.0000000浮动
代码:
$ Q$ b
Quat aQ = Quat :: RotateAxisAngle(axisX,DegToRad(30))* Quat :: RotateAxisAngle(axisY,DegToRad(60))* Quat :: RotateAxisAngle(axisZ,DegToRad(40));
float3 eulerAnglesA = aQ.ToEulerXYZ();
Quat bQ = Quat :: RotateAxisAngle(axisX,DegToRad(-150))* Quat :: RotateAxisAngle(axisY,DegToRad(120))* Quat :: RotateAxisAngle(axisZ,DegToRad(-140) );
float3 eulerAnglesB = bQ.ToEulerXYZ();
ToEulerXYZ都得到{x = 58.675510 y = 33.600880 z = 38.327244 ...}
我可以看到的唯一区别是四元数是相同的,但是一个是负数。虽然ToEulerXYZ是错误的,但应该是负数({x = -58.675510 y = -33.600880 z = -38.327244 ...})(bQ)
AQ是:
x 0.52576530浮动$ b $ 0.084034257浮动
z 0.40772036浮动
w 0.74180400浮动
虽然bQ是:
x -0.52576530浮动$ b $浮动-0.084034257浮动
z -0.40772036浮动
w -0.74180400浮动
这仅仅是MathGeoLib的一个错误,或者是一些奇怪的细微差别,或者有人可以向我解释什么是逻辑上的。
还有一些情况甚至不是负面消息b
$ b
axisX:
$ $ b $ $ $ $ $ $ $ $ $ $ $ $ $
axisY
0.69920099 y = -0.71492511 z = 0.00000000
$ b axisZ:
x = 0.00000000 y = 0.00000000 z = 1.0000000
代码:
Quat :: RotateAxisAngle(axisX,DegToRad(0))* Quat :: RotateAxisAngle(axisY,DegToRad(0))* Quat :: RotateAxisAngle(axisZ,DegToRad(-90));
float3 eulerAnglesA = aQ.ToEulerXYZ();
Quat bQ = Quat :: RotateAxisAngle(axisX,DegToRad(-180))* Quat :: RotateAxisAngle(axisY,DegToRad(180))* Quat :: RotateAxisAngle(axisZ,DegToRad(90)) ;
float3 eulerAnglesB = bQ.ToEulerXYZ();
这些都产生相同的四元数!
x 0.00000000浮动$ b $按0.00000000浮动
z -0.70710677浮动
w 0.70710677浮动
四元数q和q不同;然而,由两个四元数表示的旋转是相同的。这种现象通常被称为四元数提供的轮换组SO(3)。看到这个代数很简单:给定一个由四元数p表示的向量和由四元数q表示的旋转,其旋转为 qpq ^ { - 1}
。另一方面, -qp(-q)^ {-1} = -1qp(q)^ { - 1}( - 1)= q(-1)p(-1)q ^ {-1} = qp(-1)^ 2q ^ { - 1} = qpq ^ { - 1}
,相同的旋转。四元数通常不通勤,所以对于一般的四元数来说, pq!= qp
,但像-1这样的标量可以通过四元数来交换。
我相信ToEulerXYZ在两种情况下应该是相同的,看起来是这样。
I've been trying to figure out the difference between these, and why ToEulerXYZ does not get the right rotation.
Using MathGeoLib:
axisX:
x 0.80878228 float
y -0.58810818 float
z 0.00000000 float
axisY:
x 0.58811820 float
y 0.80877501 float
z 0.00000000 float
axisZ:
x 0.00000000 float
y 0.00000000 float
z 1.0000000 float
Code:
Quat aQ = Quat::RotateAxisAngle(axisX, DegToRad(30)) * Quat::RotateAxisAngle(axisY, DegToRad(60)) * Quat::RotateAxisAngle(axisZ, DegToRad(40));
float3 eulerAnglesA = aQ.ToEulerXYZ();
Quat bQ = Quat::RotateAxisAngle(axisX, DegToRad(-150)) * Quat::RotateAxisAngle(axisY, DegToRad(120)) * Quat::RotateAxisAngle(axisZ, DegToRad(-140));
float3 eulerAnglesB = bQ.ToEulerXYZ();
Both to ToEulerXYZ get {x=58.675510 y=33.600880 z=38.327244 ...} (when converted to degrees).
The only difference I can see, is the quaternions are identical, but one is negative. The ToEulerXYZ is wrong though, as one should be the negative ({x=-58.675510 y=-33.600880 z=-38.327244 ...}) (bQ)
AQ is:
x 0.52576530 float
y 0.084034257 float
z 0.40772036 float
w 0.74180400 float
While bQ is:
x -0.52576530 float
y -0.084034257 float
z -0.40772036 float
w -0.74180400 float
Is this just an error with MathGeoLib, or some weird nuance, or maybe someone can explain to me what is going on logically.
There are additional scenarios that are not even negative
axisX:
-0.71492511 y=-0.69920099 z=0.00000000
axisY:
0.69920099 y=-0.71492511 z=0.00000000
axisZ:
x=0.00000000 y=0.00000000 z=1.0000000
Code:
Quat aQ = Quat::RotateAxisAngle(axisX, DegToRad(0)) * Quat::RotateAxisAngle(axisY, DegToRad(0)) * Quat::RotateAxisAngle(axisZ, DegToRad(-90));
float3 eulerAnglesA = aQ.ToEulerXYZ();
Quat bQ = Quat::RotateAxisAngle(axisX, DegToRad(-180)) * Quat::RotateAxisAngle(axisY, DegToRad(180)) * Quat::RotateAxisAngle(axisZ, DegToRad(90));
float3 eulerAnglesB = bQ.ToEulerXYZ();
These both yield the same quaternion!
x 0.00000000 float
y 0.00000000 float
z -0.70710677 float
w 0.70710677 float
The quaternions -q and q are different; however, the rotations represented by the two quaternions are identical. This phenomenon is usually described by saying quaternions provide a double cover of the rotation group SO(3). The algebra to see this is very simple: given a vector represented by quaternion p, and a rotation represented represented by a quaternion q, the rotation is qpq^{-1}
. On the other hand, -qp(-q)^{-1} = -1qp(q)^{-1}(-1) = q(-1)p(-1)q^{-1} = qp(-1)^2q^{-1} = qpq^{-1}
, the same rotation. Quaternions normally don't commute, so pq != qp
for general quaternions, but scalars like -1 do commute with quaternions.
I believe ToEulerXYZ should be the same in both cases, which it appears to be.
这篇关于四元数到EulerXYZ,如何区分正负四元数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!