变换矩阵

Multi tool use
Multi tool use
The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

变换矩阵是数学线性代数中的一个概念。


在线性代数中,线性变换能够用矩阵表示。如果T是一个把Rn映射到Rm的线性变换,且x是一个具有n个元素的列向量,那么


T(x→)=Ax→displaystyle T(vec x)=mathbf A vec xT(vec x)=mathbf Avec x

我们把m×n的矩阵A,称为T的变换矩阵




目录





  • 1 应用


  • 2 寻找变换矩阵


  • 3 在二维图形中的应用示例

    • 3.1 旋转


    • 3.2 缩放


    • 3.3 切变


    • 3.4 反射


    • 3.5 正投影



  • 4 组合变换与逆变换


  • 5 其它类型的变换

    • 5.1 仿射变换


    • 5.2 透视投影



  • 6 参考资料


  • 7 参见


  • 8 外部連結




应用


任意线性变换都可以用矩阵表示为易于计算的一致形式[1],并且多个变换也可以很容易地通过矩阵的相乘连接在一起。


线性变换不是唯一可以用矩阵表示的变换。Rn维的仿射变换与透视投影都可以用齐次坐标表示为RPn+1维(即n+1维的真实投影空间)的线性变换。因此,在三维计算机图形学中大量使用着4x4的矩阵变换。



寻找变换矩阵


如果已经有一个函数型的线性变换T(x)displaystyle T(x)T(x),那么通过T对标准基每个向量进行简单变换,然后将结果插入矩阵的列中,这样很容易就可以确定变换矩阵A,即


A=(T(e→1)T(e→2)⋯T(e→n))displaystyle mathbf A =beginpmatrixT(vec e_1)&T(vec e_2)&cdots &T(vec e_n)endpmatrixmathbf A=beginpmatrixT(vec e_1)&T(vec e_2)&cdots &T(vec e_n)endpmatrix

例如,函数T(x)=5xdisplaystyle T(x)=5xT(x)=5x是线性变换,通过上面的过程得到(假设n = 2)


T(x→)=5x→=(5005)x→displaystyle T(vec x)=5vec x=beginpmatrix5&&0\0&&5endpmatrixvec xT(vec x)=5vec x=beginpmatrix5&&0\0&&5endpmatrixvec x


在二维图形中的应用示例


最为常用的几何变换都是线性变换,这包括旋转、缩放、切变、反射以及正投影。在二维空间中,线性变换可以用2×2的变换矩阵表示。



旋转


绕原点逆时针旋转 θ 度角的变换公式是 x′=xcos⁡θ−ysin⁡θdisplaystyle x'=xcos theta -ysin theta x'=xcos theta -ysin theta y′=xsin⁡θ+ycos⁡θdisplaystyle y'=xsin theta +ycos theta y'=xsin theta +ycos theta ,用矩阵表示为:


(x′y′)=(cos⁡θ−sin⁡θsin⁡θcos⁡θ)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrixcos theta &-sin theta \sin theta &cos theta endpmatrixbeginpmatrixx\yendpmatrixdisplaystyle beginpmatrixx'\y'endpmatrix=beginpmatrixcos theta &-sin theta \sin theta &cos theta endpmatrixbeginpmatrixx\yendpmatrix


缩放


缩放(反矩陣)公式为 x′=sx⋅xdisplaystyle x'=s_xcdot xx'=s_xcdot xy′=sy⋅ydisplaystyle y'=s_ycdot yy'=s_ycdot y,用矩阵表示为:


(x′y′)=(sx00sy)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrixs_x&0\0&s_yendpmatrixbeginpmatrixx\yendpmatrixbeginpmatrixx'\y'endpmatrix=beginpmatrixs_x&0\0&s_yendpmatrixbeginpmatrixx\yendpmatrix


切变


切变有两种可能的形式:


平行于 x 轴的切变为 x′=x+kydisplaystyle x'=x+kyx'=x+kyy′=ydisplaystyle y'=yy'=y,矩阵表示为:


