Skip to content

Commit 9a16417

Browse files
authored
Update
1 parent 6532777 commit 9a16417

1 file changed

Lines changed: 101 additions & 0 deletions

File tree

CustomView/Advance/[09]Matrix_Basic.md

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,107 @@ matrix.postScale(0.5f, 0.5f, pivotX, pivotY);
423423
424424
**组合操作构造Matrix时,个人建议尽量全部使用后乘或者全部使用前乘,这样操作顺序容易确定,出现问题也比较容易排查。<br/>当然,由于矩阵乘法不满足交换律,前乘和后乘的结果是不同的,使用时应结合具体情景分析使用。**
425425
426+
### Pre与Post的区别
427+
428+
主要区别其实就是矩阵的乘法顺序不同,pre相当于矩阵的右乘,而post相当于矩阵的左乘,在图像处理中,越靠近右边的矩阵越先执行,所以pre操作会先执行,而post操作会后执行。
429+
430+
**假设我们需要先缩放再平移:**
431+
432+
pre:
433+
434+
```
435+
Matrix m = new Matrix();
436+
m.reset();
437+
m.preTranslate(tx, ty); //使用pre,越靠后越先执行。
438+
m.preScale(sx, sy);
439+
```
440+
441+
用矩阵表示:
442+
443+
![](http://latex.codecogs.com/png.latex?
444+
$$
445+
\\left [
446+
\\begin{matrix}
447+
& &\\\\
448+
& Result Matrix &\\\\
449+
& &
450+
\\end{1}
451+
\\right ]
452+
=
453+
\\left [
454+
\\begin{matrix}
455+
& &\\\\
456+
& Empty Matrix &\\\\
457+
& &
458+
\\end{1}
459+
\\right ]
460+
\\cdot
461+
\\left [
462+
\\begin{matrix}
463+
1 & 0 & \\Delta x \\\\
464+
0 & 1 & \\Delta y \\\\
465+
0 & 0 & 1
466+
\\end{1}
467+
\\right ]
468+
\\cdot
469+
\\left [
470+
\\begin{matrix}
471+
sx & 0 & 0\\\\
472+
0 & sy & 0\\\\
473+
0 & 0 & 1
474+
\\end{1}
475+
\\right ]
476+
$$)
477+
478+
post:
479+
480+
```
481+
Matrix m = new Matrix();
482+
m.reset();
483+
m.postScale(sx, sy); //使用post,越靠前越先执行。
484+
m.postTranslate(tx, ty);
485+
```
486+
487+
用矩阵表示:
488+
489+
![](http://latex.codecogs.com/png.latex?
490+
$$
491+
\\left [
492+
\\begin{matrix}
493+
& &\\\\
494+
& Result Matrix &\\\\
495+
& &
496+
\\end{1}
497+
\\right ]
498+
=
499+
\\left [
500+
\\begin{matrix}
501+
1 & 0 & \\Delta x \\\\
502+
0 & 1 & \\Delta y \\\\
503+
0 & 0 & 1
504+
\\end{1}
505+
\\right ]
506+
\\cdot
507+
\\left [
508+
\\begin{matrix}
509+
sx & 0 & 0\\\\
510+
0 & sy & 0\\\\
511+
0 & 0 & 1
512+
\\end{1}
513+
\\right ]
514+
\\cdot
515+
\\left [
516+
\\begin{matrix}
517+
& &\\\\
518+
& Empty Matrix &\\\\
519+
& &
520+
\\end{1}
521+
\\right ]
522+
$$)
523+
524+
**由于矩阵乘法不满足交换律,请保证初始矩阵为空,如果初始矩阵不为空,则可能导致两次运算结果不同。**
525+
526+
426527
<p id="fangfa" />
427528
## Matrix方法表
428529

0 commit comments

Comments
 (0)