C# 中的矩阵乘法方法
我不太理解 C# 中的 Matrix.Multiply(Matrix m) 方法。
假设我有 2 个矩阵。 1 个矩阵在世界空间中,1 个矩阵在局部空间中,现在我想将世界空间转换为局部空间或从局部空间转换为世界空间,我应该用 Multiply 方法做什么?
Matrix world = ....
Matrix local = ...
world.Multiply(local)
// It means world*local or local*world and it will transform world space to
// local or from local to world space?
提前致谢。
I dont really understand the method Matrix.Multiply(Matrix m) in C#.
Let say I have 2 matrices. 1 matrix is in world space and 1 matrix in local space, now I want to transform world space to local space or from local space to world space, what should I do with the Multiply method?
Matrix world = ....
Matrix local = ...
world.Multiply(local)
// It means world*local or local*world and it will transform world space to
// local or from local to world space?
Thank in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想将一个矩阵转换为另一个矩阵,则不需要将矩阵相乘。您想要找到需要将一个乘以从一个到另一个的矩阵。本质上,您想要求解方程:
其中
W
是您的世界矩阵,L
是您的本地矩阵。您正在寻找矩阵X
。求解X
:其中
I
是单位矩阵,1/L
是L
的逆矩阵,因此:注意矩阵乘法不可交换,因此
W * L
与L * W
不同。You don't want to multiply the matrixes if you want to transform one matrix into the other. You want to find the matrix you need to multiply one by to go from one to the other. Essentially, you want to solve the equation:
Where
W
is your world matrix andL
is your local matrix. You're looking for matrixX
. Solving forX
:Where
I
is the identity matrix and1/L
is the inverse ofL
So:Note that matrix multiplication is not commutative, so
W * L
is not the same, in general, asL * W
.