翻译四元数

发布于 2024-09-28 15:32:35 字数 619 浏览 1 评论 0原文

(也许这对于数学堆栈交换更好?)

我有一条由骨头组成的链。每块骨头都有一个尖端和尾巴。以下代码在给定旋转的情况下计算其尖端的位置,并适当地设置链中的下一个链接的位置:

    // Quaternion is a hand-rolled class that works correctly (as far as I can tell.)
    Quaternion quat = new Quaternion(getRotationAngleDegrees(), getRotation());

    // figure out where the tip will be after applying the rotation
    Vector3f rotatedTip = quat.applyRotationTo(tip);

    // set the next bone's tail to be at this one's tip
    updateNextPosFrom(rotatedTip);

如果旋转应该围绕对象坐标系的原点发生,则此方法有效。但是,如果我希望旋转围绕对象中的其他任意点发生怎么办?我不知道如何翻译四元数。最好的方法是什么?

(我正在使用 JOGL / OpenGL。)

(perhaps this is better for a math Stack Exchange?)

I have a chain composed of bones. Each bone has a with a tip and tail. The following code computes where its tip will be, given a rotation, and sets the next link in the chain's position appropriately:

    // Quaternion is a hand-rolled class that works correctly (as far as I can tell.)
    Quaternion quat = new Quaternion(getRotationAngleDegrees(), getRotation());

    // figure out where the tip will be after applying the rotation
    Vector3f rotatedTip = quat.applyRotationTo(tip);

    // set the next bone's tail to be at this one's tip
    updateNextPosFrom(rotatedTip);

This works if the rotation is supposed to occur around the origin of the object's coordinate system. But what if I want the rotation to occur around some other arbitrary point in the object? I'm not sure how to translate the quaternion. What is the best way to do it?

(I'm using JOGL / OpenGL.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

夏の忆 2024-10-05 15:32:35

对偶四元数可用于表达刚性空间变换(组合旋转和平移)。

基于对偶数(Clifford 代数之一,d = a + eb,其中 a、b 为实数,e 不等于 0,但 e^2 = 0 ),对偶四元数 U + e V 可以表示空间中的线,其中 U 是单位方向四元数,V 是关于参考点的矩。这样,对偶四元数线就很像普鲁克线了。

虽然四元数变换 QVQ*(Q* 是 Q 的四元数共轭)用于绕点旋转单位向量四元数 V,但类似的对偶四元数形式可用于应用直线螺旋变换(绕点的刚性旋转)轴与沿轴的平移相结合。)

正如任何刚性 2D 变换都可以解析为绕点的旋转一样,任何刚性 3D 变换都可以解析为螺旋。

对于如此强大的功能和表现力,对偶四元数引用很少,维基百科文章也是一个不错的地方与任何开始一样。

Dual quaternions are useful for expressing rigid spatial transformations (combined rotations and translations.)

Based on dual numbers (one of the Clifford algebras, d = a + e b where a, b are real and e is unequal to zero but e^2 = 0), dual quaternions, U + e V, can represent lines in space with U the unit direction quaternion and V the moment about a reference point. In this way, dual quaternion lines are very much like Pluecker lines.

While the quaternion transform Q V Q* (Q* is the quaternion conjugate of Q) is used to rotate a unit vector quaternion V about a point, a similar dual quaternion form can be used to apply to line a screw transform (the rigid rotation about an axis combined with a translation along the axis.)

Just as any rigid 2D transform can be resolved to a rotation about a point, any rigid 3D transform can be resolved to a screw.

For such power and expressiveness, dual quaternion references are thin, and the Wikipedia article is as good a place as any to start.

半夏半凉 2024-10-05 15:32:35

四元数专门用于处理旋转因子,但根本不包括平移。

通常,在这种情况下,您需要根据“骨骼”长度对点应用旋转,但以原点为中心。然后,您可以将旋转后平移到空间中的正确位置。

A quaternion is used specifically to handle a rotation factor, but does not include a translation at all.

Typically, in this situation, you'll want to apply a rotation to a point based on the "bone's" length, but centered at the origin. You can then translate post-rotation to the proper location in space.

染年凉城似染瑾 2024-10-05 15:32:35

四元数通常仅用于表示旋转;它们也不能代表翻译。

您需要将四元数转换为旋转矩阵,将其插入到您的标准 OpenGL 4x4 矩阵,并将其与平移结合起来,以便绕任意点旋转。

4x4 rotation matrix:
  [ r r r 0 ]
  [ r r r 0 ]  <- the r's are the 3x3 rotation matrix from the wiki article
  [ r r r 0 ]
  [ 0 0 0 1 ]

Quaternions are generally used to represent rotations only; they cannot represent translations as well.

You need to convert your quaternion into a rotation matrix, insert it into the appropriate part of your standard OpenGL 4x4 matrix, and combine it with a translation in order to rotate about an arbitrary point.

4x4 rotation matrix:
  [ r r r 0 ]
  [ r r r 0 ]  <- the r's are the 3x3 rotation matrix from the wiki article
  [ r r r 0 ]
  [ 0 0 0 1 ]
请叫√我孤独 2024-10-05 15:32:35

编辑:这个答案是错误的。它争论的是 4x4 变换矩阵属性,而不是四元数...

我可能弄错了,但对我来说(与某些答案不同)四元数确实是处理旋转和平移的工具 (以及更多)。它是一个 4x4 矩阵,其中最后一列表示平移。使用矩阵代数,将 3 向量 (x, y, z) 替换为 4 向量 (x, y, z, 1),并通过矩阵计算变换后的向量。您会发现矩阵最后一列的值将添加到原始向量的坐标 x、y、z,就像平移一样。

3D 空间的 3x3 矩阵表示线性变换(如绕原点旋转)。您不能使用 3x3 矩阵进行仿射变换(如平移)。因此,我将四元数简单地理解为使用矩阵代数表示更多种类的变换的一个小“技巧”​​。诀窍是添加第四个等于 1 的坐标并使用 4x4 矩阵。由于矩阵代数仍然有效,因此您可以通过矩阵相乘来组合空间变换,这确实很强大。

Edit : This answer is wrong. It argues on 4x4 transformation matrices properties, which are not quaternions...

I might have got it wrong but to me (unlike some answers) a quaternion is indeed a tool to handle rotations and translations (and more). It is a 4x4 matrix where the last column represents the translation. Using matrix algebra, replace the 3-vector (x, y, z) by the 4-vector (x, y, z, 1) and compute the transformed vector by the matrix. You will find that values of the last column of the matrix will be added to the coordinates x, y, z of the original vector, as in a translation.

A 3x3 matrix for a 3D space represents a linear transformation (like rotation around the origin). You cannot use a 3x3 matrix for an affine transformation like a translation. So I understand simply the quaternions as a little "trick" to represent more kinds of transformations using matrix algebra. The trick is to add a fourth coordinate equal to 1 and to use 4x4 matrices. Because matrix algebra remains valid, you can combine space transformations by multiplying the matrices, which is indeed powerful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文