(x′y′)=(1k01)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrix1&k\0&1endpmatrixbeginpmatrixx\yendpmatrixbeginpmatrixx'\y'endpmatrix=beginpmatrix1&k\0&1endpmatrixbeginpmatrixx\yendpmatrix

平行于 y 轴的切变为 x′=xdisplaystyle x'=xx'=xy′=y+kxdisplaystyle y'=y+kxy'=y+kx,矩阵表示为:


(x′y′)=(10k1)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrix1&0\k&1endpmatrixbeginpmatrixx\yendpmatrixbeginpmatrixx'\y'endpmatrix=beginpmatrix1&0\k&1endpmatrixbeginpmatrixx\yendpmatrix


反射


为了沿经过原点的直线反射向量,假设(ux, uy)为直线方向的单位向量。变换矩阵为:


(x′y′)=(2ux2−12uxuy2uxuy2uy2−1)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrix2u_x^2-1&2u_xu_y\2u_xu_y&2u_y^2-1endpmatrixbeginpmatrixx\yendpmatrixbeginpmatrixx'\y'endpmatrix=beginpmatrix2u_x^2-1&2u_xu_y\2u_xu_y&2u_y^2-1endpmatrixbeginpmatrixx\yendpmatrix

不经过原点的直线的反射是仿射变换,而不是线性变换。


若一座標(x, y)沿直線 y=(tan⁡θ)⋅xdisplaystyle y=(tan theta )cdot xdisplaystyle y=(tan theta )cdot x 進行反射,則其影像(x', y')可用以下公式求得:


(x′y′)=(cos⁡2θsin⁡2θsin⁡2θ−cos⁡2θ)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrixcos 2theta &sin 2theta \sin 2theta &-cos 2theta endpmatrixbeginpmatrixx\yendpmatrixdisplaystyle beginpmatrixx'\y'endpmatrix=beginpmatrixcos 2theta &sin 2theta \sin 2theta &-cos 2theta endpmatrixbeginpmatrixx\yendpmatrix



正投影


为了将向量正投影到一条经过原点的直线,假设(ux, uy)是直线方向的单位向量,变换矩阵为:


(x′y′)=(ux2uxuyuxuyuy2)(xy)displaystyle beginpmatrixx'\y'endpmatrix=beginpmatrixu_x^2&u_xu_y\u_xu_y&u_y^2endpmatrixbeginpmatrixx\yendpmatrixbeginpmatrixx'\y'endpmatrix=beginpmatrixu_x^2&u_xu_y\u_xu_y&u_y^2endpmatrixbeginpmatrixx\yendpmatrix

跟反射一样,正投影到一条不经过原点的直线的变换是仿射变换,而不是线性变换。


平行投影也是线性变换,也可以用矩阵表示。但是透视投影不是线性变换,必须用齐次坐标表示。



组合变换与逆变换


用矩阵表示线性变换的一个主要动力就是可以很容易地进行组合变换以及逆变换。


组合可以通过矩阵乘法来完成。如果AB是两个线性变换,那么对向量x先进行A变换,然后进行B变换的过程为:


B(Ax→)=(BA)x→displaystyle mathbf B (mathbf A vec x)=(mathbf BA )vec xmathbf B(mathbf Avec x)=(mathbf BA)vec x

换句话说,AB变换的组合等同于两个矩阵乘积的变换。需要注意的是先AB表示为BA而不是AB


能够通过两个矩阵相乘将两个变换组合在一起这样的能力就使得可以通过逆矩阵进行变换的逆变换。A -1表示A的逆变换。


变换矩阵并不都是可逆的,但通常都可以进行直观的解释。在上一节中,几乎所有的变换都是可逆的。只要sxdisplaystyle s_xs_xsydisplaystyle s_ys_y都不为零,那么缩放变换也是可逆的。另外,正投影永远是不可逆的。



其它类型的变换



仿射变换


为了表示仿射变换,需要使用齐次坐标,即用三维向量(x, y, 1)表示二维向量,对于高维来说也是如此。按照这种方法,就可以用矩阵乘法表示变换。x′=x+txdisplaystyle x'=x+t_xx'=x+t_x; y′=y+tydisplaystyle y'=y+t_yy'=y+t_y变为


