使用四元数旋转 3D 欧拉点以避免万向节锁定
首先,我已经做了很多谷歌搜索并检查了有关此问题的其他 stackoverflow 帖子,但无法获得工作回复或工作代码片段。数学不是我的强项。
我需要一个例程,获取相机点(CX,CY,CZ)并将其围绕观察点(LX,LY,LZ)旋转三个旋转角度(RX,RY,RZ)。在某些情况下,使用欧拉旋转会导致万向节锁定,我需要避免这种情况。所以我听说了使用四元数。
我发现这可以将旋转转换为四元数 http://www.euclideanspace.com/maths/geometry/rotations /conversions/eulerToQuaternion/index.htm
并将其从四元数转换回欧拉 XYZ 旋转 http://www.euclideanspace.com/maths/geometry/rotations /conversions/quaternionToEuler/index.htm
它们似乎工作正常,但我需要知道如何使用四元数来旋转围绕 LX、LY、LZ 的 CX、CY、CZ,然后返回新的 CX、CY、CZ,而不会出现万向节锁定问题。
关于这一点的内容太多了,我确信一个好的解释和代码片段不仅会帮助我,而且会在未来帮助许多其他人。
所以如果可以的话请帮忙。非常感谢。
Firstly, I have done much googling and checking other stackoverflow posts about this, but cannot get a working reply or a snippet of working code. Maths is not my strength.
I need to have a routine that takes a camera point (CX,CY,CZ) and rotate it about a lookat point (LX,LY,LZ) by three rotation angles (RX,RY,RZ). Using euler rotations leads to gimbal lock in some cases which I need to avoid. So I heard about using quaternions.
I found this to convert the rotations into a quaternion
http://www.euclideanspace.com/maths/geometry/rotations/conversions/eulerToQuaternion/index.htm
and this to convert from a quaternion back to euler XYZ rotations
http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToEuler/index.htm
They seem to work fine, but I need to know how to use the quaternion to rotate the CX,CY,CZ around LX,LY,LZ and then return the new CX,CY,CZ without issues of gimbal lock.
There is so much out there about this, that I am sure a good explanation and snippet of code will help not only me but many others in the future.
So please help if you can. Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的答案是,如果您的四元数是 Q 并且新的相机点是 C':
其中点通过 Cw=0 进行增强,并且乘法和逆运算根据四元数规则。
具体来说,令D = C - L。然后我们让 F = Q*D:
最后,我们得到 C' = F*Q^-1 + L:
但是,请注意,如果您要创建从欧拉表示的四元数,你仍然会得到万向节锁。万向节锁是欧拉表示的一个属性,四元数仅表示相同的变换。要摆脱万向节锁,您需要完全避免欧拉表示,除非我误解了您如何使用它。
The short answer, if your quaternion is Q and the new camera point is C':
where the points are augmented with Cw=0 and multiplication and inverse are according to quaternion rules.
Specifically, let D = C - L. Then we let F = Q*D:
Finally, we get C' = F*Q^-1 + L:
However, be aware that if you're creating the quaternion from an Euler representation, you'll still end up with gimbal lock. The gimbal lock is a property of the Euler representation and the quaternion will just represent the same transformation. To get rid of gimbal lock, you'll need to avoid the Euler representation altogether, unless I misunderstand how you're using it.