Skip to content

Instantly share code, notes, and snippets.

@ixiyang
Created July 15, 2014 10:15
Show Gist options
  • Save ixiyang/4c32c70a059711df8968 to your computer and use it in GitHub Desktop.
Save ixiyang/4c32c70a059711df8968 to your computer and use it in GitHub Desktop.
matrix preXXX and postXXX
matrix代表一个3*3矩阵,其内容如下
MSCALE_X MSKEW_X MTRANS_X
MSKEW_Y MSKEW_Y MTRANS_Y
MPERSP_0 MPERSP_1 MPERSP_2
Matrix matrix=new Matrix();
System.err.println(matrix.toShortString());
matrix.postScale(2, 3);
System.err.println(matrix.toShortString());
matrix.postTranslate(10, 10);
System.err.println(matrix.toShortString());
计算过程如下
2 0 0 1 0 0 2 0 0
0 3 0 * 0 1 0 = 0 3 0
0 0 1 0 0 1 0 0 1
1 0 10 2 0 0 2 0 10
0 1 10 * 0 3 0 = 0 3 10
0 0 1 0 0 1 0 0 1
matrix=new Matrix();
System.err.println(matrix.toShortString());
matrix.preScale(2, 3);
System.err.println(matrix.toShortString());
matrix.preTranslate(10, 10);
System.err.println(matrix.toShortString());
计算过程如下
1 0 0 2 0 0 2 0 0
0 1 0 * 0 3 0 = 0 3 0
0 0 1 0 0 1 0 0 1
2 0 0 1 0 10 2 0 20
0 3 0 * 0 1 10 = 0 3 30
0 0 1 0 0 1 0 0 1
所以prexxx或者postxxx方法先在单位矩阵的基础上生成一个矩阵M'。方法中参数的值会被设置到对应的位置(见开头)。
假定原始矩阵为M,则
matrix.prexxx(a,b)=M*M'
matrix.postxxx(a,b)= M'*M