检测 3d 中的物体旋转

发布于 2024-10-20 04:05:58 字数 278 浏览 2 评论 0原文

我有一个参考模型(例如三角形),其“向上”向量定义为 <0 1 0>及其“over”向量定义为<1 0 0>。

现在我有另一个相同大小的三角形,在 3d 空间中旋转并任意定位。我想做的是找出这个新三角形的“向上”和“上方”向量。即,如果三角形绕X轴旋转180度,则其“向上”向量应为<0 -1 0>。并且它的“over”向量应该是相同的。

如何找到旋转变换?如果我有这个,我可以将“向上”向量反向“旋转”以获得新的“向上”向量,然后就完成了。

有什么想法吗?

I have a reference model, (for example a triangle), with its 'up' vector definied as <0 1 0> and its 'over' vector defined as <1 0 0>.

Now I have another triangle of the same size rotated and positioned arbitrarily in a 3d space. What I want to do is to find out this new triangle's 'up' and 'over' vector. I.e. if the triangle is rotated 180 degrees around the X-axis, it's 'up' vector should be <0 -1 0> and its 'over' vector should be the same.

How do I find the rotation transformation? If I have this, I can just 'rotate' the 'up' vector by the inverse to get the new 'up' vector and then I'm done.

Any ideas?

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

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

发布评论

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

评论(3

叹倦 2024-10-27 04:05:58

为此,您需要垂直于构成三角形的向量的向量。您可以使用叉积来计算它:

http://en.wikipedia.org/wiki/Cross_product

因此,给定一个由点组成的三角形A、B、C 计算 2 个向量 BA 和 CA 的叉积。然后,您可以通过旋转垂直向量来旋转三角形以适合您的参考三角形。

这是您搜索的内容吗?如果没有,请发表评论,我会考虑更多。

To do this you need the vector that is perpendicular to the vectors that make up the triangle. You can compute it using the cross product:

http://en.wikipedia.org/wiki/Cross_product

So given a triangle composed of the points A,B,C you calculate the cross-product of the 2 vectors B-A and C-A. You can then rotate the triangle to fit your reference-triangle by rotating the perpendicular vector.

Is this what you searched for? If not please comment and i will think some more.

三月梨花 2024-10-27 04:05:58

必须在另一个答案中回答您的评论,因为我想添加图形。

如果你的模型有超过 4 个点,但是刚体,那么取任意 3 个不相同的点就足以获得垂直向量(然后取你想要的对象上的 3 个对应点)将其旋转到)。您可以通过计算它们之间的角度将一个垂直矢量旋转到另一个垂直矢量,这必须针对 3 轴单独完成。我将演示如何计算绕 z 轴旋转的角度。因此,在下图中,粗体红色和蓝色箭头是原始的 3 维向量。

Graphic 1

只需将它们的 z 值设置为 0,即可将它们投影在 xy 平面上您可以使用它们的点积、范数和反余弦来计算它们之间的角度,如以下公式中的 http://en.wikipedia.org/wiki/Dot_product。现在,theta 就是您必须绕 z 轴旋转的角度。对 x 轴和 y 轴做同样的事情,你就得到了旋转角度。

图 2

Have to answer your comment in another answer because i want to add graphics.

If your model has more than 4 points but is a rigid body then it is sufficient to take any 3 non-identical points to get the perpendicular vector (and then take the 3 corresponding points on the object you want to rotate it into). You rotate the one perpendicular vector into the other by calculating the angle between them, this has to be done separately for the 3 axis'. I will demonstrate it for how you do it to calculate the angle by which you rotate around the z-axis. So in the following graphic the bold red and blue arrows are the original 3-dimensional vectors.

Graphic 1

You project them on the x-y-plane by just setting their z-value to 0. You calculate the angle between them by using their dot-product, norm and arcus cosine as in the following formula from http://en.wikipedia.org/wiki/Dot_product. That theta is now the angle by which you have to rotate around the z-axis. Do the same thing for the x- and y-axis and you have your rotation-angles.

Graphic 2

寂寞清仓 2024-10-27 04:05:58

好吧大家。感谢您的帮助,但我设法弄清楚了。

以下是步骤。

  1. 将两个对象置于原点中心

  2. 将一个向量旋转到另一个向量上,例如 (a0) -> (b0)。现在你必须使向量彼此重叠。 a0/b0虽然是点,但从原点形成向量

  3. 找到每个向量的法线,这可以通过在每个坐标空间中使用附加点并找到叉积来完成。例如:

    an = a0 x a1
    bn = b0 x b1

  4. 现在只需将 an 旋转到 bn 上即可完成。

进行旋转的最简单方法是添加一个返回四元数的“rotateTo”成员函数(避免万向节锁定)。然后您可以将两个四元数相乘以获得旋转变换结果。

Ok everyone. Thanks for the help, but I managed to figure it out.

Here are the steps.

  1. Center both objects at the origin

  2. Rotate one vector onto another, for examble (a0) -> (b0). Now you have to vectors overlapping one another. a0/b0, although points, form vectors from the origin

  3. Find the normals of each of these vectors, this can be done by using an additional point in each coordinate space and finding the cross products. For example:

    an = a0 x a1
    bn = b0 x b1

  4. Now just rotate an onto bn and you are finished.

The easiest way to do the rotations is to add a 'rotateTo' member function that returns a quaternion (Avoids gimbal lock). Then you can multiply the two quaternions together to get the resulting rotation transformation.

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