GDI+ Matrix 基本概念

Matrix 参考仿射变换

MatrixOrder,矩阵序(左右乘)

Translate 平移变换
平移变换,将每一点移动到(x+tx, y+ty),变换矩阵为:
[ 1 0 tx ]

[ 0 1 ty ]

[ 0 0 1 ]

Translate(100, 0) 向右平移100
Translate(0, 100) 向下平移100
Translate(100, 100) 向右平移100,再向下平移100

scale 缩放变换
缩放变换,将每一点的横坐标放大(缩小)至sx倍,纵坐标放大(缩小)至sy倍,变换矩阵为:
[ sx 0 0 ]

[ 0 sy 0 ]

[ 0 0 1 ]
参考:Matrix的基本三种变换之Scale

Rotate(REAL angle, MatrixOrder order)

旋转变换,目标图形围绕原点顺时针旋转theta弧度,变换矩阵为:

[ cos(theta) -sin(theta) 0 ]

[ sin(theta) cos(theta) 0 ]

[ 0 0 1 ]


RotateAt(REAL angle, const PointF &center, MatrixOrder order)
旋转变换,目标图形以(x, y)为轴心顺时针旋转theta弧度,变换矩阵为:

[ cos(theta) -sin(theta) x-x*cos+y*sin]

[ sin(theta) cos(theta) y-x*sin-y*cos ]

[ 0 0 1 ]

相当于两次平移变换与一次原点旋转变换的复合:

[1 0 -x][cos(theta) -sin(theta) 0][1 0 x]

[0 1 -y][sin(theta) cos(theta) 0][0 1 y]

[0 0 1 ][ 0 0 1 ][0 0 1]

也就是说,图像围绕着某个点(a ,b)旋转呢?则先要将坐标平移到该点,再进行旋转,然后将旋转后的图像平移回到原来的坐标原点.


Shear 剪切变换

剪切变换,变换矩阵为:

[ 1 shx 0 ]

[ shy 1 0 ]

[ 0 0 1 ]

相当于一个横向剪切与一个纵向剪切的复合

[ 1 0 0 ][ 1 shx 0 ]

[ shy 1 0 ][ 0 1 0 ]

[ 0 0 1 ][ 0 0 1 ]

(译注:“剪切变换”又称“错切变换”,指的是类似于四边形不稳定性那种性质,街边小商店那种铁拉门都见过吧?想象一下上面铁条构成的菱形拉动的过程,那就是“错切”的过程。)


TransformPoints
对指定的点(多个点,用数组表示)应用某 Matrix(矩阵)进行几何变换,转换为另外一个点(多个点,用数组表示)

 

参考

几个几何变换的矩阵表示

转换矩阵 Matrix详解

Android Matrix理论与应用详解

posted on 2012-11-14 12:11  零一小子  阅读(3187)  评论(0编辑  收藏  举报

导航