Skip to content

Commit 561b9d6

Browse files
authored
Update
1 parent 9a16417 commit 561b9d6

1 file changed

Lines changed: 67 additions & 4 deletions

File tree

CustomView/Advance/[09]Matrix_Basic.md

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,14 @@ matrix.postScale(0.5f, 0.5f, pivotX, pivotY);
427427
428428
主要区别其实就是矩阵的乘法顺序不同,pre相当于矩阵的右乘,而post相当于矩阵的左乘,在图像处理中,越靠近右边的矩阵越先执行,所以pre操作会先执行,而post操作会后执行。
429429
430-
**假设我们需要先缩放再平移:**
431430
432-
pre:
431+
432+
**假设我们需要先缩放再平移,下面我们用不同对方式来构造这一个矩阵:**
433+
434+
>
435+
**注意: 由于矩阵乘法不满足交换律,请保证初始矩阵为空,如果初始矩阵不为空,则可能导致两次运算结果不同。**
436+
437+
#### 1.pre:
433438
434439
```
435440
Matrix m = new Matrix();
@@ -475,7 +480,7 @@ sx & 0 & 0\\\\
475480
\\right ]
476481
$$)
477482
478-
post:
483+
#### 2.post:
479484
480485
```
481486
Matrix m = new Matrix();
@@ -521,7 +526,65 @@ sx & 0 & 0\\\\
521526
\\right ]
522527
$$)
523528
524-
**由于矩阵乘法不满足交换律,请保证初始矩阵为空,如果初始矩阵不为空,则可能导致两次运算结果不同。**
529+
#### 3.混合:
530+
531+
```
532+
Matrix m = new Matrix();
533+
m.reset();
534+
m.preScale(sx, sy);
535+
m.postTranslate(tx, ty);
536+
```
537+
538+
或:
539+
540+
```
541+
Matrix m = new Matrix();
542+
m.reset();
543+
m.postTranslate(tx, ty);
544+
m.preScale(sx, sy);
545+
```
546+
547+
> 由于此处只有两步操作,且指定了先后,所以代码上交换并不会影响结果。
548+
549+
用矩阵表示:
550+
551+
![](http://latex.codecogs.com/png.latex?
552+
$$
553+
\\left [
554+
\\begin{matrix}
555+
& &\\\\
556+
& Result Matrix &\\\\
557+
& &
558+
\\end{1}
559+
\\right ]
560+
=
561+
\\left [
562+
\\begin{matrix}
563+
1 & 0 & \\Delta x \\\\
564+
0 & 1 & \\Delta y \\\\
565+
0 & 0 & 1
566+
\\end{1}
567+
\\right ]
568+
\\cdot
569+
\\left [
570+
\\begin{matrix}
571+
& &\\\\
572+
& Empty Matrix &\\\\
573+
& &
574+
\\end{1}
575+
\\right ]
576+
\\cdot
577+
\\left [
578+
\\begin{matrix}
579+
sx & 0 & 0\\\\
580+
0 & sy & 0\\\\
581+
0 & 0 & 1
582+
\\end{1}
583+
\\right ]
584+
$$)
585+
586+
587+
**注意: 由于矩阵乘法不满足交换律,请保证初始矩阵为空,如果初始矩阵不为空,则可能导致两次运算结果不同。**
525588
526589
527590
<p id="fangfa" />

0 commit comments

Comments
 (0)