(x′y′1)=(10tx01ty001)(xy1)displaystyle beginpmatrixx'\y'\1endpmatrix=beginpmatrix1&0&t_x\0&1&t_y\0&0&1endpmatrixbeginpmatrixx\y\1endpmatrixbeginpmatrixx'\y'\1endpmatrix=beginpmatrix1&0&t_x\0&1&t_y\0&0&1endpmatrixbeginpmatrixx\y\1endpmatrix

在矩阵中增加一列与一行,除右下角的元素为1外其它部分填充为0,通过这种方法,所有的线性变换都可以转换为仿射变换。例如,上面的旋转矩阵变为


(cos⁡θ−sin⁡θ0sin⁡θcos⁡θ0001)displaystyle beginpmatrixcos theta &-sin theta &0\sin theta &cos theta &0\0&0&1endpmatrixbeginpmatrixcos theta &-sin theta &0\sin theta &cos theta &0\0&0&1endpmatrix

通过这种方法,使用与前面一样的矩阵乘积可以将各种变换无缝地集成到一起。


当使用仿射变换时,齐次坐标向量w从来不变,这样可以把它当作为1。但是,透视投影中并不是这样。



透视投影


三维计算机图形学中另外一种重要的变换是透视投影。与平行投影沿着平行线将物体投影到图像平面上不同,透视投影按照从投影中心这一点发出的直线将物体投影到图像平面。这就意味着距离投影中心越远投影越小,距离越近投影越大。


最简单的透视投影将投影中心作为坐标原点,z = 1作为图像平面,这样投影变换为x′=x/zdisplaystyle x'=x/zx'=x/z; y′=y/zdisplaystyle y'=y/zy'=y/z,用齐次坐标表示为:


(xcyczcwc)=(1000010000100010)(xyz1)displaystyle beginpmatrixx_c\y_c\z_c\w_cendpmatrix=beginpmatrix1&0&0&0\0&1&0&0\0&0&1&0\0&0&1&0endpmatrixbeginpmatrixx\y\z\1endpmatrixbeginpmatrixx_c\y_c\z_c\w_cendpmatrix=beginpmatrix1&0&0&0\0&1&0&0\0&0&1&0\0&0&1&0endpmatrixbeginpmatrixx\y\z\1endpmatrix

(这个乘法的计算结果是(xc,yc,zc,wc)displaystyle (x_c,y_c,z_c,w_c)(x_c,y_c,z_c,w_c) = (x,y,z,z)displaystyle (x,y,z,z)(x,y,z,z)。)


在进行乘法计算之后,通常齐次元素wc并不为1,所以为了映射回真实平面需要进行齐次除法,即每个元素都除以wc


(x′y′z′)=(xc/wcyc/wczc/wc)displaystyle beginpmatrixx'\y'\z'endpmatrix=beginpmatrixx_c/w_c\y_c/w_c\z_c/w_cendpmatrixbeginpmatrixx'\y'\z'endpmatrix=beginpmatrixx_c/w_c\y_c/w_c\z_c/w_cendpmatrix

更加复杂的透视投影可以是与旋转、缩放、平移、切变等组合在一起对图像进行变换。



参考资料




  1. ^ Gentle, James E. Matrix Transformations and Factorizations. Matrix Algebra: Theory, Computations, and Applications in Statistics. Springer. 2007. ISBN 9780387708737. 



参见


三维投影



外部連結



  • (英文)线性变换求解器
Q6ABzLb9YRExr0elbirOLhKa9Qz8,Dn mp,1hZjze7A,zHRVI49saXOGEgW
yjGXTAE,gZE2US8 sZR1Hsz

Popular posts from this blog

The Dalles, Oregon

영화 미래의 미라이 다시보기 (2018) 다운로드 링크 무료보기

Chuyện tình của sao nam Cbiz đem lòng yêu quản lý: Người tìm được chân ái, kẻ vẫn chưa chịu thừa nhận