The Wayback Machine - https://web.archive.org/web/20201207020427/https://github.com/GcsSloop/AndroidNote/issues/47
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

矩阵前乘后乘问题 #47

Open
a474790005 opened this issue Oct 12, 2016 · 2 comments
Open

矩阵前乘后乘问题 #47

a474790005 opened this issue Oct 12, 2016 · 2 comments
Labels

Comments

@a474790005
Copy link

@a474790005 a474790005 commented Oct 12, 2016

Matrix m = new Matrix();
m.reset();
m.preTranslate(tx, ty);
m.preScale(sx, sy);

这地方是怎么个顺序
1.是preScale先右乘矩阵 preTranslate再右乘上次的结果。
2.preScale先右乘preTranslate,然后再乘矩阵。

@GcsSloop
Copy link
Owner

@GcsSloop GcsSloop commented Oct 12, 2016

  • 首先、探讨此问题前请确保理解矩阵概念,以及明白矩阵乘法的运算方式
  • 其次、了解下面矩阵中每一个位置数值的作用。

![](http://latex.codecogs.com/png.latex?
$$
\left [
\begin{matrix}
MSCALE_X & MSKEW_X & MTRANS_X \
\
MSKEW_Y & MSCALE_Y & MTRANS_Y \
\
MPERSP_0 & MPERSP_1 & MPERSP_2
\end{1}
\right ]
$$)

以上是前提条件,如果不理解这些内容以下所有说明都是白搭。

  • 概念一、矩阵乘法不满足交换律,即 A_B ≠ B_A
  • 概念二、pre相当于矩阵的右乘,而post相当于矩阵的左乘
  • 概念三、程序每一步运算都会得到确定的结果
  • 概念四、根据矩阵乘法运算规则可得,每一次矩阵相乘都会受到其中的所有元素影响,左乘和右乘影响的结果也不同。

当执行 preTranslate 时会受到 MSCALE_XMSCALE_Y 的影响,具体影响如何,自己运算一遍矩阵乘法即可。
例如,当进行如下操作时

Matrix matrix = new Matrix();
matrix.preScale(0.5f, 0.8f);
matrix.preTranslate(1000, 1000);
Log.e(TAG, "MatrixTest:3" + matrix.toShortString());

执行完 preScale(0.5, 0.8),缩放为 (0.5, 0.8)
执行完 preTranslate(1000, 1000),结果平移距离为(500, 800) (概念四、每一次矩阵相乘都会受到其中的所有元素影响)
因此产生一种先执行了平移操作,之后将平移距离缩放的错觉。

最后: 矩阵(线性代数) 是一个学期的数学课程,不是我三言两语能够说明白的,(如果我有这种能力早去当教授了),矩阵相关的具体资料可以自行寻找,网上有很多。

@GcsSloop GcsSloop changed the title 矩阵问题 矩阵前乘后乘问题 Oct 14, 2016
@GcsSloop GcsSloop added the 已解决 label Oct 18, 2016
@xingstarx
Copy link

@xingstarx xingstarx commented Oct 20, 2016

@GcsSloop 真是好心人啊 @a474790005
我最近写的一篇,没写完额,这个例子,按照矩阵乘法的顺序计算了一遍,每一步骤的结果,具体计算过程可以自己尝试,在跟我的结果对照
https://github.com/xingstarx/AndroidNote/blob/master/view/Matrix%E8%AF%A6%E8%A7%A3.md#部分疑问解读

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.