如何旋转由四元数表示的对象集?
假设物体的方向由四元数表示。 如果我想旋转该对象,只需将四元数与旋转四元数相乘即可。
object.q = q_rotation*(object.q)
然后对于由一组较小对象组成的对象。我该如何旋转它?
class Object
{
public:
std::vector<Object> part;
Point centre; //Point is basically double x, y, z
Quaternion q;
void RotateBy(Quaternion q_rotation);
};
只是说这个对象有两个部分。并且每个部分都可以有自己的中心和q,并且它们相对于整个空间(而不是相对于主要对象的中心)。
然后现在我想旋转该对象,并且它的所有部分也应该旋转并更新到它们的新中心和 q's。这些部件将相对于主要对象的中心旋转。
我该怎么办呢???我发现了许多链接,展示了如何使用变换矩阵来做到这一点。但是有没有办法直接用四元数来做呢?
换句话说,也许如何在原点移动的情况下旋转四元数?
感谢您的帮助!
Say a object's orientation is represented by a quaternion.
If I want to rotate that object, I simply multiply the quaternion with the rotational quaternion.
object.q = q_rotation*(object.q)
Then for an object that is composed of made up of a set of smaller objects. How do I rotate it?
class Object
{
public:
std::vector<Object> part;
Point centre; //Point is basically double x, y, z
Quaternion q;
void RotateBy(Quaternion q_rotation);
};
Just say this object has two part's. And each part could have its own centre and q, and they relative to the entire space (not relative to the centre of the main object).
Then now I want to rotate the object, and all its parts should rotate as well and get updated to their new centres and q's. The parts will be rotated relative to the main object's centre.
How should I do that??? I have found many some link that show how to do this with transformational matrice. But is there a way to do it directly with the quaternion?
Perhaps, in other word, how to rotate a quaternion with the origin shifted?
Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上比我想象的要容易。我想那些线性代数课程实际上很有用。
在本例中,我假设您有一些 3D 几何体定义为名为“GeomType”的类。一个“Object”由许多“GeomType”组成。这里的“对象”是简单的“GeomType”向量。
“对象”中的每个“GeomType”由其相对于“对象”中心点的中心点位置和表示从默认中性位置旋转的四元数来定义。这是一些示例代码。
还有PointType,它基本上是双精度的(x, y, z),以及QuaternionType,它也是双精度的(w,x,y,z)。
这是 RotateAbout 函数,用于绕点旋转矢量。
这是相对于点旋转一组 3D 对象的通用程序。尽管它是基于C++编写的,但它应该适用于任何编程语言。
It is actually easier than I thought. I guess those linear algebra classes was actually useful.
In this case, I assume you have some 3D geometry defined as a class named 'GeomType'. An 'Object' is made up of many 'GeomType'. Here an 'Object' is simple a vector of 'GeomType'.
Each 'GeomType' in an 'Object' is defined by it centre point location relative to the centre point of the 'Object' and an quaternion which represent the rotation from a default neutral position. Here is some sample code.
There are also PointType which is basically (x, y, z) in double, and QuaternionType which is (w,x,y,z) in double as well.
This is the RotateAbout function which was used to rotate a vector about a point
Here is the general program to rotate a set of 3D objects relative to a point. It should be applicable to any programming language though it is written based on C++.