为什么二维变换需要 3x3 矩阵? [英] Why do 2D transformations need 3x3 matrices?

查看:33
本文介绍了为什么二维变换需要 3x3 矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些 2D 绘图,因此想要实现一些矩阵变换.凭借我的浅数学背景,我试图了解如何在 C# 中做到这一点(任何其他 oop 语言显然都可以做到).

I want to do some 2D drawing and thus want to implement some matrix transformations. With my light mathematics background I am trying to understand how to do so in C# (any other oop language would do it obviously).

我读到的只是解释我们需要使用 3x3 矩阵来处理翻译.因为你不能用乘法来翻译.但这是我们创建转换的矩阵的乘法.所以我们使用类似的东西:

All I read is explaining that we need to work with 3x3 matrices to be able to cope with the translations. Because you cannot make translation with multiplications. But this is with multiplications of the matrices that we create our transformations. So we work with something like:

{ x1, x2, tx }
{ y1, y2, ty }
{ 0,  0,  1  }

我明白第三列的意思,但为什么我们需要第三行?在单位矩阵以及旋转、缩放或旋转中,最后一行是相同的.是否有我还没有达到的操作需要它?是不是因为某些语言(Java)在使用平方维数"数组时表现更好?如果是这样,我可以在 C# 中使用 3 列和 2 行(因为锯齿状数组同样有效或更好).

I understand the mean of the third column, but why do we need the third row? In a identity matrix as well as in a rotation, scale or rotation the last row is the same. Are there operations I did not reach yet which will need it? Is it because some languages (Java) performs better with "squared dimensions" arrays? If so I can use 3 columns and 2 rows in C# (since jagged arrays works as well or better).

例如,对于旋转 + 平移,我有一个这样的矩阵

For example, for a rotation + translation I have a matrix like this

{ cos(rot)*x1, (-sin(rot))*x2, tx }
{ sin(rot)*y1, cos(rot)*y2,    ty }
{ 0,           0,              1  }

不需要最后一行.

推荐答案

这是我们创建变换的矩阵的乘法

this is with multiplications of the matrices that we create our transformations

就是我们想要方阵的原因.

This is why we want square matrices.

假设我们按照您的建议进行操作,并使用 2x3 矩阵进行转换.

Suppose we did what you propose, and used 2x3 matrices for our transformations.

然后是旋转

( x1, x2, 0 )
( y1, y2, 0 )

翻译将是

( 1, 0, tx )
( 0, 1, ty )

我们可以通过将矩阵乘以表示点的列向量来执行旋转或平移:

and we could perform either rotations or translations by multiplying our matrix by a column vector representing the point:

    ( x )
M   ( y )
    ( 0 )

获得正确答案.

但是 - 我们将如何进行组合转换?实际上,对于您的对于旋转 + 平移,我有一个这样的矩阵"示例,您是如何获得该矩阵的?当然,在这种情况下,您可以将其写出来,但一般情况下?嗯,你知道答案:

However - how would we go about composing transformations? Indeed, for your "for a rotation + translation I have a matrix like this" example, how did you get to that matrix? Sure, in this case you can just write it out, but in general? Well, you know the answer:

这是我们创建变换的矩阵的乘法

this is with multiplications of the matrices that we create our transformations

所以必须可以将两个变换矩阵相乘得到另一个变换矩阵.而矩阵乘法的规则表明:

So it must be possible to multiply two transformation matrices to give another transformation matrix. And the rules of matrix multiplication show that this:

( . . . ) ( . . . )
( . . . ) ( . . . ) = ???

不是有效的矩阵乘法.我们需要可以乘法的矩阵,以便我们的转换是可组合的.所以我们有额外的一行.

is not a valid matrix multiplcation. We need matrices that can be multipled in order for our transformations to be composable. So we have that extra row.

现在,我在这里表达的方式实际上完全背离了标准的数学表达,在标准数学表达中,熟悉的旋转和平移变换只是投影平面上齐次坐标变换的全部功率的特例 -但我认为它会告诉你为什么我们需要额外的行 - 使矩阵成为正方形,从而能够与类似的矩阵相乘.

Now, the way I've expressed it here is in fact completely backward from the standard mathematical presentation, in which the familiar transformations of rotation and translation are just special cases of the full power of homogeneous coordinate transformations on the projective plane - but I think it will do to show you why we need that extra row - to make the matrix square, and thus able to be multipled with like matrices.

这篇关于为什么二维变换需要 3x3 矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