如何表示 4x4 矩阵旋转?

发布于 2024-09-28 05:23:19 字数 687 浏览 1 评论 0原文

给定 x、y、z 旋转矩阵的以下定义,如何将其表示为一个完整的矩阵?只需将 x、y 和 & 相乘即可矩阵?

X 旋转:

[1 0 0 0]
[0 cos(-X Angle) -sin(-X Angle) 0]
[0 sin(-X Angle) cos(-X Angle) 0]
[0 0 0 1]

Y 旋转:

[cos(-Y Angle) 0 sin(-Y Angle) 0]
[0 1 0 0]
[-sin(-Y Angle) 0 cos(-Y Angle) 0]
[0 0 0 1]

Z 旋转:

[cos(-Z Angle) -sin(-Z Angle) 0 0]
[sin(-Z Angle) cos(-Z Angle) 0 0]
[0 0 1 0]
[0 0 0 1] 

编辑: 我有一个单独的旋转类,其中包含 x、y、z 浮点值,稍后我将其转换为矩阵以便与其他翻译组合/缩放/旋转。

从这里的答案来看,我可以假设如果我做类似的事情:

旋转旋转; 旋转.SetX(45); 旋转.SetY(90); 旋转.SetZ(180);

那么旋转的应用顺序实际上非常重要?或者可以安全地假设,当使用旋转类时,您接受它们按 x、y、z 顺序应用?

Given the following definitions for x,y,z rotation matrices, how do I represent this as one complete matrix? Simply multiply x, y, & matrices?

X Rotation:

[1 0 0 0]
[0 cos(-X Angle) -sin(-X Angle) 0]
[0 sin(-X Angle) cos(-X Angle) 0]
[0 0 0 1]

Y Rotation:

[cos(-Y Angle) 0 sin(-Y Angle) 0]
[0 1 0 0]
[-sin(-Y Angle) 0 cos(-Y Angle) 0]
[0 0 0 1]

Z Rotation:

[cos(-Z Angle) -sin(-Z Angle) 0 0]
[sin(-Z Angle) cos(-Z Angle) 0 0]
[0 0 1 0]
[0 0 0 1] 

Edit: I have a separate rotation class that contains an x, y, z float value, which I later convert to a matrix in order to combine with other translations / scales / rotations.

Judging from the answers here, I can assume that if I do something like:

Rotation rotation;
rotation.SetX(45);
rotation.SetY(90);
rotation.SetZ(180);

Then it's actually really important as to which order the rotations are applied? Or is it safe to make the assumption that when using the rotation class, you accept that they are applied in x, y, z order?

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

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

发布评论

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

评论(3

夜还是长夜 2024-10-05 05:23:19

是的,三个矩阵依次相乘就可以组成它们。

编辑:

对矩阵应用乘法的顺序将决定对点应用旋转的顺序。

P × (X × Y × Z)     Rotations in X, Y, then Z will be performed
P × (Y × X × Z)     Rotations in Y, X, then Z will be performed
P × (Z × X × Y)     Rotations in Z, X, then Y will be performed

Yes, multiplying the three matrices in turn will compose them.

EDIT:

The order that you apply multiplication to the matrices will determine the order the rotations will be applied to the point.

P × (X × Y × Z)     Rotations in X, Y, then Z will be performed
P × (Y × X × Z)     Rotations in Y, X, then Z will be performed
P × (Z × X × Y)     Rotations in Z, X, then Y will be performed
情场扛把子 2024-10-05 05:23:19

实际上,应用轮换的顺序非常重要。

您想要的顺序取决于您希望轮换执行的操作。例如,如果您正在为飞机建模,您可能需要先进行横滚(沿机身的长轴旋转),然后进行俯仰(沿另一个水平轴旋转),然后进行航向(沿垂直轴旋转) )。这是因为,如果您先进行航向,则飞机将不再沿其他轴对齐。除此之外,您还需要处理约定:哪些轴对应于 X、Y 和 Z?

通常,您只想为特定应用程序选择特定的轮换顺序。定义一个通用的“XYZrotation”对象没有多大意义;通常,您将拥有通用变换(即,可以是旋转、平移等的任意串联的矩阵)以及获取它们的各种方法(例如,rotX、rotY、平移、缩放...),以及应用的能力它们按特定顺序排列(通过进行矩阵乘法)。

如果你想要的东西只能代表旋转而不代表其他任何东西,你可以考虑四元数(正如阿南德建议的那样)。但是,您仍然需要决定执行轮换的顺序,而且,为此硬连线所需的顺序并没有真正的意义。

It actually is really important what order you apply your rotations in.

The order you want depends on what you want the rotations to do. For instance, if you are modeling an airplane, you might want to do the roll first (rotate along the long axis of the body), then the pitch (rotate along the other horizontal axis), then the heading (rotate along the vertical axis). This would be because, if you did the heading first, the plane would no longer be aligned along the other axes. Beyond that, you need to deal with your conventions: which of these axes correspond to X, Y, and Z?

Generally, you only want to choose a particular rotation order for specific applications. It doesn't make much sense to define a generic "XYZrotation" object; typically, you will have generic transformations (i.e., matrices that can be any concatenation of rotations, translations, etc.) and various ways to get them (e.g., rotX, rotY, translate, scale...), plus the ability to apply them in a particular order (by doing matrix multiplication).

If you want something that can only represent rotations and nothing else, you might consider quaternions (as anand suggests). However, you still need to decide which order to perform your rotations in, and, again, it doesn't really make sense to hardwire a required order for that.

嘴硬脾气大 2024-10-05 05:23:19

顺便说一句,如果您在此处的开发活动足够早,您可能需要考虑使用四元数旋转< /a>.与基于矩阵的方法相比,它具有许多比较优势

As an aside and if you're early enough in your development activities here, you might want to consider using quaternion rotation. It has a number of comparative advantages to matrix based approaches.

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