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

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

问题描述

我想要做一些2D绘图,因此想实现一些矩阵变换。用我的光明数学的背景我想了解如何做到这一点在C#中(任何其他OOP语言会做到这一点很明显)。

我所读到的解释,我们需要用3×3矩阵来工作,以便能够应付翻译。因为你不能使译文与乘法。但是,这是与我们创建变换矩阵的乘法。因此,我们的东西,如工作:

  {X1,X2,TX}
{Y1,Y2,TY}
{0,0,1}
 

据我所知,第三列的意思,但为什么我们需要第三排?在一个单位矩阵,以及在一个旋转,缩放和旋转的最后一行是相同的。是否有操作我并没有达到尚未将需要它吗? 是不是因为某些语言(Java)的执行与平方尺寸阵列更好?如果是这样我就可以使用3列,并在C#2行(因为交错数组作品,以及或更好)。

例如,对于一个旋转+翻译我有这样一个矩阵

  {COS(腐)* X1,(-sin(腐))* X2,TX}
{罪(腐)* Y1,COS(腐)* Y2,TY}
{0,0,1}
 

没有必要在最后一排。

解决方案
  

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

的就是我们为什么要方阵。

假设我们做了什么,你提议,并用2×3矩阵为我们的转换。

然后旋转将是

 (X1,X2,0)
(Y1,Y2,0)
 

和翻译将是

 (1,0,TX)
(0,1,TY)
 

,我们可以用我们的矩阵的列向量重新$ P $乘以psenting点进行任何旋转或译:

 (X)
M(Y)
    (0)
 

要得到正确的答案。

然而 - 我们将如何去构成的转换?事实上,为贵的旋转+翻译我有这样一个矩阵的例子,你是怎么的的是矩阵?当然,在这种情况下,你可以写出来,但有什么看法?那么,你知道答案了:

  

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

因此​​,它必须有可能的乘两个变换矩阵,得到另一变换矩阵的。而矩阵乘法的规则表明这一点:

 (。)(。)
(。)(。)= ???
 

不是一个有效的矩阵multiplcation。我们需要一个能够按顺序multipled我们转换为组合的矩阵。所以我们有一个额外的行。


现在的样子,我已经EX pressed在这里实际上是从标准的数学presentation,其中旋转和平移熟悉的转化仅仅是均匀的全功率的只是特殊情况下彻底倒向协调射影平面转换 - 但我认为它会做给你看,为什么我们需要一个额外的行 - 使矩阵方,从而能够与像矩阵来multipled

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).

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  }

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  }

No need of the last row.

解决方案

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

This is why we want square matrices.

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

Then a rotation would be

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

and a translation would be

( 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 )

to get correct answers.

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.

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

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