简体   繁体   English

合并3个以上的旋转(四元数)

[英]Combine more than 3 rotations (Quaternions)

I have a 3D point and the x,y,z rotations ( qInitial ) for that point. 我有一个3D点,并且该点有x,y,z旋转qInitial )。 I want to rotate that point more (by some degrees that could be 0 up to 360) around y axis ( qYextra ). 我想旋转该点以上 (由一定程度,可能是0至360)围绕y轴线( qYextra )。 How can I calculate the final Euler rotation ( qResult.eulerAngles ) that is a combination of these 4 rotations (xyzy) ? 我怎样才能计算出最终的Euler旋转qResult.eulerAngles就是这4个旋转(XYZY)的组合

I have tried calculating the initial quaternion rotation, and the extra rotation to be applied. 我尝试计算初始四元数旋转以及要应用的额外旋转。 And then multiply these two quaternions. 然后将这两个四元数相乘。 However, I get weird results (probably gimbal lock) . 但是,我得到了奇怪的结果(可能是万向节锁)

Code in C#. C#中的代码。 Unity. 统一。

1. Quaternion qX = Quaternion.AngleAxis(rotationFromBvh.x,Vector3.right); 1. Quaternion qX = Quaternion.AngleAxis(rotationFromBvh.x,Vector3.right);

2. Quaternion qY = Quaternion.AngleAxis(rotationFromBvh.y,Vector3.up); 2. Quaternion qY = Quaternion.AngleAxis(rotationFromBvh.y,Vector3.up);

3. Quaternion qZ = Quaternion.AngleAxis(rotationFromBvh.z,Vector3.forward); 3. Quaternion qZ = Quaternion.AngleAxis(rotationFromBvh.z,Vector3.forward);

4. Quaternion qYextra = Quaternion.AngleAxis(angle,Vector3.up); 4. Quaternion qYextra = Quaternion.AngleAxis(angle,Vector3.up);

Quaternion qInitial = qY * qX * qZ; // Yes. This is the correct order.

qY*qX*qZ has exactly the same Euler x,y,z results as Quaternion.Euler(rotationFromBvh) qY*qX*qZ 的Euler x,y,z结果Quaternion.Euler(rotationFromBvh) 完全相同 qY*qX*qZ Quaternion.Euler(rotationFromBvh)

Quaternion qResult = qInitial * qYextra;

return qResult.eulerAngles;

I can confirm that the code works fine (no gimbal lock) when 4th rotation is 0 degrees ( qYextra = identity ). 我可以确认第4次旋转为0度qYextra = identity )时, 代码工作正常 (无万向节锁定)。 Meaning that qInitial is correct. 表示qInitial是正确的。 So, the error might be due to the combination of those 2 rotations ( qInitial and qYextra ) OR due to the convertion from Quaternion to Euler . 因此,该错误可能是由于这两个旋转qInitialqYextra )的组合, 或者是由于从四元数到欧拉的转换所致。

EXAMPLE: ( qYextra angle is 120 degrees) 示例:( qYextra角度为120度)

RESULTS: 结果:

qInitial.eulerAngles gives these results: applying_qInitial_rotation qInitial.eulerAngles给出了这些结果: applying_qInitial_rotation

qResult.eulerAngles gives these results: applying_qResult_rotation qResult.eulerAngles给出了这些结果: applying_qResult_rotation

EXPECTED RESULTS: 预期成绩:

The expected results should be like qInitial but rotated 120 degrees around y. 预期结果应类似于qInitial但绕y旋转120度。

Any suggestions? 有什么建议么? I haven't yet found a solution, and probably I won't. 我还没有找到解决方案,也许我不会。

In your question, you write: 在您的问题中,您写道:

How can I calculate the final Euler rotation that is a combination of these 4 rotations (xyzy)? 如何计算这四个旋转(xyzy)的组合的最终欧拉旋转?

However, in your code, you write 但是,在您的代码中,您编写了

Quaternion qInitial = qY * qX * qZ; // Multiply them in the correct order.

I don't know unity, but I would have expected that you would want the order of the rotations to match x, y, z, rather than y, x, z. 我不知道统一性,但我曾希望您希望旋转的顺序匹配x,y,z,而不是y,x,z。

You stated that it works when the y-rotation is 0, in which case the place of the y-rotation in the order becomes irrelevant. 您说它在y旋转为0时有效,在这种情况下y旋转在顺序中的位置变得无关紧要。

Do you get the correct result if you instead write the code below? 如果改写下面的代码,您得到正确的结果吗?

Quaternion qInitial = qX * qY * qZ; // Multiply them in the correct order.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM